javascript-type-checker
v0.2.1
Published
Utility to validate or fetch type of given argument in javascript.
Downloads
2
Maintainers
Readme
javascript-type-checker
A NPM module to validate or fetch type of given argument in javascript.
Table of Contents
Installation
npm install javascript-type-checker --save
Available Methods
isArray(argument)
const javascriptTypeChecker = require('javascript-type-checker');
console.log(javascriptTypeChecker.isArray(['A','B',3])); // true
console.log(javascriptTypeChecker.isArray('A')); // false
isObject(argument)
const javascriptTypeChecker = require('javascript-type-checker');
console.log(javascriptTypeChecker.isObject({'key':'value'})); // true
console.log(javascriptTypeChecker.isObject(['A','B',3])); // false
isNumber(argument)
const javascriptTypeChecker = require('javascript-type-checker');
console.log(javascriptTypeChecker.isNumber(123)); // true
console.log(javascriptTypeChecker.isNumber('123')); // false
console.log(javascriptTypeChecker.isNumber(NaN)); // false
isError(argument)
const javascriptTypeChecker = require('javascript-type-checker');
console.log(javascriptTypeChecker.isError(new Error('Test Error'))); // true
console.log(javascriptTypeChecker.isError('Test Error')); // false
isString(argument)
const javascriptTypeChecker = require('javascript-type-checker');
console.log(javascriptTypeChecker.isString('123')); // true
console.log(javascriptTypeChecker.isString(123)); // false
isBoolean(argument)
const javascriptTypeChecker = require('javascript-type-checker');
console.log(javascriptTypeChecker.isBoolean(false)); // true
console.log(javascriptTypeChecker.isBoolean('false')); // false
isNull(argument)
const javascriptTypeChecker = require('javascript-type-checker');
console.log(javascriptTypeChecker.isNull(null)); // true
console.log(javascriptTypeChecker.isNull('ABC')); // false
isUndefined(argument)
const javascriptTypeChecker = require('javascript-type-checker');
console.log(javascriptTypeChecker.isUndefined({}.testKey)); // true
console.log(javascriptTypeChecker.isUndefined({})); // false
isEmptyObject(argument)
const javascriptTypeChecker = require('javascript-type-checker');
console.log(javascriptTypeChecker.isEmptyObject({})); // true
console.log(javascriptTypeChecker.isEmptyObject({'key':'value'})); // false
isEmptyArray(argument)
const javascriptTypeChecker = require('javascript-type-checker');
console.log(javascriptTypeChecker.isEmptyArray([])); // true
console.log(javascriptTypeChecker.isEmptyArray(['A'])); // false
isArrayOfEmptyArrays(argument)
const javascriptTypeChecker = require('javascript-type-checker');
console.log(javascriptTypeChecker.isArrayOfEmptyArrays([[[[]], [[]]], [])); // true
console.log(javascriptTypeChecker.isArrayOfEmptyArrays([[[[[]]]], 'A'])); // false
getType(argument)
const javascriptTypeChecker = require('javascript-type-checker');
console.log(javascriptTypeChecker.getType('123')); // string
console.log(javascriptTypeChecker.getType(123)); // number
console.log(javascriptTypeChecker.getType(true)); // boolean
console.log(javascriptTypeChecker.getType(NaN)); // NaN
console.log(javascriptTypeChecker.getType(null)); // null
console.log(javascriptTypeChecker.getType(undefined)); // undefined
console.log(javascriptTypeChecker.getType({})); // object
console.log(javascriptTypeChecker.getType([])); // array
console.log(javascriptTypeChecker.getType(new Error('test'))); // error