Skip to content

Repository files navigation

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

About

Cross-realm type predicates for Bare

Resources

Stars

3 stars

Watchers

6 watching

Forks

Used by

Contributors

Languages