@bemoje/is-type
Check if a value is of the given type.
Version
Travis CI
Dependencies
Stats
Donate
Installation
npm install @bemoje/is-type
npm install --save @bemoje/is-type
npm install --save-dev @bemoje/is-type
Usage
import isType from '@bemoje/is-type'
isType()
//=> undefined
isType(String, 'asd')
//=> true
isType(String, String('asd'))
//=> true
isType(String, new String('asd'))
//=> true
isType(String, '')
//=> true
isType(Number, NaN)
//=> false
isType(Number, Infinity)
//=> false
isType(Number, 2)
//=> true
isType(Number, new Number(2))
//=> true
isType(Number, 1.1)
//=> true
isType(Array, [])
//=> true
isType(Array, new Uint16Array(1))
//=> false
isType(Uint16Array, new Uint16Array(1))
//=> true
isType(Object, {})
//=> true
class Custom {}
isType(Custom, new Custom())
//=> true
isType(null, null)
//=> true
isType(undefined, undefined)
//=> true
isType(void 0, void 0)
//=> true
Tests
Uses Jest to test module functionality. Run tests to get coverage details.
npm run test
API
isType
Check if a value is of the given type.
Parameters
-
constructor
(function | undefined | null) the constructor that creates instances of the type in question, which should be used to check whether or not the value, 'v' is an instance of that same constructor. -
value
any The value to evaluate