@unikue/ts-multi-map
    Preparing search index...

    Class MultiValueMap<K, V>

    Map with entries that contains a single key and multiple values

    David Hsing

    Type Parameters

    • K
    • V

    Implements

    • Omit<
          Map<K, V[]>,

              | "delete"
              | "forEach"
              | "get"
              | "has"
              | "set"
              | "entries"
              | "keys"
              | "values"
              | "push",
      >
    Index

    Constructors

    Accessors

    • get "[toStringTag]"(): string

      Returns the string representation of the map identifier ('MultiValueMap')

      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[]]>

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

      Returns void

    • Deletes the entry with the given key

      Parameters

      • key: K

        the key to delete

      Returns boolean

      whether the entry has been deleted

      map.deleteByKey('color');
      
    • Deletes all the entries with any of the given keys

      Parameters

      • keys: K[]

        the keys to delete

      Returns boolean

      whether any of the entries has been deleted

      map.deleteByKeys(['color', 'position']);
      
    • Deletes the entry/entries with the given value

      Parameters

      • value: V

        the value to delete

      Returns boolean

      whether the entry/entries has been deleted

      map.deleteByValue('red');
      
    • Deletes all the entries with any of the given values

      Parameters

      • values: V[]

        the values to delete

      Returns boolean

      whether any of the entries has been deleted

      map.deleteByValues(['green', 'blue']);
      
    • Deletes a value for the given key from the map, keeping other values

      Parameters

      • key: K

        the key to operate

      • value: V

        the value to delete

      Returns boolean

      whether the value has been removed

      map.deleteValueOfKey('color', 'blue');
      
    • 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

      • 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

      • 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

      • 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 = MultiValueMap.of([
      ['color', ['red', 'green', 'blue']]
      ]);
      map.get('color'); // ['red', 'green', 'blue']
      map.get('foobar', ['foo', 'bar']); // ['foo', 'bar']
    • Returns the key with the given values

      Parameters

      • values: V[]

        the values to inspect

      • Optionaldefaults: K

        the default key if nothing matches the given value

      Returns undefined | K

      the key with the given value

      map.getKey(['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 = MultiValueMap.of([
      ['color', ['red', 'green', 'blue']]
      ]);
      map.hasAnyKeys(['color', 'position']);
    • 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 = MultiValueMap.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']]);
    • 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 = MultiValueMap.of([
      ['color', ['red', 'green', 'blue']]
      ]);
      map.hasKeyValue('color', 'red'); // true
      map.hasKeyValue('color', 'black');
    • 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 = MultiValueMap.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);
    • 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

    • Push values onto the given key, the values will be appended to the given key

      Parameters

      • key: K

        the key to operate

      • values: V[]

        the values to push

      Returns void

      map.push('color', ['yellow', 'black']);
      
    • Sets the values of the given key

      Parameters

      • key: K

        the key to set

      • values: V[]

        the values to set

      Returns void

      map.set('color', ['red', 'green', 'blue']);
      
    • Returns the string representation of the map elements

      Returns string

      the string representation of the map elements

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

      Returns V[][]

      the values array of the map