easytype
Just something better then typeof
![NPM version](https://badge.fury.io/js/easytype.svg)
Install
npm i easytype
Usage
const type = require('easytype');
type()
type(undefined)
type(void 0)
type(null)
type('')
type('🦄')
type(true)
type(false)
type(type(Boolean())
type(type(Boolean(1))
type(type(new Boolean())
type(0)
type(-1.5)
type(NaN)
type(Infinity)
type(Number())
type(Number(-1.5))
type(Number('-1.5'))
type(Number(true))
type(Number('1string'))
type(Number('string'))
type(new Number())
type(Symbol('test'))
type(Symbol())
type({})
type(Object())
type(new Object())
type(Object.create(null))
type(Math)
type(JSON)
type([])
type(Array())
type(new Array())
type(Array.from('123'))
type(() => {})
type(function(){})
type(Object)
type(new Function())
type(new Function('return 0;'))
type(/^.*$/)
type(new RegExp('^.*$'))
type(new RegExp('ab+c', 'ig'))
type(new Date())
type(new Date(0))
type(new Set())
type(new Map())
type(new WeakSet())
type(new WeakMap())
type(new Error())
type(new EvalError())
type(new RangeError())
type(new ReferenceError())
type(new SyntaxError())
type(new TypeError())
type(new URIError())
type(new Int8Array())
type(new Uint8Array())
type(new Uint8ClampedArray())
type(new Int16Array())
type(new Uint16Array())
type(new Int32Array())
type(new Uint32Array())
type(new Float32Array())
type(new Float64Array())
type(new Promise(() => {}))
type((Promise.resolve(1))
type.isUndefined()
type.isDefined('test')
type.isNull(null)
type.isString('')
type.isBoolean(true)
type.isNumber(1)
type.isArray([])
type.isObject({})
type.isFunction(() => {})
type.isRegExp(/^.*$/)
type.isDate(new Date())
type.isSet(new Set())
type.isMap(new Map())
type.isWeakSet(new WeakSet())
type.isWeakMap(new WeakMap())
type.isSymbol(Symbol('test'))
type.isError(new Error())
type.isPromise(new Promise(() => {}))
type.isUndefined('test')
type.isDefined()
type.isNull('null')
type.isString(true)
type.isBoolean('true')
type.isNumber('1')
type.isArray({length: 1})
type.isObject(null)
type.isFunction(global)
type.isRegExp('/^.*$/')
type.isDate('Sat Dec 23 2017 18:44:45 GMT+0300 (MSK)')
type.isSet(new WeakSet())
type.isMap(new WeakMap())
type.isWeakSet(new Set())
type.isWeakMap(new Map())
type.isSymbol([Symbol('test')])
type.isError(Error)
type.isPromise(Promise.all)
type.isNumber.finite(0)
type.isNumber.finite(2e64)
type.isNumber.finite(-1.5)
type.isNumber.finite(NaN)
type.isNumber.finite(Infinity)
type.isNumber.finite(-Infinity)
type.isNaN(NaN)
type.isNaN('NaN')
type.isNaN(Infinity)
type.isNaN()
type.isNaN(0)
type.isNaN(null)
type.isNaN([NaN])
const o = Object.create(null)
function F(){}
type.isObject.pure(o)
type.isObject.pure({})
type.isObject.pure(Object())
type.isObject.pure(new Object())
type.isObject.pure(new F())
type.isObject.plain({})
type.isObject.plain(o)
type.isObject.plain(Object())
type.isObject.plain(new Object())
type.isObject.plain(Object(1))
type.isObject.plain(new Object(''))
type.isObject.plain(new F())
type.isObject.plain(new Date())
type.isObject.plain([])
type.isObject.plain(1)
type.isObject.plain(null)
type.isObject.plain()
type.isPrimitive(undefined)
type.isPrimitive(null)
type.isPrimitive(true)
type.isPrimitive(1)
type.isPrimitive('test')
type.isPrimitive(Boolean())
type.isPrimitive(Number())
type.isPrimitive(String())
type.isPrimitive({})
type.isPrimitive([])
type.isPrimitive(Object(undefined))
type.isPrimitive(Object(null))
type.isPrimitive(Object(true))
type.isPrimitive(Object(1))
type.isPrimitive(Object('test'))
type.isPrimitive(new Boolean())
type.isPrimitive(new Number())
type.isPrimitive(new String())
type.isPrimitive(new Date())
type.isPrimitive(new F())
type.isEasy(null)
type.isEasy(true)
type.isEasy(false)
type.isEasy(1)
type.isEasy('')
type.isEasy('test')
type.isEasy({})
type.isEasy(Object())
type.isEasy([])
type.isEasy(new F())
type.isEasy(undefined)
type.isEasy()
type.isEasy(Symbol('test'))
type.isArray.ofNumbers([0, -1.5, NaN])
type.isArray.ofStrings(['', 'test'])
type.isArray.ofBooleans([true, false])
type.isArray.ofFunctions([function(){}, () => {}, F])
type.isArray.ofObjects([{}, Object(), new Object(), o])
type.isArray.ofArrays([[], [1, 2, 3], Array(10)])
type.isArray.ofPrimitives([undefined, null, true, 1, ''])
type.isArray.ofEasies([null, true, 1, ''])
type.isArray.empty([])
type.isSerializable(null)
type.isSerializable(true)
type.isSerializable(1)
type.isSerializable('')
type.isSerializable([])
type.isSerializable([null, true, 1, ''])
type.isSerializable([undefined, [], {}])
License
MIT