typeverifier
v1.0.3
Published
Small utility to check variable types
Downloads
16
Maintainers
Readme
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 notnumber(val)
: Whetherval
is aNumber
or notboolean(val)
: Whetherval
is aBoolean
or notarray(val)
: Whetherval
is anArray
or notobject(val)
: Whetherval
is anObject
literal or not (different fromundefined
ornull
)emptyObject(val)
: Whetherval
is an emptyObject
literal or notregex(val)
: Whetherval
is aRegExp
or notdate(val)
: Whetherval
is aDate
or notfunc(val)
: Whetherval
is aFunction
or noterror(val)
: Whetherval
is anError
or notinstanceOf(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.