Options
All
  • Public
  • Public/Protected
  • All
Menu

build-object-better - v1.2.7

Index

Type aliases

Functions

Type aliases

Primitive

Primitive: string | number | boolean | bigint | symbol | undefined | null

A pragmatic definition of a primitive type, which is to say, something we can differentiate from the other ValueSuppliers: arrays, functions, and objects.

Functions

buildObject

  • buildObject<V>(source: {}): {}
  • buildObject<V>(entries: Iterable<[string, V]>): {}
  • buildObject<V>(entryObjects: Iterable<{ key: string; value: V }>): {}
  • buildObject<E, V>(source: {}, valueFunc: (key: string, index?: number, keys?: Iterable<string>, element?: E, elements?: Iterable<E>) => V): {}
  • buildObject<E, V>(source: {}, values: V[]): {}
  • buildObject<E, V>(source: {}, valueSource: {}): {}
  • buildObject<E, V>(source: {}, fixedVal: V): {}
  • buildObject<E, V>(keys: Iterable<E>, valueFunc: (key: string, index?: number, keys?: Iterable<string>, element?: E, elements?: Iterable<E>) => V): {}
  • buildObject<E, V>(keys: Iterable<E>, valueFunc: (key: string, index?: number, keys?: Iterable<string>, element?: E, elements?: Iterable<E>) => V): {}
  • buildObject<E, V>(keys: Iterable<E>, values: V[]): {}
  • buildObject<E, V>(keys: Iterable<E>, valueSource: {}): {}
  • buildObject<E, V>(keys: Iterable<E>, fixedVal: V): {}
  • buildObject<E, V>(elements: Iterable<E>, keyFunc: (element: E, idx?: number, elements?: Iterable<E>) => string, valueFunc: (key: string, idx?: number, keys?: Iterable<string>, element?: E, elements?: Iterable<E>) => V): {}
  • buildObject<E, V>(elements: Iterable<E>, keyFunc: (element: E, idx?: number, elements?: Iterable<E>) => string, values: V[]): {}
  • buildObject<E, V>(elements: Iterable<E>, keyFunc: (element: E, idx?: number, elements?: Iterable<E>) => string, valueSource: {}): {}
  • buildObject<E, V>(elements: Iterable<E>, keyFunc: (element: E, idx?: number, elements?: Iterable<E>) => string, fixedValue: V): {}
  • buildObject<E, V>(elements: Iterable<E>, keys: string[], valueFunc: (key: string, idx?: number, keys?: Iterable<string>, element?: E, elements?: Iterable<E>) => V): {}
  • buildObject<E, V>(elements: Iterable<E>, keys: string[], values: V[]): {}
  • buildObject<E, V>(elements: Iterable<E>, keys: string[], valueSource: {}): {}
  • buildObject<E, V>(elements: Iterable<E>, keys: string[], fixedValue: V): {}
  • buildObject<E, V>(elements: Iterable<E>, keySource: {}, valueFunc: (key: string, idx?: number, keys?: Iterable<string>, element?: E, elements?: Iterable<E>) => V): {}
  • buildObject<E, V>(elements: Iterable<E>, keySource: {}, values: V[]): {}
  • buildObject<E, V>(elements: Iterable<E>, keySource: {}, valueSource: {}): {}
  • buildObject<E, V>(elements: Iterable<E>, keySource: {}, fixedValue: V): {}
  • Create a new object as a shallow clone of the given object.

    Type parameters

    • V

    Parameters

    • source: {}

      The object to clone.

      • [key: string]: V | undefined

    Returns {}

    • [key: string]: V | undefined
  • Create an object from an iterable of key-value pairs, each pair defining one property in the created object.

    Type parameters

    • V

    Parameters

    • entries: Iterable<[string, V]>

      The list of key-value pairs.

    Returns {}

    • [key: string]: V | undefined
  • Create an object from an iterable of key-value pairs, each pair defining one property in the created object.

    Type parameters

    • V

    Parameters

    • entryObjects: Iterable<{ key: string; value: V }>

    Returns {}

    • [key: string]: V | undefined
  • Create an object by transforming the property values of a source object. The returned object has all the same property names as the source object, but with (possibly) different values, as generated by the given valueFunc.

    The valueFunc is invoked with each "key" (a property name from the source object), the index of the property (based on iteration order of the source object's properties), a list of all the keys, the corresponding "element" (property value) from the source, and a list of all the element values.

    Note that only the enumerable properties of the source object are used.

    > buildObject(
     {a: "foo", b: "bar" },
     (k, i, ks, e) => `${k}-${e}`
    )
    { a: "a-foo", b: "b-bar" }

    Type parameters

    • E

    • V

    Parameters

    • source: {}

      The source object.

      • [key: string]: E | undefined
    • valueFunc: (key: string, index?: number, keys?: Iterable<string>, element?: E, elements?: Iterable<E>) => V

      A function that generates property values for the output object.

        • (key: string, index?: number, keys?: Iterable<string>, element?: E, elements?: Iterable<E>): V
        • Parameters

          • key: string
          • Optional index: number
          • Optional keys: Iterable<string>
          • Optional element: E
          • Optional elements: Iterable<E>

          Returns V

    Returns {}

    • [key: string]: V | undefined
  • Create an object by replacing the property values of a source object with corresponding values from an array of values. The returned object has all the same property names as the source object, but with (possibly) different values, as provided by the values array.

    The enumerable properties of the source object are iterated over and paired with corresponding values from values; the property values of the source object are ignored.

    > buildObject(
     {a: "foo", b: "bar" },
     ["one", "two", "ignored"]
    )
    { a: "one", b: "two" }

    Type parameters

    • E

    • V

    Parameters

    • source: {}

      The source object.

      • [key: string]: E | undefined
    • values: V[]

      The array of property values.

    Returns {}

    • [key: string]: V | undefined
  • Create an object by replacing the property values of a source object with corresponding values from another object.

    Note that only the enumerable properties of the source object are used; the property values of the source object are ignored.

    > buildObject(
     {b: 1, d: 2},
     {e: 10, d: 20, c: 30, b: 40, a: 50 }
    )
    { b: 40, d: 20 }

    Type parameters

    • E

    • V

    Parameters

    • source: {}

      The source object.

      • [key: string]: E | undefined
    • valueSource: {}

      The object from which property values are taken.

      • [key: string]: V | undefined

    Returns {}

    • [key: string]: V | undefined
  • Create an object by replacing the property value of every property in a source object with the given fixed value.

    Note that only the enumerable properties of the source object are used; the property values of the source object are ignored. This only works for primitive typed values.

    > buildObject(
     {b: 1, d: 2},
     "the one and only"
    )
    { b: "the ony and only", d: "the one and only" }

    Type parameters

    Parameters

    • source: {}

      The source object.

      • [key: string]: E | undefined
    • fixedVal: V

      The value to use for every property.

    Returns {}

    • [key: string]: V | undefined
  • Creates an object from a list (or other iterable) of "keys" (property values) and a function which generates the property values.

    The valueFunc is invoked with each "key" (a property name from the source object), the index of the property (based on iteration order of the source object's properties), a list of all the keys, the corresponding "element" (property value) from the source, and a list of all the element values. In this case, the keys and the elements are identical.

    Note that only the enumerable properties of the source object are used.

    > buildObject(
     ["a", "b"],
     (k, i, ks, e) => `${k}-${e}`
    )
    { a: "a-a", b: "b-b" }

    Type parameters

    • E: string

    • V

    Parameters

    • keys: Iterable<E>

      The iterable of keys (property names).

    • valueFunc: (key: string, index?: number, keys?: Iterable<string>, element?: E, elements?: Iterable<E>) => V

      A function that generates property values for the output object.

        • (key: string, index?: number, keys?: Iterable<string>, element?: E, elements?: Iterable<E>): V
        • Parameters

          • key: string
          • Optional index: number
          • Optional keys: Iterable<string>
          • Optional element: E
          • Optional elements: Iterable<E>

          Returns V

    Returns {}

    • [key: string]: V | undefined
  • Creates an object from a list (or other iterable) of "keys" (property values) and a function which generates the property values.

    The valueFunc is invoked with each "key" (a property name from the source object), the index of the property (based on iteration order of the source object's properties), a list of all the keys, the corresponding "element" (property value) from the source, and a list of all the element values. In this case, the keys and the elements are identical.

    Note that only the enumerable properties of the source object are used.

    > buildObject(
     ["a", "b"],
     (k, i, ks, e) => `${k}-${e}`
    )
    { a: "a-a", b: "b-b" }

    Type parameters

    • E: string

    • V

    Parameters

    • keys: Iterable<E>

      The iterable of keys (property names).

    • valueFunc: (key: string, index?: number, keys?: Iterable<string>, element?: E, elements?: Iterable<E>) => V

      A function that generates property values for the output object.

        • (key: string, index?: number, keys?: Iterable<string>, element?: E, elements?: Iterable<E>): V
        • Parameters

          • key: string
          • Optional index: number
          • Optional keys: Iterable<string>
          • Optional element: E
          • Optional elements: Iterable<E>

          Returns V

    Returns {}

    • [key: string]: V | undefined
  • Create an object by pairing corresponding elements from a list of keys (property names) and a list of values. Any iterable can be used in place of a list for the keys, but only an array can be used for the values.

    > buildObject(
     ["a", "b"],
     ["one", "two", "ignored"]
    )
    { a: "one", b: "two" }

    Type parameters

    • E: string

    • V

    Parameters

    • keys: Iterable<E>

      The keys (property names).

    • values: V[]

      The array of property values.

    Returns {}

    • [key: string]: V | undefined
  • Create an object by copying the specified properties from the given object.

    > buildObject(
     ["b", "d"],
     {e: 10, d: 20, c: 30, b: 40, a: 50 }
    )
    { b: 40, d: 20 }

    Type parameters

    • E

    • V

    Parameters

    • keys: Iterable<E>

      The keys (property names).

    • valueSource: {}

      The object from which property values are taken.

      • [key: string]: V | undefined

    Returns {}

    • [key: string]: V | undefined
  • Create an object with the named properties, all of whom share the same primitive value.

    > buildObject(
     ["b", "d"],
     "the one and only"
    )
    { b: "the ony and only", d: "the one and only" }

    Note this only works for primitive typed values.

    Type parameters

    Parameters

    • keys: Iterable<E>

      The keys (property names).

    • fixedVal: V

      The value to use for every property.

    Returns {}

    • [key: string]: V | undefined
  • Create an object by iterating over a set of elements and defining one property for each. Property names ("keys") are determined for each element from the given keyFunc, and property values are determined from the given valueFunc.

    The keyFunc is invoked with each element and it's index within elements, plus a full list of all the elements, and the valueFunc is invoked with each key (property name) produced by the keyFunc, the index, the set of all produced keys, plus the corresponding elements and the set of all elements.

    > buildObject(
     ["b", "d"],
     e => e.toUpperCase(),
     (k, i, ks, e) => `${k}-${e}`
    )
    { B: "B-b", D: "D-d" }

    Type parameters

    • E

    • V

    Parameters

    • elements: Iterable<E>

      The elements from which the properties are derived.

    • keyFunc: (element: E, idx?: number, elements?: Iterable<E>) => string

      The function that caluclates property names from elements.

        • (element: E, idx?: number, elements?: Iterable<E>): string
        • Parameters

          • element: E
          • Optional idx: number
          • Optional elements: Iterable<E>

          Returns string

    • valueFunc: (key: string, idx?: number, keys?: Iterable<string>, element?: E, elements?: Iterable<E>) => V

      The function that calculates property values from keys and/or elements.

        • (key: string, idx?: number, keys?: Iterable<string>, element?: E, elements?: Iterable<E>): V
        • Parameters

          • key: string
          • Optional idx: number
          • Optional keys: Iterable<string>
          • Optional element: E
          • Optional elements: Iterable<E>

          Returns V

    Returns {}

    • [key: string]: V | undefined
  • Create an object by iterating over a set of elements and defining one property for each. Property names ("keys") are determined for each element from the given keyFunc, and property values are taken from the corresponding index in the provided array.

    The keyFunc is invoked with each element and it's index within elements, plus a full list of all the elements.

    > buildObject(
     ["b", "d"],
     e => e.toUpperCase(),
     (k, i, ks, e) => `${k}-${e}`
    )
    { B: "B-b", D: "D-d" }

    Type parameters

    • E

    • V

    Parameters

    • elements: Iterable<E>

      The elements from which the properties are derived.

    • keyFunc: (element: E, idx?: number, elements?: Iterable<E>) => string

      The function that caluclates property names from elements.

        • (element: E, idx?: number, elements?: Iterable<E>): string
        • Parameters

          • element: E
          • Optional idx: number
          • Optional elements: Iterable<E>

          Returns string

    • values: V[]

      The property values.

    Returns {}

    • [key: string]: V | undefined
  • Create an object by iterating over a set of elements and defining one property for each. Property names ("keys") are determined for each element from the given keyFunc, and property values are taken from the corresponding properties of the given valueSource object (the property named by the produced key).

    The keyFunc is invoked with each element and it's index within elements, plus a full list of all the elements.

    Type parameters

    • E

    • V

    Parameters

    • elements: Iterable<E>

      The elements from which the properties are derived.

    • keyFunc: (element: E, idx?: number, elements?: Iterable<E>) => string

      The function that caluclates property names from elements.

        • (element: E, idx?: number, elements?: Iterable<E>): string
        • Parameters

          • element: E
          • Optional idx: number
          • Optional elements: Iterable<E>

          Returns string

    • valueSource: {}

      The object that provides the property values.

      • [key: string]: V | undefined

    Returns {}

    • [key: string]: V | undefined
  • Create an object by iterating over a set of elements and defining one property for each, using the same fixedValue for each property. Property names ("keys") are determined for each element from the given keyFunc.

    The keyFunc is invoked with each element and it's index within elements, plus a full list of all the elements.

    Type parameters

    Parameters

    • elements: Iterable<E>

      The elements from which the properties are derived.

    • keyFunc: (element: E, idx?: number, elements?: Iterable<E>) => string

      The function that caluclates property names from elements.

        • (element: E, idx?: number, elements?: Iterable<E>): string
        • Parameters

          • element: E
          • Optional idx: number
          • Optional elements: Iterable<E>

          Returns string

    • fixedValue: V

      The value to use for all properties.

    Returns {}

    • [key: string]: V | undefined
  • Create an object by iterating over a set of elements and defining one property for each. Property names ("keys") are taken from the corresponding index of the provided keys array, and property values are determined from the given valueFunc.

    The valueFunc is invoked with each key (property name) produced by the keyFunc, the index, the set of all produced keys, plus the corresponding elements and the set of all elements.

    Type parameters

    • E

    • V

    Parameters

    • elements: Iterable<E>

      The elements from which the properties are derived.

    • keys: string[]

      The array of keys.

    • valueFunc: (key: string, idx?: number, keys?: Iterable<string>, element?: E, elements?: Iterable<E>) => V

      The function that calculates property values from keys and/or elements.

        • (key: string, idx?: number, keys?: Iterable<string>, element?: E, elements?: Iterable<E>): V
        • Parameters

          • key: string
          • Optional idx: number
          • Optional keys: Iterable<string>
          • Optional element: E
          • Optional elements: Iterable<E>

          Returns V

    Returns {}

    • [key: string]: V | undefined
  • Create an object by iterating over a set of elements and defining one property for each. Property names ("keys") are taken from the corresponding index of the provided keys array, and property values are taken from the corresponding index in the provided values array.

    Type parameters

    • E

    • V

    Parameters

    • elements: Iterable<E>

      The elements from which the properties are derived.

    • keys: string[]

      The array of keys.

    • values: V[]

      The property values.

    Returns {}

    • [key: string]: V | undefined
  • Create an object by iterating over a set of elements and defining one property for each. Property names ("keys") are taken from the corresponding index of the provided keys array, and property values are taken from the corresponding properties of the given valueSource object (the property named by the key).

    Type parameters

    • E

    • V

    Parameters

    • elements: Iterable<E>

      The elements from which the properties are derived.

    • keys: string[]

      The array of keys.

    • valueSource: {}

      The object that provides the property values.

      • [key: string]: V | undefined

    Returns {}

    • [key: string]: V | undefined
  • Create an object by iterating over a set of elements and defining one property for each, using the same fixedValue for each property. Property names ("keys") are taken from the corresponding index of the provided keys array.

    Type parameters

    Parameters

    • elements: Iterable<E>

      The elements from which the properties are derived.

    • keys: string[]

      The array of keys.

    • fixedValue: V

      The value to use for all properties.

    Returns {}

    • [key: string]: V | undefined
  • Create an object by iterating over a set of elements and defining one property for each. Property names ("keys") are taken from the corresponding property of the provided keySource object, and property values are determined from the given valueFunc.

    The valueFunc is invoked with each key (property name) produced by the keyFunc, the index, the set of all produced keys, plus the corresponding elements and the set of all elements.

    Type parameters

    • E: string

    • V

    Parameters

    • elements: Iterable<E>

      The elements from which the properties are derived.

    • keySource: {}
      • [key: string]: string | undefined
    • valueFunc: (key: string, idx?: number, keys?: Iterable<string>, element?: E, elements?: Iterable<E>) => V

      The function that calculates property values from keys and/or elements.

        • (key: string, idx?: number, keys?: Iterable<string>, element?: E, elements?: Iterable<E>): V
        • Parameters

          • key: string
          • Optional idx: number
          • Optional keys: Iterable<string>
          • Optional element: E
          • Optional elements: Iterable<E>

          Returns V

    Returns {}

    • [key: string]: V | undefined
  • Create an object by iterating over a set of elements and defining one property for each. Property names ("keys") are taken from the corresponding property of the provided keySource object, and property values are taken from the corresponding index in the provided values array.

    Type parameters

    • E

    • V

    Parameters

    • elements: Iterable<E>

      The elements from which the properties are derived.

    • keySource: {}
      • [key: string]: string | undefined
    • values: V[]

      The property values.

    Returns {}

    • [key: string]: V | undefined
  • Create an object by iterating over a set of elements and defining one property for each. Property names ("keys") are taken from the corresponding property of the provided keySource object, and property values are taken from the corresponding properties of the given valueSource object (the property named by the key).

    Type parameters

    • E

    • V

    Parameters

    • elements: Iterable<E>

      The elements from which the properties are derived.

    • keySource: {}
      • [key: string]: string | undefined
    • valueSource: {}

      The object that provides the property values.

      • [key: string]: V | undefined

    Returns {}

    • [key: string]: V | undefined
  • Create an object by iterating over a set of elements and defining one property for each, using the same fixedValue for each property. Property names ("keys") are taken from the corresponding property of the provided keySource object, and property values are taken from the corresponding properties of the given

    Type parameters

    Parameters

    • elements: Iterable<E>

      The elements from which the properties are derived.

    • keySource: {}
      • [key: string]: string | undefined
    • fixedValue: V

      The value to use for all properties.

    Returns {}

    • [key: string]: V | undefined

Generated using TypeDoc