Function createObjectFactory

  • Creates a factory function for creating objects with specified keys and default values.

    Type Parameters

    • T

      The type of the values.

    Parameters

    • keys: string[]

      An array of strings representing the keys of the objects to be created.

    • Optional defaultValues: T[]

      An optional array of default values for the keys. If provided, its length should not be larger than the length of the keys array.

    Returns ((values?) => Record<string, T>)

    An ObjectFactory function. When called, this function takes an optional array of values and returns an object with the specified keys and values. If the values array is not provided or if a value is undefined, the corresponding default value is used.

      • (values?): Record<string, T>
      • Parameters

        • Optional values: T[]

        Returns Record<string, T>

    Throws

    If the length of the defaultValues array is larger than the length of the keys array, or if the length of the values array passed to the factory function is larger than the length of the keys array.

    Example

    createObjectFactory(['key1', 'key2'], ['default1', 'default2'])(['value1']);
    //=> { key1: 'value1', key2: 'default2' }

Generated using TypeDoc