Nutrient Web SDK

Interface Map

An immutable, unordered map of keys to values. Every change returns a new map and leaves the original untouched; a change that would not alter the map returns the same map. Keys are compared as is() does, so collections and records with equal values are the same key.

Interface

Type Parameters

K
V

Properties

size

Readonly
number

The number of entries in the map.

Methods

  • Returns an iterator over the [key, value] pairs.

    Returns

    IterableIterator<[K, V]>

    A new iterator.

  • An alias of includes.

    Parameters

    valueV

    The value to look for.

    Returns

    boolean

    true when an equal value is present.

  • Returns the number of entries.

    Returns

    number

    The size of the map.

  • Counts the entries the predicate accepts.

    Parameters

    predicate(value: V, key: K, map: NutrientViewer.Immutable.Map<K, V>) => boolean

    Called with each value, its key and the map.

    contextunknown
    Optional

    The this value for predicate.

    Returns

    number

    The number of entries it returns truthy for.

  • Returns an iterator over the [key, value] pairs.

    Returns

    IterableIterator<[K, V]>

    A new iterator.

  • Reports whether other is an unordered keyed collection, such as a map, holding equal keys and values, comparing as is() does.

    Parameters

    otherunknown

    The value to compare against.

    Returns

    boolean

    true when other is an unordered keyed collection with equal entries.

  • Reports whether the predicate accepts every entry, narrowing the collection to the type predicate guards.

    Type Parameters

    F

    Parameters

    predicate(value: V, key: K, map: NutrientViewer.Immutable.Map<K, V>) => value is F

    Called with each value, its key and the map.

    contextunknown
    Optional

    The this value for predicate.

    Returns

    true when it returns truthy for every entry, and for an empty map.

  • Reports whether the predicate accepts every entry.

    Parameters

    predicate(value: V, key: K, map: NutrientViewer.Immutable.Map<K, V>) => boolean

    Called with each value, its key and the map.

    contextunknown
    Optional

    The this value for predicate.

    Returns

    boolean

    true when it returns truthy for every entry, and for an empty map.

  • Returns the first value the predicate accepts, narrowed to the type predicate guards.

    Type Parameters

    F

    Parameters

    predicate(value: V, key: K, map: NutrientViewer.Immutable.Map<K, V>) => value is F

    Called with each value, its key and the map.

    contextunknown
    Optional

    The this value for predicate.

    Returns

    F | undefined

    The first accepted value, or undefined.

  • Returns the first value the predicate accepts.

    Type Parameters

    N

    Parameters

    predicate(value: V, key: K, map: NutrientViewer.Immutable.Map<K, V>) => boolean

    Called with each value, its key and the map.

    contextunknown

    The this value for predicate.

    notSetValueN

    Returned when no value is accepted.

    Returns

    V | N

    The first accepted value, or notSetValue.

  • Returns the first value the predicate accepts.

    Parameters

    predicate(value: V, key: K, map: NutrientViewer.Immutable.Map<K, V>) => boolean

    Called with each value, its key and the map.

    contextunknown
    Optional

    The this value for predicate.

    notSetValueV
    Optional

    Returned when no value is accepted.

    Returns

    V | undefined

    The first accepted value, or notSetValue.

  • Returns the last value the predicate accepts, narrowed to the type predicate guards.

    Type Parameters

    F

    Parameters

    predicate(value: V, key: K, map: NutrientViewer.Immutable.Map<K, V>) => value is F

    Called with each value, its key and the map.

    contextunknown
    Optional

    The this value for predicate.

    Returns

    F | undefined

    The last accepted value, or undefined.

  • Returns the last value the predicate accepts.

    Type Parameters

    N

    Parameters

    predicate(value: V, key: K, map: NutrientViewer.Immutable.Map<K, V>) => boolean

    Called with each value, its key and the map.

    contextunknown

    The this value for predicate.

    notSetValueN

    Returned when no value is accepted.

    Returns

    V | N

    The last accepted value, or notSetValue.

  • Returns the last value the predicate accepts.

    Parameters

    predicate(value: V, key: K, map: NutrientViewer.Immutable.Map<K, V>) => boolean

    Called with each value, its key and the map.

    contextunknown
    Optional

    The this value for predicate.

    notSetValueV
    Optional

    Returned when no value is accepted.

    Returns

    V | undefined

    The last accepted value, or notSetValue.

  • Returns the last [key, value] pair the predicate accepts.

    Parameters

    predicate(value: V, key: K, map: NutrientViewer.Immutable.Map<K, V>) => boolean

    Called with each value, its key and the map.

    contextunknown
    Optional

    The this value for predicate.

    notSetValue[K, V]
    Optional

    Returned when no value is accepted.

    Returns

    [K, V] | undefined

    The last accepted pair, or notSetValue.

  • Returns the key of the last entry the predicate accepts.

    Parameters

    predicate(value: V, key: K, map: NutrientViewer.Immutable.Map<K, V>) => boolean

    Called with each value, its key and the map.

    contextunknown
    Optional

    The this value for predicate.

    Returns

    K | undefined

    The key, or undefined when no value is accepted.

  • Returns the first value in iteration order.

    Returns

    V | undefined

    The first value, or undefined for an empty map.

  • Returns the first value in iteration order.

    Type Parameters

    N

    Parameters

    notSetValueN

    Returned when the map is empty.

    Returns

    V | N

    The first value, or notSetValue for an empty map.

  • Flattens nested collections, merging their entries by key.

    Parameters

    depthnumber
    Optional

    How many levels to flatten; omitted for all.

    Returns

    NutrientViewer.Immutable.Map<unknown, unknown>

    A new map.

  • Flattens nested collections, merging their entries by key.

    Parameters

    shallowboolean
    Optional

    true to flatten one level; omitted or false for all.

    Returns

    NutrientViewer.Immutable.Map<unknown, unknown>

    A new map.

  • Calls sideEffect for each entry until it returns false.

    Parameters

    sideEffect(value: V, key: K, map: NutrientViewer.Immutable.Map<K, V>) => unknown

    Called with each value, its key and the map.

    contextunknown
    Optional

    The this value for sideEffect.

    Returns

    number

    The number of entries visited, including the one that returned false.

  • Returns the value stored under key.

    Parameters

    keyK

    The key to read.

    Returns

    V | undefined

    The value, or undefined when the map has no such key.

  • Returns the value stored under key.

    Type Parameters

    N

    Parameters

    keyK

    The key to read.

    notSetValueN

    Returned when the map has no such key.

    Returns

    V | N

    The value, or notSetValue when the map has no such key.

  • Reads a value deep inside nested collections.

    Parameters

    searchKeyPathIterable<unknown>

    The keys to follow, from this map inwards.

    notSetValueunknown
    Optional

    Returned when the path does not exist.

    Returns

    unknown

    The value at the path, or notSetValue.

  • Reports whether the map has key, even when its value is undefined.

    Parameters

    keyK

    The key to look for.

    Returns

    boolean

    true when the map has an entry for key.

  • Computes a hash of this map from its contents, the same way Immutable.js does. Equal maps have equal hashes; maps with equal hashes are not necessarily equal. Plain objects, functions and symbols hash by identity, so a hash is only meaningful within the page that computed it.

    Returns

    number

    An integer hash.

  • Reports whether a path exists inside nested collections.

    Parameters

    searchKeyPathIterable<unknown>

    The keys to follow, from this map inwards.

    Returns

    boolean

    true when every key on the path exists.

  • Reports whether the map holds a value equal to value, comparing as is() does.

    Parameters

    valueV

    The value to look for.

    Returns

    boolean

    true when an equal value is present.

  • Reports whether the map has no entries.

    Returns

    boolean

    true for an empty map.

  • Reports whether every value of this map is in iter.

    Parameters

    iterIterable<V>

    The values to look in.

    Returns

    boolean

    true when each value of this map equals one in iter.

  • Reports whether every value of iter is in this map.

    Parameters

    iterIterable<V>

    The values to look for.

    Returns

    boolean

    true when each value of iter equals one in this map.

  • Joins the values into a string.

    Parameters

    separatorstring
    Optional

    Placed between values; defaults to ,.

    Returns

    string

    The joined string, with null and undefined as empty strings.

  • Returns the key of the first entry whose value equals searchValue.

    Parameters

    searchValueV

    The value to look for.

    Returns

    K | undefined

    The key, or undefined when no value is equal.

  • Returns an iterator over the keys.

    Returns

    IterableIterator<K>

    A new iterator.

  • Returns the last value in iteration order.

    Returns

    V | undefined

    The last value, or undefined for an empty map.

  • Returns the last value in iteration order.

    Type Parameters

    N

    Parameters

    notSetValueN

    Returned when the map is empty.

    Returns

    V | N

    The last value, or notSetValue for an empty map.

  • Returns the key of the last entry whose value equals searchValue.

    Parameters

    searchValueV

    The value to look for.

    Returns

    K | undefined

    The key, or undefined when no value is equal.

  • Returns a map with each entry replaced by the pair mapper returns.

    Type Parameters

    KM
    VM

    Parameters

    mapper(
    entry: [K, V],
    index: number,
    map: NutrientViewer.Immutable.Map<K, V>
    ) => [KM, VM] | undefined

    Called with each [key, value] pair, its index and the map.

    contextunknown
    Optional

    The this value for mapper.

    Returns

    A new map. Pairs that share a key keep the last value; undefined results are skipped.

  • Returns the largest value.

    Parameters

    comparator(a: V, b: V) => number
    Optional

    Orders two values; defaults to < and >.

    Returns

    V | undefined

    The largest value, or undefined for an empty map.

  • Returns the value with the largest mapped key.

    Type Parameters

    C

    Parameters

    comparatorValueMapper(value: V, key: K, map: NutrientViewer.Immutable.Map<K, V>) => C

    Maps each entry to the key to compare by.

    comparator(a: C, b: C) => number
    Optional

    Orders two mapped keys; defaults to < and >.

    Returns

    V | undefined

    The value, or undefined for an empty map.

  • Deeply merges collections into the map found at a path, creating it when missing.

    Parameters

    keyPathIterable<unknown>

    The keys to follow, from this map inwards.

    ...collectionsunknown[]

    The collections to merge in.

    Returns

    A new map, or this one when nothing changes.

  • Adds the entries of the collections, merging collections found under the same key and combining other values with merger.

    Parameters

    merger(oldVal: unknown, newVal: unknown, key: unknown) => unknown

    Returns the value to keep from the existing value, the new value and the key.

    ...collections(Iterable<[K, V], any, any> | { [key: string]: V })[]

    Collections of [key, value] pairs, or plain objects.

    Returns

    A new map, or this one when nothing changes.

  • Merges collections into the map found at a path, creating it when missing.

    Parameters

    keyPathIterable<unknown>

    The keys to follow, from this map inwards.

    ...collectionsunknown[]

    The collections to merge in.

    Returns

    A new map, or this one when nothing changes.

  • Adds the entries of the collections, combining values under a key both have.

    Type Parameters

    KC
    VC
    VCC

    Parameters

    merger(oldVal: V, newVal: VC, key: K) => VCC

    Returns the value to keep from the existing value, the new value and the key.

    ...collectionsIterable<[KC, VC], any, any>[]

    Collections of [key, value] pairs, or plain objects.

    Returns

    A new map, or this one when nothing changes.

  • Type Parameters

    C
    CC

    Parameters

    merger(oldVal: V, newVal: C, key: string) => CC
    ...collections{ [key: string]: C }[]

    Returns

    NutrientViewer.Immutable.Map<string | K, V | C | CC>
  • Returns the smallest value.

    Parameters

    comparator(a: V, b: V) => number
    Optional

    Orders two values; defaults to < and >.

    Returns

    V | undefined

    The smallest value, or undefined for an empty map.

  • Returns the value with the smallest mapped key.

    Type Parameters

    C

    Parameters

    comparatorValueMapper(value: V, key: K, map: NutrientViewer.Immutable.Map<K, V>) => C

    Maps each entry to the key to compare by.

    comparator(a: C, b: C) => number
    Optional

    Orders two mapped keys; defaults to < and >.

    Returns

    V | undefined

    The value, or undefined for an empty map.

  • Reduces the values to one, starting from the first value.

    Parameters

    reducer(reduction: V, value: V, key: K, map: NutrientViewer.Immutable.Map<K, V>) => V

    Called with the running result, each later value, its key and the map.

    Returns

    The reduced value, or undefined for an empty map.

  • Reduces the values to one.

    Type Parameters

    R

    Parameters

    reducer(reduction: R, value: V, key: K, map: NutrientViewer.Immutable.Map<K, V>) => R

    Called with the running result, each value, its key and the map.

    initialReductionR

    The starting result.

    contextunknown
    Optional

    The this value for reducer.

    Returns

    The reduced value.

  • Type Parameters

    R

    Parameters

    reducer(
    reduction: V | R,
    value: V,
    key: K,
    map: NutrientViewer.Immutable.Map<K, V>
    ) => R

    Returns

  • Reduces the values to one, from the last value to the first, starting from the last value.

    Parameters

    reducer(reduction: V, value: V, key: K, map: NutrientViewer.Immutable.Map<K, V>) => V

    Called with the running result, each earlier value, its key and the map.

    Returns

    The reduced value, or undefined for an empty map.

  • Reduces the values to one, from the last value to the first.

    Type Parameters

    R

    Parameters

    reducer(reduction: R, value: V, key: K, map: NutrientViewer.Immutable.Map<K, V>) => R

    Called with the running result, each value, its key and the map.

    initialReductionR

    The starting result.

    contextunknown
    Optional

    The this value for reducer.

    Returns

    The reduced value.

  • Type Parameters

    R

    Parameters

    reducer(
    reduction: V | R,
    value: V,
    key: K,
    map: NutrientViewer.Immutable.Map<K, V>
    ) => R

    Returns

  • Sets a value deep inside nested collections, creating maps for missing keys.

    Parameters

    keyPathIterable<unknown>

    The keys to follow, from this map inwards.

    valueunknown

    The value to store.

    Returns

    A new map, or this one when the path already holds value.

  • Returns the entries from begin up to, not including, end, in iteration order. A negative index counts from the end.

    Parameters

    beginnumber
    Optional

    The first position to keep; defaults to the start.

    endnumber
    Optional

    The position to stop before; defaults to the end.

    Returns

    A new map, or this one when begin is given and the range covers every entry.

  • Reports whether the predicate accepts any entry.

    Parameters

    predicate(value: V, key: K, map: NutrientViewer.Immutable.Map<K, V>) => boolean

    Called with each value, its key and the map.

    contextunknown
    Optional

    The this value for predicate.

    Returns

    boolean

    true when it returns truthy for at least one entry.

  • Returns the entries sorted by value. The sort is stable.

    Parameters

    comparator(a: V, b: V) => number
    Optional

    Orders two values; defaults to < and >, with undefined last.

    Returns

    OrderedMap<K, V>

    A new ordered map.

  • Returns the entries sorted by a mapped key. The sort is stable.

    Type Parameters

    C

    Parameters

    comparatorValueMapper(value: V, key: K, map: NutrientViewer.Immutable.Map<K, V>) => C

    Maps each entry to the key to sort by.

    comparator(a: C, b: C) => number
    Optional

    Orders two keys; defaults to < and >, with undefined last.

    Returns

    OrderedMap<K, V>

    A new ordered map.

  • Converts the map to an array of [key, value] pairs.

    Returns

    [K, V][]

    A new array.

  • Converts the map to plain values all the way down: nested collections, records, arrays and plain objects become plain arrays and objects.

    Returns

    PlainObjectOf<V>

    A new plain object.

  • Converts the map to an object, leaving nested collections as they are, for JSON.stringify.

    Returns

    { [key: string]: V; [key: number]: V; [key: symbol]: V }

    A new object.

  • Converts the map to an object, leaving nested collections as they are. Keys become strings.

    Returns

    { [key: string]: V }

    A new object.

  • Converts the map to an ordered map with the same iteration order.

    Returns

    OrderedMap<K, V>

    A new ordered map.

  • Converts the map to an ordered set of its values, dropping duplicates.

    Returns

    OrderedSet<V>

    A new ordered set.

  • Prints the map, for example Map { "a": 1 }.

    Returns

    string

    The printed map.

  • Replaces the value under key with the result of updater.

    Parameters

    keyK

    The key to update.

    notSetValueV

    Passed to updater when the map has no such key.

    updater(value: V) => V

    Returns the new value from the current one.

    Returns

    A new map, or this one when updater returns its argument.

  • Replaces the value under key with the result of updater.

    Parameters

    keyK

    The key to update.

    updater(value: V | undefined) => V | undefined

    Returns the new value from the current one, which is undefined when the map has no such key.

    Returns

    A new map, or this one when updater returns its argument.

  • Passes the map to updater and returns its result.

    Type Parameters

    R

    Parameters

    updater(value: NutrientViewer.Immutable.Map<K, V>) => R

    Called once with this map.

    Returns

    Whatever updater returns.

  • Replaces a value deep inside nested collections with the result of updater.

    Parameters

    keyPathIterable<unknown>

    The keys to follow, from this map inwards.

    notSetValueunknown

    Passed to updater when the path does not exist.

    updater(value: unknown) => unknown

    Returns the new value from the current one.

    Returns

    A new map, or this one when updater returns its argument.

  • Parameters

    keyPathIterable<unknown>
    updater(value: unknown) => unknown
  • Returns an iterator over the values.

    Returns

    IterableIterator<V>

    A new iterator.