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

    Module index

    Core utility types and type guards.

    Provides primitive type guards for runtime type checking with compile-time narrowing.

    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

    isValue({ a: [1, 2], b: "test" }); // true (JSON value)

    isNull(null); // true
    isBoolean(true); // true
    isNumber(42); // true
    isString("hello"); // true

    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

    isSome("hello", isString); // true (single value)
    isSome(["hello", "world"], isString); // true (array of values)

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

    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.

    Array

    Immutable JSON array.

    Object

    Immutable JSON object.

    Some

    A value or a readonly array of values.

    Lazy

    A value or a function returning a value.

    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.

    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.

    isSome

    Checks if a value is a Some value, that is either a single value or a readonly array of values.

    isLazy

    Checks if a value is a Lazy value, that is either a plain value or a no-arg function returning a value.

    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.