typechecking client lib for @magic
npm install --save-exact @magic-libraries/is
in a page/component, just use the LIB.JSON functions.
export const View = () => [
div(LIB.IS('a string', 'string') ? '"a string" is a string' : '"a string" is not a string'),
div(LIB.IS(0, 'string') ? '0 is a string' : '0 is not a string'),
]
renders
<div>"a string" is a string</div>
<div>0 is not a string</div>
by default, magic will test for type equality using typeof.
is('a string', 'string') // true
is({}, 'object') // true
is([], 'object') // true
if typeof would fail, is uses a number of builtin functions to determine the type of the value
is([], 'array') // true
is(0, 'number') // true
is(1.1, 'float') // true
is(10, 'integer') // true
is(new Date(), 'date') // true
is(/regexp/, 'regexp') // true
is(new Error(), 'error') // true
is(null, 'null') // true
is(new Promise(), 'promise') // true
is({}, 'objectNative') //true
for convenience, @magic-libraries/is also exports the alias functions it uses
is.number(0) // true
is.integer(1) // true
is.float(1.1) // true
is.array([]) // true
is.regexp(/t/) // true
is.date(new Date()) // true
is.error(new Error()) // true
is.null(null) // true
is.promise(new Promise()) // true
is.objectNative({}) //true
first release
update readme
update readme
require node 13.5.0
bump required node version
bump required node version to 14.15.4
update dependencies
update dependencies add is.objectNative
...