tguard-js
    Preparing search index...

    Function isRecordOf

    • Determines whether the provided value is a record whose entries satisfy the given predicate.

      Type Parameters

      • K extends PropertyKey

        The union of property keys represented by the record.

      • V

        The value type that each property must satisfy.

      Parameters

      • o: unknown

        The value to validate.

      • predicate: Predicate<K, V>

        A predicate used to validate each entry value.

      • OptionalincludeHidden: boolean

        Whether to include non-enumerable and symbol keys.

      Returns o is Record<K, V>

      true if all entries satisfy the predicate, otherwise false.

      This function validates both the property keys and values of an object using a custom predicate callback.

      By default, only enumerable string keys are checked using Object.keys(). When includeHidden is enabled, all own property keys are inspected using Reflect.ownKeys(), including:

      • non-enumerable properties
      • symbol keys

      The predicate receives:

      • the current property key
      • the associated property value

      and must return whether the value satisfies the expected type.

      Validate a record of strings:

      isRecordOf(
      { a: 'hello', b: 'world' },
      (_k, v): v is string => isString(v)
      ); // true

      Validate key-sensitive values:

      isRecordOf(
      { port: 3000 },
      (k, v): v is number => {
      return k === 'port' && isNumber(v);
      }
      );

      Include non-enumerable and symbol keys:

      const obj = Object.defineProperty(
      { [Symbol('id')]: 123 },
      'hidden',
      {
      value: 456,
      enumerable: false,
      }
      );

      isRecordOf(obj, (_k, v): v is number => {
      return isNumber(v);
      }, true);

      1.1