typeverifier
Small utility to check variable types.
Usage
typeverifier
is available as an npm package. Simply run npm install typeverifier
command.
To use it in your project:
import typeverifier from 'typeverifier'; // ES6 syntax
var typeverifier = require('typeverifier'); // ES5 syntax
API
The following methods are available and return true
or false
.
-
defined(val)
: Whetherval
is an defined or not (different fromundefined
ornull
) -
null(val)
: Whetherval
isnull
-
string(val)
: Whetherval
is aString
or not -
number(val)
: Whetherval
is aNumber
or not -
boolean(val)
: Whetherval
is aBoolean
or not -
array(val)
: Whetherval
is anArray
or not -
object(val)
: Whetherval
is anObject
literal or not (different fromundefined
ornull
) -
emptyObject(val)
: Whetherval
is an emptyObject
literal or not -
regex(val)
: Whetherval
is aRegExp
or not -
date(val)
: Whetherval
is aDate
or not -
func(val)
: Whetherval
is aFunction
or not -
error(val)
: Whetherval
is anError
or not -
instanceOf(val, name)
: Whetherval
is an instance of the class whose name is identical to thename
parameter. Do not use this class to check primitives, Arrays, Functions, Dates, RegExps, Objects, etc (rely oninstanceof
for those cases). Use it only for developer authored classes.
License
This software is released under the terms of WTFPL v2.0 license.