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

    Function isObject

    • Checks if a value is a plain object.

      A plain object is one created by the Object constructor (or object literal syntax), with Object.prototype as its direct prototype. This excludes built-in objects like Date, RegExp, Array, Buffer, DOM elements, and objects created with custom constructors.

      Supports two validation modes:

      • Predicate: A (value, key) => boolean function called for each entry
      • Template: validates each property against a corresponding predicate function

      Templates are closed by default: extra properties not in the template are rejected. Use the key symbol as wildcard to create open templates where extra properties are validated by the wildcard predicate (for instance, isAny to accept any value).

      isObject(value, { x: isNumber, y: isNumber }); // closed
      isObject(value, { x: isNumber, [key]: isAny }); // open, accept any extra
      isObject(value, { x: isNumber, [key]: isNumber }); // open, extras must be numbers

      Type Parameters

      • T extends Record<PropertyKey, unknown> = Record<PropertyKey, unknown>

        The expected object type, defaults to Record<PropertyKey, unknown>

      Parameters

      • value: unknown

        The value to check

      • Optionalis:
            | ((value: unknown, key: string) => boolean)
            | {
                "[key]"?: (value: unknown, key: string) => boolean;
                [key: string]: (value: unknown, key: string) => boolean;
            }

        Optional predicate or template to validate entries

      Returns value is T

      True if the value is a plain object matching the validation; false otherwise

      Warning

      The predicate signature (value, key) places value before key to match the isArray guard pattern and enable direct use of value guards like isString without wrapper lambdas.