Skip to content

@magic client typechecking library. unifies javascript typechecking api.

License

Notifications You must be signed in to change notification settings

magic-libraries/is

Repository files navigation

@magic-libraries/is

typechecking client lib for @magic

html-docs

NPM version Linux Build Status Windows Build Status Coverage Status Greenkeeper badge Known Vulnerabilities

installation

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

usage

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>

supported types

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

changelog

0.0.1

first release

0.0.2

update readme

0.0.3

update readme

0.0.4

require node 13.5.0

0.0.5

bump required node version

0.0.6

bump required node version to 14.15.4

0.0.7

update dependencies

0.0.8

update dependencies add is.objectNative

0.0.9 - unreleased

...

About

@magic client typechecking library. unifies javascript typechecking api.

Resources

License

Stars

Watchers

Forks

Packages

No packages published