Options
All
  • Public
  • Public/Protected
  • All
Menu

lightdash

Index

Type aliases

ArrayIterator<TValue, UResult>: (value: TValue, index: number, collection: ReadonlyArray<TValue>) => UResult

Type parameters

  • TValue

  • UResult

Type declaration

    • (value: TValue, index: number, collection: ReadonlyArray<TValue>): UResult
    • Function called for each item in an array.

      Parameters

      • value: TValue
      • index: number
      • collection: ReadonlyArray<TValue>

      Returns UResult

Array Functions

  • countMapBy<TValue, UKey>(array: readonly TValue[], keyMapper: ArrayIterator<TValue, UKey>): Map<UKey, number>
  • Counts the values of an array into a map, with the key being based on a key mapper and the value being the occurrences of the key mapper result in the initial array.

    since

    12.0.0

    see

    groupMapBy

    see

    groupMapReducingBy

    example

    countMapBy([1, 2, 4, 2, 4, 4], val => val) // => Map{1: 1, 2: 2, 4: 3}

    Type parameters

    • TValue

    • UKey

    Parameters

    • array: readonly TValue[]

      Array to count.

    • keyMapper: ArrayIterator<TValue, UKey>

      Function to use for key generation.

    Returns Map<UKey, number>

    Count map.

  • groupMapBy<TValue, UKey>(array: readonly TValue[], keyMapper: ArrayIterator<TValue, UKey>): Map<UKey, TValue[]>
  • Groups the elements of an array into a map, with the key being based on a key mapper and the value being the values for the same key mapper result.

    since

    6.1.0

    see

    groupMapReducingBy

    example

    groupMapBy([1, 2, 3, 4, 5], val => val % 2) // => Map{0: [2, 4], 1: [1, 3, 5]}

    Type parameters

    • TValue

    • UKey

    Parameters

    • array: readonly TValue[]

      Array to group.

    • keyMapper: ArrayIterator<TValue, UKey>

      Function returning the key for the value.

    Returns Map<UKey, TValue[]>

    Grouped map.

  • groupMapReducingBy<TValue, UKey, VReduced>(array: readonly TValue[], keyMapper: ArrayIterator<TValue, UKey>, initializer: ArrayIterator<TValue, VReduced>, reducer: (current: VReduced, value: TValue, index: number, collection: readonly TValue[]) => VReduced): Map<UKey, VReduced>
  • Groups the elements of an array into a map, with the key being based on a key mapper and the value being the values for the same key mapper result being reduced.

    since

    11.0.0

    see

    groupMapBy

    see

    countMapBy

    example

    groupMapReducingBy( ["foo", "bar", "fizz", "buzz"], val => val.charAt(0), () => { return { count: 0, matches: [] }; }, (current, val) => { current.count++; current.matches.push(val); return current; } ) // => Map{"f": {count: 2, matches: ["foo", "fizz"]}, "b": {count: 2, matches: ["bar", "buzz"]}}

    Type parameters

    • TValue

    • UKey

    • VReduced

    Parameters

    • array: readonly TValue[]

      Array to group.

    • keyMapper: ArrayIterator<TValue, UKey>

      Function returning the key for the value.

    • initializer: ArrayIterator<TValue, VReduced>

      Function initializing a new reduction result object.

    • reducer: (current: VReduced, value: TValue, index: number, collection: readonly TValue[]) => VReduced

      Consumer creating a new reduction result object based on the previous result and the new data.

        • (current: VReduced, value: TValue, index: number, collection: readonly TValue[]): VReduced
        • Parameters

          • current: VReduced
          • value: TValue
          • index: number
          • collection: readonly TValue[]

          Returns VReduced

    Returns Map<UKey, VReduced>

    Grouped and reduced map.

  • insertAt<TValue>(array: TValue[], index: number, ...values: TValue[]): TValue[]
  • Inserts the value(s) at the given position. If the index is equal or higher than the array length, the value(s) will be appended. If the index is less than 0, the value(s) will be prepended.

    Note that the input array is being mutated.

    since

    12.1.0

    see

    lodash.pullAt

    example

    const a = ["foo", "fizz"]; insertAt(a, 1, "bar") // => ["foo", "bar", "fizz"]

    const b = ["foo", "fizz"]; insertAt(b, 1, "bar", "bazz")) // => ["foo", "bar", "fizz", "bazz"]

    const c = ["foo", "fizz"]; insertAt(c, 999, "bar")) // => ["foo", "fizz", "bar"]

    const d = ["foo", "fizz"]; insertAt(d, -999, "bar")) // => ["bar", "foo", "fizz"]

    Type parameters

    • TValue

    Parameters

    • array: TValue[]

      Array to modify.

    • index: number

      Index to insert at.

    • Rest ...values: TValue[]

      Value(s) to insert.

    Returns TValue[]

    The mutated array.

  • pullFirst<TValue>(array: TValue[], value: TValue): TValue[]
  • Removes the first occurrence of an element from an array. If the element does not exist in the array nothing is done.

    Note that the input array is being mutated.

    since

    2.8.0

    see

    lodash.pullAt

    example

    const a = ["foo", "bar", "fizz", "bar"]; removeItem(a, "bar") // => ["foo", "fizz", "bar"]

    const b = ["foo", "bar", "fizz", "bar"]; removeItem(b, "bazz") // => ["foo", "bar", "fizz", "bar"]

    Type parameters

    • TValue

    Parameters

    • array: TValue[]

      Array to modify.

    • value: TValue

      The value to remove.

    Returns TValue[]

    The mutated array.

  • step<TValue>(array: readonly TValue[], stepSize: number): TValue[]
  • Returns a new array with every n-th item from the input array.

    since

    1.0.0

    example

    step([1, 2, 3, 4, 5, 6], 2) // => [1, 3, 5]

    Type parameters

    • TValue

    Parameters

    • array: readonly TValue[]

      Array to use.

    • stepSize: number

      Step to use.

    Returns TValue[]

    Stepped collection.

