@magic-libraries/is

@magic-libraries/is

typechecking client lib for @magic.

installation

npm install --save-exact @magic-libraries/is

usage

in a page/component, just use the LIB.is functions

[  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

"a string" is a string

0 is not a string

supported types

by default, magic will test for type equality using typeof.

is('a string 'string') // trueis({}, 'object')         // trueis([], 'object')         // true

if typeof would fail, is uses a number of builtin functions to determine the type of the value

is([], 'array')              // trueis(0, 'number')              // trueis(1.1, 'float')             // trueis (10, 'integer')           // trueis(new Date(), 'date')       // trueis(/regexp/, 'regexp')       // trueis(new Error(), 'error')     // trueis(null, 'null')             // trueis(new Promise(), 'promise') // trueis({}, 'objectNative')       // true

for convenience, @magic-libraries/is also exports the alias functions it uses

is.number(0)              // trueis.integer(1)             // trueis.float(1.1)             // trueis.array([])              // trueis.regexp(/t/)            // trueis.date(new Date())       // trueis.error(new Error())     // trueis.null(null)             // trueis.promise(new Promise()) // trueis.objectNative({})       // true

source

the source for this page is in the example directory, and gets built and published to github using @magic/core