Class ReadonlyMultiValueMap<K, V>

Readonly map with entries that contains a single key and multiple values

David Hsing

Type Parameters

  • K
  • V

Implements

  • Omit<ReadonlyMap<K, V[]>,
        | "forEach"
        | "get"
        | "has"
        | "entries"
        | "keys"
        | "values">

Constructors

  • Construct a readonly multi value map instance

    Type Parameters

    • K
    • V

    Parameters

    Returns ReadonlyMultiValueMap<K, V>

    const map = new ReadonlyMultiValueMap([
    ['color', ['red', 'green', 'blue']]
    ]);

Accessors

  • get [toStringTag](): string
  • Returns the string representation of the map identifier ('ReadonlyMultiValueMap')

    Returns string

    the string representation of the map identifier

  • get size(): number
  • Returns the size of map

    Returns number

    the size of map

Methods

  • Response for returning the list of key/values to iterate

    Returns IterableIterator<[K, V[]], any, any>

    for (const [key, values] of map) {
    console.log(key);
    }
  • Returns the key/values entries of the map

    Returns [K, V[]][]

    the key/values entries of the map

  • Processes each entry in the map

    Parameters

    • callback: ((values: V[], key: K) => void)

      a callback function that processes each entry

        • (values, key): void
        • Parameters

          • values: V[]
          • key: K

          Returns void

    • OptionalthisArg: any

      any instance to retrieve 'this' reference in the callback function

    Returns void

    map.forEach((values, key) => {
    console.log(key);
    });
  • Processes each entry in the map with breakable capability

    Parameters

    • callback: ((values: V[], key: K) => boolean)

      a callback function that processes each entry. Returning false indicates to break the map iteration

        • (values, key): boolean
        • Parameters

          • values: V[]
          • key: K

          Returns boolean

    • OptionalthisArg: any

      any instance to retrieve 'this' reference in the callback function

    Returns void

    map.forEachBreakable((values, key) => {
    return true;
    });
  • Processes each entry in the map with index capability

    Parameters

    • callback: ((values: V[], key: K, index: number) => void)

      a callback function that processes each entry

        • (values, key, index): void
        • Parameters

          • values: V[]
          • key: K
          • index: number

          Returns void

    • OptionalthisArg: any

      any instance to retrieve 'this' reference in the callback function

    Returns void

    map.forEachIndexing((values, key, index) => {
    console.log(index);
    });
  • Returns the values of the given key

    Parameters

    • key: K

      the key to retrieve

    • Optionaldefaults: V[]

      the default values if not found

    Returns undefined | V[]

    the values of the given key

    const map = ReadonlyMultiValueMap.of([
    ['color', ['red', 'green', 'blue']]
    ]);
    map.get('color'); // ['red', 'green', 'blue']
    map.get('foobar', ['foo', 'bar']); // ['foo', 'bar']
  • Returns whether the map contains all the given keys

    Parameters

    • keys: K[]

      the keys to check

    Returns boolean

    whether the map contains all the given keys

    map.hasAllKeys(['color', 'position']);
    
  • Returns whether the map contains all the given values

    Parameters

    • values: V[][]

      the values to check

    • exact: boolean = true

      whether matching entry values exactly

    Returns boolean

    whether the map contains all the given values

    map.hasAllValues([['red', 'green', 'blue'], ['top', 'right', 'bottom', 'left']]);
    
  • Returns whether the map contains any of the given keys

    Parameters

    • keys: K[]

      the keys to check

    Returns boolean

    whether the map contains any of the given keys

    const map = ReadonlyMultiValueMap.of([
    ['color', ['red', 'green', 'blue']]
    ]);
    map.hasAnyKeys(['color', 'position']); // true
  • Returns whether the map contains any of the given values

    Parameters

    • values: V[][]

      the values to check

    • exact: boolean = true

      whether matching entry values exactly

    Returns boolean

    whether the map contains any of the given values

    const map = ReadonlyMultiValueMap.of([
    ['color', ['red', 'green', 'blue']],
    ['position', ['top', 'right', 'bottom', 'left']]
    ]);
    map.hasAnyValues([['red', 'black'], ['green', 'blue']]); // false
    map.hasAnyValues([['top', 'right'], ['top', 'right', 'bottom', 'left']]); // true
  • Returns whether the map contains the given key

    Parameters

    • key: K

      the key to check

    Returns boolean

    whether the map contains the given key

    map.hasKey('color');
    
  • Returns whether the map contains the given key/value pair

    Parameters

    • key: K

      the key to check

    • value: V

      the value to check

    Returns boolean

    whether the map contains the given key/value pair

    const map = ReadonlyMultiValueMap.of([
    ['color', ['red', 'green', 'blue']]
    ]);
    map.hasKeyValue('color', 'red'); // true
    map.hasKeyValue('color', 'black'); // false
  • Returns whether any entries of the map that contains the given values

    Parameters

    • values: V[]

      the values to check

    • exact: boolean = true

      whether matching entry values exactly

    Returns boolean

    whether any entries of the map that contains the given values

    const map = ReadonlyMultiValueMap.of([
    ['color', ['red', 'green', 'blue']],
    ['position', ['top', 'right', 'bottom', 'left']]
    ]);
    map.hasValue(['red', 'black'], true); // false
    map.hasValue(['top', 'right'], true); // false
    map.hasValue(['top', 'right'], false); // true
  • Returns whether the map is empty

    Returns boolean

    whether the map is empty

  • Returns whether the map is not empty

    Returns boolean

    whether the map is not empty

  • Returns the keys of the map

    Returns K[]

    the keys of the map

  • Returns the string representation of the map elements

    Returns string

    the string representation of the map elements

    const map = ReadonlyMultiValueMap.of([
    ['color', ['red', 'green', 'blue']],
    ['position', ['top', 'right', 'bottom', 'left']]
    ]);
    console.log(map.toString()); // 'color:[red,green,blue];position:[top,right,bottom,left]'
  • Returns the values array of the map

    Returns V[][]

    the values array of the map

  • Construct a readonly multi value map instance

    Type Parameters

    • K
    • V

    Parameters

    Returns ReadonlyMultiValueMap<K, V>

    a readonly multi value map instance

    const map = ReadonlyMultiValueMap.of([
    ['color', ['red', 'green', 'blue']]
    ]);