Lang Functions

  • isBlank(string: string): boolean
  • Checks if the string is blank (has no non-space content).

    since

    11.0.0

    example

    isBlank("") // => true

    isBlank(" ") // => true

    isBlank(" foo ") // => false

    Parameters

    • string: string

      String to use.

    Returns boolean

    If the string is blank.

  • isPromise(value: unknown): value is Promise<unknown>
  • Checks if a value is a promise.

    since

    3.0.0

    example

    isPromise(new Promise((resolve, reject) => resolve("foo"))); // => true

    isPromise(() => "foo"); // => false

    Parameters

    • value: unknown

      Value to check.

    Returns value is Promise<unknown>

    If the value is a promise.

  • name(value: unknown): null | string
  • Gets the name of a value.

    If the value is a function, its name is returned. If the value is a symbol, its key is returned. If the value is a string, it is returned as is. Otherwise, null is returned.

    since

    10.2.0

    example

    name(class Foo{}) // => "Foo"

    name(function bar(){}) // => "bar"

    name(Symbol.for("abc")) // => "abc"

    name("foo") // => "foo"

    name(1) // => null

    Parameters

    • value: unknown

      Value to check.

    Returns null | string

    The name of the value.

  • requireNonNilElseThrow<T>(value: undefined | null | T, errorSupplier: () => Error): T
  • Throws an exception if the value is nil, returns the value otherwise.

    since

    13.0.0

    throws

    Error if value is nil.

    example

    requireNonNilElseThrow("foo", () => new TypeError()) // => "foo"

    requireNonNilElseThrow(null, () => new TypeError()) // => throws TypeError

    Type parameters

    • T

    Parameters

    • value: undefined | null | T

      Value to check.

    • errorSupplier: () => Error

      Supplier for the error to be thrown.

        • (): Error
        • Returns Error

    Returns T

    The value provided with guarantee to be non-nil.

  • toMap<TValue>(object: Record<PropertyKey, TValue>): Map<string, TValue>
  • Creates a map from the own entries of an object.

    since

    1.0.0

    see

    toMapBy

    example

    toMap({a: 1, b: 4, c: 5}) // => Map{"a": 1, "b": 4, "c": 5}

    Type parameters

    • TValue

    Parameters

    • object: Record<PropertyKey, TValue>

      Object to use.

    Returns Map<string, TValue>

    Map created from the object.

  • toMapBy<TValue, UKey, VInitialValue>(object: Record<PropertyKey, VInitialValue>, keyMapper: (key: string, val: VInitialValue) => UKey, valueMapper: (key: string, value: VInitialValue) => TValue): Map<UKey, TValue>
  • Creates a map from the own entries of an object.

    since

    13.0.0

    see

    toMap

    example

    toMap({a: 1, b: 4, c: 5}, key => { return { key }; }, value => value * 2) // => Map{{key: "a"}: 2, {key: "b"}: 8, {key: "a"}: 10}

    Type parameters

    • TValue

    • UKey

    • VInitialValue

    Parameters

    • object: Record<PropertyKey, VInitialValue>

      Object to use.

    • keyMapper: (key: string, val: VInitialValue) => UKey

      Function mapping an object key to a map key.

        • (key: string, val: VInitialValue): UKey
        • Parameters

          • key: string
          • val: VInitialValue

          Returns UKey

    • valueMapper: (key: string, value: VInitialValue) => TValue

      Function mapping an object value to a map value.

        • (key: string, value: VInitialValue): TValue
        • Parameters

          • key: string
          • value: VInitialValue

          Returns TValue

    Returns Map<UKey, TValue>

    Map created from the object.

