@metreeca/core - v0.9.19
    Preparing search index...

    Module index

    Core utility types and type guards.

    Bridges the gap between TypeScript's static type system and untrusted runtime data. Every guard returns a boolean and narrows its argument on success, so validation and type inference collapse into a single call at API boundaries, deserialisation sites, and other trust-crossing points.

    Guards for language-level values and host objects.

    isDefined("value"); // true
    isIdentifier("myVar"); // true (valid ECMAScript identifier)
    isSymbol(Symbol("key")); // true
    isFunction(() => {}); // true
    isError(new Error()); // true
    isRegExp(/pattern/); // true
    isDate(new Date()); // true
    isPromise(Promise.resolve()); // true
    isIterable([1, 2, 3]); // true
    isAsyncIterable(asyncGenerator()); // true

    Complete coverage of the JSON data model: the recursive Value type, its Scalar leaves, and structural guards for arrays and objects. isArray and isObject validate shape in depth through element predicates or tuple/template descriptors; object templates are closed by default, with the key wildcard turning them open.

    isNull(null); // true
    isBoolean(true); // true
    isNumber(42); // true
    isString("hello"); // true
    isScalar(42); // true (boolean, number, or string)
    isValue({ a: [1, 2], b: "test" }); // true (recursive JSON value)

    isArray([1, 2, 3]); // true
    isArray([1, 2, 3], isNumber); // with element predicate
    isArray(["hello", 42], [isString, isNumber]); // with tuple template
    isArray([], []); // empty array check

    isObject({ a: 1 }); // true
    isObject({ a: 1 }, isNumber); // with entry predicate
    isObject({ a: 1 }, { a: isNumber }); // with closed template
    isObject({ a: 1 }, { a: isNumber, [key]: isAny }); // with open template
    isObject({ a: 1 }, { a: isNumber, b: v => isOptional(v, isString) }); // with optional field
    isObject({ kind: "circle" }, { kind: v => isLiteral(v, ["circle", "square"]) }); // with literal field
    isObject({ value: 42 }, { value: v => isUnion(v, [isString, isNumber]) }); // with union field
    isObject({}, {}); // empty object check

    isLazy admits values supplied either eagerly or as no-arg factories; isEager is its dual, rejecting factories and accepting only plain values. Paired with the Lazy / Eager type operators.

    isLazy(() => 42, isNumber); // true (no-arg function)
    isLazy(42, isNumber); // true (plain value)
    isEager(42, isNumber); // true (plain value)
    isEager(() => 42, isNumber); // false (no-arg function rejected)

    Higher-order guards that combine primitive ones into arbitrary type expressions: isUnion for A | B, isIntersection for A & B, isOptional for T | undefined, and isLiteral for literal and enum-like sets. isAny acts as a wildcard that always succeeds, typically used as a placeholder inside templates.

    isAny("test"); // true (wildcard, always succeeds)
    isOptional(undefined, isString); // true
    isOptional("hello", isString); // true
    isLiteral("foo", "foo"); // true
    isLiteral("foo", ["foo", "bar", "baz"]); // true (matches any)
    isUnion("test", [isString, isNumber]); // true (matches isString)
    isUnion(42, [isString, isNumber]); // true (matches isNumber)
    isIntersection({ a: 1 }, [isObject, v => isObject(v, { a: isNumber })]); // true (satisfies all)

    Variables

    key

    Wildcard symbol for open template validation in isObject.

    Type Aliases

    Identifier

    ECMAScript Identifier.

    Value

    Immutable JSON value.

    Scalar

    Immutable JSON scalar.

    Array

    Immutable JSON array.

    Object

    Immutable JSON object.

    Lazy

    A value or a function returning a value.

    Eager

    The eager counterpart of a Lazy reference.

    Guard

    A type guard function.

    Union

    Extracts the guarded type from an array of type guards.

    Intersection

    Extracts the intersection of guarded types from an array of type guards.

    Functions

    isDefined

    Checks if a value is not undefined.

    isIdentifier

    Checks if a value is a valid Identifier.

    isSymbol

    Checks if a value is a symbol.

    isFunction

    Checks if a value is a function.

    isError

    Checks if a value is an Error instance.

    isRegExp

    Checks if a value is a RegExp instance.

    isDate

    Checks if a value is a Date instance.

    isPromise

    Checks if a value is a promise.

    isIterable

    Checks if a value is iterable.

    isAsyncIterable

    Checks if a value is async iterable.

    isValue

    Checks if a value is a valid JSON value.

    isNull

    Checks if a value is null.

    isScalar

    Checks if a value is a JSON scalar.

    isBoolean

    Checks if a value is a boolean.

    isNumber

    Checks if a value is a finite number.

    isString

    Checks if a value is a string.

    isArray

    Checks if a value is an array.

    isObject

    Checks if a value is a plain object.

    isLazy

    Checks if a value is a Lazy reference.

    isEager

    Checks if a value is an Eager reference.

    isAny

    Wildcard type guard that always succeeds.

    isOptional

    Checks if a value is either undefined or satisfies a type guard.

    isLiteral

    Checks if a value matches one of the specified literal values.

    isUnion

    Checks if a value satisfies any of the provided type guards.

    isIntersection

    Checks if a value satisfies all the provided type guards.