is-a
legible type checking "micro library"
Installation
$ npm install is-a
Usage
var is = ; var StringOrRegExp = isSTRING isREGEXP; var thing1 = /mischief/; console; //falseconsole; //trueconsole; //falseconsole; //trueconsole; //trueconsole; //falseconsole; //trueconsole; //trueconsole; //true var thing2 = "mayhem"; console; //trueconsole; //trueconsole; //falseconsole; //falseconsole; //trueconsole; //trueconsole; //trueconsole; //falseconsole; //true var myType = isARRAY; console; //falseconsole; //trueconsole; //trueconsole; //falseconsole; //falseconsole; //falseconsole; //trueconsole; //falseconsole; //true
Tests
this is the complete list of tests. .a
, .an
, and .is
are optional, is(x).not...
is the same as !is(x)...
Testing: is X a Type
is(x).Arguments
is(x).an.Array
is(x).a.Boolean
is(x).a.Date
is(x).a.Function
is(x).a.Math
is(x).Null
is(x).a.Number
is(x).an.Object
is(x).a.RegExp
is(x).a.String
is(x).Undefined
Testing: is X not a Type
is(x).not.Arguments
is(x).not.an.Array
is(x).not.a.Boolean
is(x).not.a.Date
is(x).not.a.Function
is(x).not.a.Math
is(x).not.Null
is(x).not.a.Number
is(x).not.an.Object
is(x).not.a.RegExp
is(x).not.a.String
is(x).not.Undefined
Testing: is X a GeneralType
general types are
BuiltinType
: one of (Arguments, Array, Boolean, Date, Function, Math, Null, Number, Object, RegExp, String, Undefined)JsonBasicType
: one of (Array, Boolean, Null, Number, Object, String, Undefined)CoreObject
: one of (Array, Boolean, Date, Function, Math, Number, RegExp, String)Primitive
: one of (Boolean, Null, Number, String, Undefined)
general types can be tested for just like simple types
is(x).a.BuiltinType
is(x).a.JsonBasicType
is(x).a.CoreObject
is(x).a.Primitive
is(x).a([is.STRING, is.ARRAY])
.not
still works
is(x).not.a.BuiltinType
is(x).not.a.JsonBasicType
is(x).not.a.CoreObject
is(x).not.a.Primitive
is(x).not.a([is.STRING, is.ARRAY])
builtin types can be tested too
is.ARRAY.a.JsonBasicType
is.REGEXP.a([is.STRING, is.ARRAY])
everything else
var is = ; var thing1 = /mischief/; console; // "RegExp"console; // "[object RegExp]"