Map Functions

  • getExistingElseThrow<TKey, UValue>(map: ReadonlyMap<TKey, UValue>, key: TKey): UValue
  • Gets the value of a map entry by its key, throwing if the map does not contain the key.

    since

    13.0.0

    throws

    TypeError if map does not contain key.

    example

    getExistingElseThrow(new Map([["key", 1]]), "key") // => 1

    getExistingElseThrow(new Map([["key", 1]]), "foo") // => throws TypeError

    Type parameters

    • TKey

    • UValue

    Parameters

    • map: ReadonlyMap<TKey, UValue>

      Map to check against.

    • key: TKey

      Key to get the value for.

    Returns UValue

    The corresponding value.

Object Functions

  • deepFreeze(object: object): void
  • Recursively freezes an objects and all own non-function sub-objects.

    Note that the input object is being mutated.

    since

    12.0.0

    see

    deepSeal

    see

    Object.freeze

    example

    const a = {a: {b: 2}, b: [1, {foo: "foo"}], c: 2};

    deepFreeze(a) // => object and all sub-objects are frozen.

    Parameters

    • object: object

      Object to recursively freeze.

    Returns void

  • deepSeal(object: object): void
  • Recursively seals an objects and all own non-function sub-objects.

    Note that the input object is being mutated.

    since

    12.0.0

    see

    deepFreeze

    see

    Object.seal

    example

    const a = {a: {b: 2}, b: [1, {foo: "foo"}], c: 2};

    deepSeal(a) // => object and all sub-objects are sealed.

    Parameters

    • object: object

      Object to recursively seal.

    Returns void

String Functions

  • removeEnd(string: string, removeValue: string): string
  • Removes a value from the end of a string.

    If the string does not end with the value, nothing is done.

    since

    13.0.0

    see

    removeStart

    example

    removeEnd("FooBar", "Bar") // => "Foo"

    removeEnd("FooBar", "Foo") // => "FooBar"

    removeEnd("FooBar", "Buzz") // => "FooBar"

    Parameters

    • string: string

      String to check.

    • removeValue: string

      Value to remove.

    Returns string

    String with the value removed from the end.

  • removeStart(string: string, removeValue: string): string
  • Removes a value from the start of a string.

    If the string does not start with the value, nothing is done.

    since

    13.0.0

    see

    removeEnd

    example

    removeStart("FooBar", "Foo") // => "Bar"

    removeStart("FooBar", "Bar") // => "FooBar"

    removeStart("FooBar", "Buzz") // => "FooBar"

    Parameters

    • string: string

      String to check.

    • removeValue: string

      Value to remove.

    Returns string

    String with the value removed from the start.

Generated using TypeDoc