Licence
Apache-2.0
Version
1.4.0
Deps
0
Size
512 kB
Vulns
0
Weekly
0
bare-type
Cross-realm type predicates for Bare.
npm i bare-type
Usage
const type = require('bare-type')
if (type(123).isNumber()) {
console.log(123, 'is a number')
}
To test a value against many types at once, switch on type.of() rather than walking the predicates. Every constant carries its base type, so each one matches outright:
const type = require('bare-type')
const { ARRAY, DATE, MAP } = type.constants
switch (type.of(value)) {
case ARRAY:
return value.length
case DATE:
return value.getTime()
case MAP:
return value.size
}
API
See the bare-type reference.
Threat model
bare-type is one of the addons Bare compiles into its binary, so it inherits Bare's threat model. See docs/threat-model.md for where this addon sits in it.
License
Apache-2.0