import { isArray, isString, isNumber, ... } from '@nawael/checker.js'
Usage examples
// instead of using typeof
if (typeof arg === 'object') {
// ...some stuff
// But if we do Object.keys(arg) we throw an error if arg is null! π±
// TypeError: Cannot convert undefined or null to object
}
// use isObject
import { isObject } from '@nawael/checker.js'
isObject(arg)
// β true if arg = {}
// β false if arg = null cause typeof null === 'object'
// β false if arg = [] cause typeof [] === 'object'
// instead of using typeof
if (typeof arg === 'number') {
// some stuff
}
// use isNumber
import { isNumber } from '@nawael/checker.js'
isNumber(arg)
// β true if arg = 0 or arg = Infinity or -Infinity or
// β true if arg = new Number() cause typeof new Number() === 'object'
// β false if arg = NaN cause NaN is a number and we need to avoid NaN
// π± so we must check Object.prototype.toString.call(arg) === '[object Number]'
!TIP
All APIs are available in the standalone "is" API
// instead of importing all API
import { isArray, isString, isNumber, ... } from '@nawael/checker.js'
// use "is" API and avoid boring imports
import { is } from '@nawael/checker.js'
is.array(arg) // isArray(arg)
is.string(arg) // isString(arg)
is.number(arg) // isNumber(arg)
// ...and so on