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

    Module index

    Runtime/value type guards, safe casts, deep equality and immutability, error utilities.

    Runtime Guards

    Type guards for runtime JavaScript types and protocols.

    import { isDefined, isEmpty, isFunction, isPromise, isIterable } from '@metreeca/core';

    if (isDefined<T>(value)) {
    // value is T
    }
    and define T

    isEmpty({}); // true
    isEmpty([]); // true

    isFunction(() => {}); // true
    isPromise(Promise.resolve(42)); // true
    isIterable([1, 2, 3]); // true
    isDefined

    Checks if a value is not undefined or null.

    isEmpty

    Checks if a value is an empty plain object or an empty array.

    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.

    isPromise

    Checks if a value is a promise.

    isIterable

    Checks if a value is iterable.

    isAsyncIterable

    Checks if a value is async iterable.

    Value Guards

    Type guards for JSON-like values and data structures.

    import { isBoolean, isNumber, isString, isObject, isArray } from '@metreeca/core';

    isBoolean(true); // true
    isNumber(42); // true (excludes NaN, Infinity)
    isString('hello'); // true

    isObject({ a: 1 }); // true
    isObject(new Date()); // false

    isArray([1, 2, 3], isNumber); // true
    isArray([1, 'two'], isNumber); // false
    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.

    isObject

    Checks if a value is a plain object.

    isArray

    Checks if a value is an array.

    Value Casts

    Safe casts for JSON-like primitive values and data structures, returning undefined instead of throwing.

    import { asNumber, asString, asObject, asArray } from '@metreeca/core';

    asNumber(42); // 42
    asNumber('42'); // undefined
    asBoolean

    Retrieves a value as a boolean if it is one, otherwise returns undefined.

    asNumber

    Retrieves a value as a number if it is one, otherwise returns undefined.

    asString

    Retrieves a value as a string if it is one, otherwise returns undefined.

    asObject

    Retrieves a value as a plain object if it is one, otherwise returns undefined.

    asArray

    Retrieves a value as an array if it is one, otherwise returns undefined.

    Structural Utilities

    Deep operations on complex types.

    import { equals, immutable } from '@metreeca/core';

    equals({ a: [1, 2] }, { a: [1, 2] }); // true
    immutable({ a: [1, 2, 3] }); // deep frozen
    equals

    Checks deep object equality.

    immutable

    Creates an immutable deep clone.