Cross-realm type predicates for Bare.
npm i bare-type
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
}See the bare-type reference.
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.
Apache-2.0