bare-type
Cross-realm type predicates for Bare
v1.6.0bare-type — Cross-realm type predicates for Bare. It is a native addon and requires Bare >=1.37.0. Before v1.5.0, it required Bare >=1.32.0.
npm i bare-typeUsage
const type = require('bare-type')
if (type(123).isNumber()) {
console.log(123, 'is a number')
}API
Type
new Type(type: number)
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
type | number | — | — |
isArguments(): boolean
isArray(): boolean
isArrayBuffer(): boolean
Whether the value is an ArrayBuffer, whether or not it can be detached. A SharedArrayBuffer is not one; see isSharedArrayBuffer().
isAsyncFunction(): boolean
isAsyncGeneratorFunction(): boolean
isBigInt(): boolean
isBigInt64Array(): boolean
isBigIntObject(): boolean
isBigUint64Array(): boolean
isBoolean(): boolean
isBooleanObject(): boolean
isDataView(): boolean
isDate(): boolean
isDetachableArrayBuffer(): boolean
Whether the value is an ArrayBuffer that can be detached, such as with transfer(). The buffer of a WebAssembly.Memory can't be. A buffer that is already detached still counts. Added in v1.5.0.
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
isMapIterator(): boolean
Whether the value is an iterator over a Map, such as the one entries(), keys(), or values() of a Map returns. Added in v1.6.0.
isModuleNamespace(): boolean
isNull(): boolean
isNumber(): boolean
isNumberObject(): boolean
isObject(): boolean
isPromise(): boolean
isProxy(): boolean
isRegExp(): boolean
isSet(): boolean
isSetIterator(): boolean
Whether the value is an iterator over a Set, such as the one entries(), keys(), or values() of a Set returns. Added in v1.6.0.
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
| Parameter | Type | Default | Description |
|---|---|---|---|
value | unknown | — | 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
| Parameter | Type | Default | Description |
|---|---|---|---|
value | unknown | — | The value to test. |
Constants and variables
type.constants: Constants
The type constants that of() returns. Changed in v1.5.0: for an ArrayBuffer that can't be detached, such as the buffer of a WebAssembly.Memory, of() returns NON_DETACHABLE_ARRAYBUFFER where it returned ARRAYBUFFER, so a switch with a case for ARRAYBUFFER alone no longer matches it. isArrayBuffer() is still true for both. Added in v1.6.0: MAP_ITERATOR and SET_ITERATOR.
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 MAP_ITERATOR: number
readonly SET_ITERATOR: 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 NON_DETACHABLE_ARRAYBUFFER: 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
}Threat model
bare-type is one of the addons Bare compiles into its binary, so every Bare process has it, sealed or not, and it inherits Bare's threat model. The module's own threat model, added in v1.2.0, says where it sits in that one. It only reports what a value is, across realms, and reaches and keeps nothing, so it has the smallest surface of the builtins. The risk is in the C that walks values an attacker built, proxies and revoked proxies included. Seeing across realms is not a hole, because a realm is not a wall in Bare.
See also
- Bare modules — the full
bare-*catalog. - Bare runtime API — the runtime these modules extend.
Last updated on