Bare Docs

bare-type

Cross-realm type predicates for Bare

Documented against v1.4.0
stable

bare-type — Cross-realm type predicates for Bare. It is a native addon and requires Bare >=1.32.0.

npm i bare-type

Usage

const type = require('bare-type')

if (type(123).isNumber()) {
  console.log(123, 'is a number')
}

API

Type

new Type(type: number)

Parameters

ParameterTypeDefaultDescription
typenumber——

isArguments(): boolean

isArray(): boolean

isArrayBuffer(): boolean

isAsyncFunction(): boolean

isAsyncGeneratorFunction(): boolean

isBigInt(): boolean

isBigInt64Array(): boolean

isBigIntObject(): boolean

isBigUint64Array(): boolean

isBoolean(): boolean

isBooleanObject(): boolean

isDataView(): boolean

isDate(): boolean

isError(): boolean

isExternal(): boolean

isFloat16Array(): boolean

isFloat32Array(): boolean

isFloat64Array(): boolean

isFunction(): boolean

isGenerator(): boolean

isGeneratorFunction(): boolean

isInt16Array(): boolean

isInt32(): boolean

isInt32Array(): boolean

isInt8Array(): boolean

isMap(): boolean

isModuleNamespace(): boolean

isNull(): boolean

isNumber(): boolean

isNumberObject(): boolean

isObject(): boolean

isPromise(): boolean

isProxy(): boolean

isRegExp(): boolean

isSet(): boolean

isSharedArrayBuffer(): boolean

isString(): boolean

isStringObject(): boolean

isSymbol(): boolean

isSymbolObject(): boolean

isTypedArray(): boolean

isUint16Array(): boolean

isUint32(): boolean

isUint32Array(): boolean

isUint8Array(): boolean

isUint8ClampedArray(): boolean

isUndefined(): boolean

isWeakMap(): boolean

isWeakRef(): boolean

isWeakSet(): boolean

Functions

type(value: unknown): Type

Return a Type wrapping value, exposing is*() predicates to test its runtime type across realms.

Parameters

ParameterTypeDefaultDescription
valueunknown—The value to wrap and test.

type.of(value: unknown): number

Return the runtime type of value as a number, for callers that would otherwise walk a long chain of predicates and can switch on it instead. Every constant carries its base type, so constants.ARRAY matches an array outright.

Parameters

ParameterTypeDefaultDescription
valueunknown—The value to test.

Constants and variables

type.constants: Constants

The type constants that of() returns.

Types

Constants

interface Constants {
  readonly UNDEFINED: number
  readonly NULL: number
  readonly BOOLEAN: number
  readonly NUMBER: number
  readonly STRING: number
  readonly SYMBOL: number
  readonly OBJECT: number
  readonly FUNCTION: number
  readonly EXTERNAL: number
  readonly BIGINT: number
  readonly INT32: number
  readonly UINT32: number
  readonly ARRAY: number
  readonly ARGUMENTS: number
  readonly DATE: number
  readonly REGEXP: number
  readonly ERROR: number
  readonly PROMISE: number
  readonly PROXY: number
  readonly GENERATOR: number
  readonly MAP: number
  readonly SET: number
  readonly WEAK_MAP: number
  readonly WEAK_SET: number
  readonly WEAK_REF: number
  readonly ARRAYBUFFER: number
  readonly SHAREDARRAYBUFFER: number
  readonly TYPEDARRAY: number
  readonly DATAVIEW: number
  readonly MODULE_NAMESPACE: number
  readonly BOOLEAN_OBJECT: number
  readonly NUMBER_OBJECT: number
  readonly STRING_OBJECT: number
  readonly SYMBOL_OBJECT: number
  readonly BIGINT_OBJECT: number
  readonly ASYNC_FUNCTION: number
  readonly GENERATOR_FUNCTION: number
  readonly ASYNC_GENERATOR_FUNCTION: number
  readonly INT8ARRAY: number
  readonly UINT8ARRAY: number
  readonly UINT8CLAMPEDARRAY: number
  readonly INT16ARRAY: number
  readonly UINT16ARRAY: number
  readonly INT32ARRAY: number
  readonly UINT32ARRAY: number
  readonly FLOAT16ARRAY: number
  readonly FLOAT32ARRAY: number
  readonly FLOAT64ARRAY: number
  readonly BIGINT64ARRAY: number
  readonly BIGUINT64ARRAY: number
}

See also

Last updated on

Was this helpful?

On this page