Options
All
  • Public
  • Public/Protected
  • All
Menu

Module "invert"

Index

Functions

Const invertMap

  • invertMap<K, V>(src: Map<K, V>, dest?: Map<V, K>): Map<V, K>
  • Returns a new map in which the original values are used as keys and original keys as values. If dest is given, writes results in that map instead. Depending on the value type of src and/or if the inverted map should use custom key equality semantics as provided by the Map types in this package, you MUST provide a dest map, since the default dest will only be a standard ES6 Map.

    example
    invertMap(new Map(), new Map([["a", 1], ["b", 2]]));
    // Map { 1 => 'a', 2 => 'b' }

    Type parameters

    • K

    • V

    Parameters

    • src: Map<K, V>

      map to invert

    • Optional dest: Map<V, K>

      result map

    Returns Map<V, K>

Const invertObj

  • invertObj(src: IObjectOf<PropertyKey>, dest?: IObjectOf<PropertyKey>): IObjectOf<string | number | symbol>
  • Returns a new object in which the original values are used as keys and original keys as values. If dest is given, writes results in that object instead.

    example
    invertObj({a: 1, b: 2})
    // { '1': 'a', '2': 'b' }

    Parameters

    • src: IObjectOf<PropertyKey>

      object to invert

    • Default value dest: IObjectOf<PropertyKey> = {}

      result object

    Returns IObjectOf<string | number | symbol>

Generated using TypeDoc