What Type Is?
A simple type checking library for Node.js
Table of Contents
Example
const getType isPlainObject isArray = // array // false // true
Installation
npm i --save what-type-is
Tests
npm test
Usage
You can import all functions or import it on-demand using destructuring assignment
Importing all functions
const it = const message = 'Hello' console // true
Importing on-demand
This is a great way to import only what you need to use. You can import any functions available using destructuring assignment. Just take a look at API section to know all functions you can use and import it on-demand.
const isArray isObject isPlainObject isFunction = const messages = 'Hello' 'World' 'How are you?' console // true console // true console // false console // false
API
- getType
- isArray
- isString
- isNumber
- isBoolean
- isObject
- isPlainObject
- isFunction
- isDate
- isRegExp
- isNull
- isUndefined
getType( any )
Returns a string containing the type of the given argument.
Example
// array // date // object
isArray( any )
Check if a given argument is an array and returns a boolean.
Example
// true // false
isString( any )
Check if a given argument is a string and returns a boolean.
Example
// true // false
isNumber( any )
Check if a given argument is a number and returns a boolean.
Example
// true // false
isBoolean( any )
Check if a given argument is a boolean and returns a boolean.
Example
// true // false
isObject( any )
Check if a given argument is an object according with ECMA spec and returns a boolean.
Example
// true // true
isPlainObject( any )
Check if a given argument is a plain object and returns a boolean.
Example
// true // false
isFunction( any )
Check if a given argument is a function and returns a boolean.
Example
// true // false
isDate( any )
Check if a given argument is a date object and returns a boolean.
Example
// true // false
isRegExp( any )
Check if a given argument is a regular expression and returns a boolean.
Example
// true // true
isNull( any )
Check if a given argument is a null and returns a boolean.
Example
// true // false
isUndefined( any )
Check if a given argument is an undefined and returns a boolean.
Example
// true // false