is-check
Check if the given value is of a specific type.
About
Provide a simple and clean way to check if a value matches a specific type. Abstract the usage of "typeof === '...'".
Installation
npm install is-check
Module Usage
var check = require('is-check');
var myValue = 'something';
check.isArray(myValue);
check.isBoolean(myValue);
check.isFunction(myValue);
check.isNil(myValue);
check.isNull(myValue);
check.isNumber(myValue);
check.isObject(myValue);
check.isString(myValue);
check.isUndefined(myValue);
Running the tests
From inside the root project folder run:
npm install
and then if you are on a windows machine:
npm test
if you are on a unix machine:
npm testUNIX
Spec
TOC
- function isArray()
- function isBoolean()
- function isFunction()
- function isNill()
- function isNull()
- function isNumber()
- function isObject()
- function isString()
- function isUndefined()
function isArray()
returns true:
isArray([]) should be true.
checkshouldbeok;
isArray([1]) should be true.
checkshouldbeok;
isArray([new Array()]) should be true.
checkshouldbeok;
isArray([Array.prototype]) should be true.
checkshouldbeok;
returns false:
isArray(37) should be false.
checkshouldnotbeok;
isArray(3.14) should be false.
checkshouldnotbeok;
isArray(Math.LN2) should be false.
checkshouldnotbeok;
isArray(Infinity) should be false.
checkshouldnotbeok;
isArray(Number(1)) should be false.
checkshouldnotbeok;
isArray(NaN) should be false.
checkshouldnotbeok;
isArray("") should be false.
checkshouldnotbeok;
isArray("bla") should be false.
checkshouldnotbeok;
isArray(typeof 1) should be false.
checkshouldnotbeok;
isArray("abc") should be false.
checkshouldnotbeok;
isArray(false) should be false.
checkshouldnotbeok;
isArray(false) should be false.
checkshouldnotbeok;
isArray(Boolean(false)) should be false.
checkshouldnotbeok;
isArray(Boolean(false)) should be false.
checkshouldnotbeok;
isArray( new Boolean(false)) should be false.
checkshouldnotbeok;
isArray(undefined) should be false.
checkshouldnotbeok;
isArray(null) should be false.
checkshouldnotbeok;
isArray({a:1}) should be false.
checkshouldnotbeok;
isArray(new Date()) should be false.
checkshouldnotbeok;
isArray(function(){}) should be false.
checkshouldnotbeok;
isArray(Math.sin) should be false.
checkshouldnotbeok;
function isBoolean()
returns true:
isBoolean(true) should be true.
checkshouldbeok;
isBoolean(false) should be true.
checkshouldbeok;
isBoolean(Boolean(true)) should be true.
checkshouldbeok;
isBoolean(Boolean(false)) should be true.
checkshouldbeok;
returns false:
isBoolean(NaN) should be false.
checkshouldnotbeok;
isBoolean(undefined) should be false.
checkshouldnotbeok;
isBoolean(null) should be false.
checkshouldnotbeok;
isBoolean({a:1}) should be false.
checkshouldnotbeok;
isBoolean(new Date()) should be false.
checkshouldnotbeok;
isBoolean(function(){}) should be false.
checkshouldnotbeok;
isBoolean(Math.sin) should be false.
checkshouldnotbeok;
isBoolean([1, 2, 4]) should be false.
checkshouldnotbeok;
isBoolean(37) should be false.
checkshouldnotbeok;
isBoolean(3.14) should be false.
checkshouldnotbeok;
isBoolean(Math.LN2) should be false.
checkshouldnotbeok;
isBoolean(Infinity) should be false.
checkshouldnotbeok;
isBoolean(Number(1)) should be false.
checkshouldnotbeok;
isBoolean("") should be false.
checkshouldnotbeok;
isBoolean("bla") should be false.
checkshouldnotbeok;
isBoolean(typeof 1) should be false.
checkshouldnotbeok;
isBoolean("abc") should be false.
checkshouldnotbeok;
function isFunction()
returns true:
isFunction(function(){}) should be true.
checkshouldbeok;
isFunction(Math.sin) should be true.
checkshouldbeok;
returns false:
isFunction(37) should be false.
checkshouldnotbeok;
isFunction(3.14) should be false.
checkshouldnotbeok;
isFunction(Math.LN2) should be false.
checkshouldnotbeok;
isFunction(Infinity) should be false.
checkshouldnotbeok;
isFunction(Number(1)) should be false.
checkshouldnotbeok;
isFunction(NaN) should be false.
checkshouldnotbeok;
isFunction("") should be false.
checkshouldnotbeok;
isFunction("bla") should be false.
checkshouldnotbeok;
isFunction(typeof 1) should be false.
checkshouldnotbeok;
isFunction("abc") should be false.
checkshouldnotbeok;
isFunction(true) should be false.
checkshouldnotbeok;
isFunction(false) should be false.
checkshouldnotbeok;
isFunction(Boolean(true)) should be false.
checkshouldnotbeok;
isFunction(Boolean(false)) should be false.
checkshouldnotbeok;
isFunction( new Boolean(true)) should be false.
checkshouldnotbeok;
isFunction(undefined) should be false.
checkshouldnotbeok;
isFunction(null) should be false.
checkshouldnotbeok;
isFunction({a:1}) should be false.
checkshouldnotbeok;
isFunction(new Date()) should be false.
checkshouldnotbeok;
isFunction([1, 2, 4]) should be false.
checkshouldnotbeok;
function isNill()
returns true:
isNil(null) should be true.
checkshouldbeok;
isNil(undefined) should be true.
checkshouldbeok;
returns false:
isNil(NaN) should be false.
checkshouldnotbeok;
isNil("") should be false.
checkshouldnotbeok;
isNil("bla") should be false.
checkshouldnotbeok;
isNil(typeof 1) should be false.
checkshouldnotbeok;
isNil("abc") should be false.
checkshouldnotbeok;
isNil(true) should be false.
checkshouldnotbeok;
isNil(false) should be false.
checkshouldnotbeok;
isNil(Boolean(true)) should be false.
checkshouldnotbeok;
isNil(Boolean(false)) should be false.
checkshouldnotbeok;
isNil( new Boolean(true)) should be false.
checkshouldnotbeok;
isNil({a:1}) should be false.
checkshouldnotbeok;
isNil(new Date()) should be false.
checkshouldnotbeok;
isNil(function(){}) should be false.
checkshouldnotbeok;
isNil(Math.sin) should be false.
checkshouldnotbeok;
isNil([1, 2, 4]) should be false.
checkshouldnotbeok;
isNil(37) should be false.
checkshouldnotbeok;
isNil(3.14) should be false.
checkshouldnotbeok;
isNil(Math.LN2) should be false.
checkshouldnotbeok;
isNil(Infinity) should be false.
checkshouldnotbeok;
isNil(Number(1)) should be false.
checkshouldnotbeok;
function isNull()
returns true:
isNull(null) should be true.
checkshouldbeok;
returns false:
isNull(37) should be false.
checkshouldnotbeok;
isNull(3.14) should be false.
checkshouldnotbeok;
isNull(Math.LN2) should be false.
checkshouldnotbeok;
isNull(Infinity) should be false.
checkshouldnotbeok;
isNull(Number(1)) should be false.
checkshouldnotbeok;
isNull(NaN) should be false.
checkshouldnotbeok;
isNull("") should be false.
checkshouldnotbeok;
isNull("bla") should be false.
checkshouldnotbeok;
isNull(typeof 1) should be false.
checkshouldnotbeok;
isNull("abc") should be false.
checkshouldnotbeok;
isNull(true) should be false.
checkshouldnotbeok;
isNull(false) should be false.
checkshouldnotbeok;
isNull(Boolean(true)) should be false.
checkshouldnotbeok;
isNull(Boolean(false)) should be false.
checkshouldnotbeok;
isNull( new Boolean(true)) should be false.
checkshouldnotbeok;
isNull(undefined) should be false.
checkshouldnotbeok;
isNull({a:1}) should be false.
checkshouldnotbeok;
isNull(new Date()) should be false.
checkshouldnotbeok;
isNull(function(){}) should be false.
checkshouldnotbeok;
isNull(Math.sin) should be false.
checkshouldnotbeok;
isNull([1, 2, 4]) should be false.
checkshouldnotbeok;
function isNumber()
returns true:
isNumber(37) should be true.
checkshouldbeok;
isNumber(3.14) should be true.
checkshouldbeok;
isNumber(Math.LN2) should be true.
checkshouldbeok;
isNumber(Infinity) should be true.
checkshouldbeok;
isNumber(Number(1)) should be true.
checkshouldbeok;
returns false:
isNumber(NaN) should be false.
checkshouldnotbeok;
isNumber("") should be false.
checkshouldnotbeok;
isNumber("bla") should be false.
checkshouldnotbeok;
isNumber(typeof 1) should be false.
checkshouldnotbeok;
isNumber("abc") should be false.
checkshouldnotbeok;
isNumber(true) should be false.
checkshouldnotbeok;
isNumber(false) should be false.
checkshouldnotbeok;
isNumber(Boolean(true)) should be false.
checkshouldnotbeok;
isNumber(Boolean(false)) should be false.
checkshouldnotbeok;
isNumber( new Boolean(true)) should be false.
checkshouldnotbeok;
isNumber(undefined) should be false.
checkshouldnotbeok;
isNumber(null) should be false.
checkshouldnotbeok;
isNumber({a:1}) should be false.
checkshouldnotbeok;
isNumber(new Date()) should be false.
checkshouldnotbeok;
isNumber(function(){}) should be false.
checkshouldnotbeok;
isNumber(Math.sin) should be false.
checkshouldnotbeok;
isNumber([1, 2, 4]) should be false.
checkshouldnotbeok;
function isObject()
returns true:
isObject({a:1}) should be true.
checkshouldbeok;
isObject(new Date()) should be true.
checkshouldbeok;
isObject(new Boolean(true)) should be true.
checkshouldbeok;
returns false:
isObject(37) should be false.
checkshouldnotbeok;
isObject(3.14) should be false.
checkshouldnotbeok;
isObject(Math.LN2) should be false.
checkshouldnotbeok;
isObject(Infinity) should be false.
checkshouldnotbeok;
isObject(Number(1)) should be false.
checkshouldnotbeok;
isObject(NaN) should be false.
checkshouldnotbeok;
isObject("") should be false.
checkshouldnotbeok;
isObject("bla") should be false.
checkshouldnotbeok;
isObject(typeof 1) should be false.
checkshouldnotbeok;
isObject("abc") should be false.
checkshouldnotbeok;
isObject(true) should be false.
checkshouldnotbeok;
isObject(false) should be false.
checkshouldnotbeok;
isObject(Boolean(true)) should be false.
checkshouldnotbeok;
isObject(Boolean(false)) should be false.
checkshouldnotbeok;
isObject( new Boolean(true)) should be false.
checkshouldnotbeok;
isObject(undefined) should be false.
checkshouldnotbeok;
isObject(null) should be false.
checkshouldnotbeok;
isObject(function(){}) should be false.
checkshouldnotbeok;
isObject(Math.sin) should be false.
checkshouldnotbeok;
isObject([1, 2, 4]) should be false.
checkshouldnotbeok;
function isString()
returns true:
isString("") should be true.
checkshouldbeok;
isString("bla") should be true.
checkshouldbeok;
isString(typeof 1) should be true.
checkshouldbeok;
isString("abc") should be true.
checkshouldbeok;
returns false:
isString(NaN) should be false.
checkshouldnotbeok;
isString(true) should be false.
checkshouldnotbeok;
isString(false) should be false.
checkshouldnotbeok;
isString(Boolean(true)) should be false.
checkshouldnotbeok;
isString(Boolean(false)) should be false.
checkshouldnotbeok;
isString( new Boolean(true)) should be false.
checkshouldnotbeok;
isString(undefined) should be false.
checkshouldnotbeok;
isString(null) should be false.
checkshouldnotbeok;
isString({a:1}) should be false.
checkshouldnotbeok;
isString(new Date()) should be false.
checkshouldnotbeok;
isString(function(){}) should be false.
checkshouldnotbeok;
isString(Math.sin) should be false.
checkshouldnotbeok;
isString([1, 2, 4]) should be false.
checkshouldnotbeok;
isString(37) should be false.
checkshouldnotbeok;
isString(3.14) should be false.
checkshouldnotbeok;
isString(Math.LN2) should be false.
checkshouldnotbeok;
isString(Infinity) should be false.
checkshouldnotbeok;
isString(Number(1)) should be false.
checkshouldnotbeok;
function isUndefined()
returns true:
isUndefined(undefined) should be true.
checkshouldbeok;
returns false:
isUndefined(37) should be false.
checkshouldnotbeok;
isUndefined(3.14) should be falsw.
checkshouldnotbeok;
isUndefined(Math.LN2) should be false.
checkshouldnotbeok;
isUndefined(Infinity) should be false.
checkshouldnotbeok;
isUndefined(Number(1)) should be false.
checkshouldnotbeok;
isUndefined(NaN) should be false.
checkshouldnotbeok;
isUndefined("") should be false.
checkshouldnotbeok;
isUndefined("bla") should be false.
checkshouldnotbeok;
isUndefined(typeof 1) should be false.
checkshouldnotbeok;
isUndefined("abc") should be false.
checkshouldnotbeok;
isUndefined(true) should be false.
checkshouldnotbeok;
isUndefined(false) should be false.
checkshouldnotbeok;
isUndefined(Boolean(true)) should be false.
checkshouldnotbeok;
isUndefined(Boolean(false)) should be false.
checkshouldnotbeok;
isUndefined( new Boolean(true)) should be false.
checkshouldnotbeok;
isUndefined(null) should be false.
checkshouldnotbeok;
isUndefined({a:1}) should be false.
checkshouldnotbeok;
isUndefined(new Date()) should be false.
checkshouldnotbeok;
isUndefined(function(){}) should be false.
checkshouldnotbeok;
isUndefined(Math.sin) should be false.
checkshouldnotbeok;
isUndefined([1, 2, 4]) should be false.
checkshouldnotbeok;