Class CharMap<T>

A map from characters to generic values.

The map guarantees that there are no adjacent character ranges that map to the equal values, will always be iterated as one character range. The equality of values is given by JavaScript's strict equality operator (===).

Type Parameters

  • T

Hierarchy

  • CharMap

Implements

Constructors

Accessors

  • get entryCount(): number
  • The number of entires in this map.

    This is different from size. In general, you should use size, because it has the same semantics as Set#size and Map#size.

    This is equivalent to [...this.entries()].length.

    Returns number

  • get isEmpty(): boolean
  • Returns whether this map is empty.

    This is equivalent to this.size === 0 and this.entryCount === 0.

    Returns boolean

  • get size(): number
  • The number of characters in this map. This is different from entryCount.

    This is equivalent to [...this.keys()].reduce((count, range) => count + range.max - range.min + 1, 0).

    Returns number

Methods

  • Returns IterableIterator<[CharRange, T]>

  • Deletes all entries in the map.

    Returns void

  • Returns a new map with all values mapped by the given function.

    If no function is given, the identity function is used.

    Returns CharMap<T>

  • Type Parameters

    • U

    Parameters

    • mapFn: ((value: T) => U)
        • (value: T): U
        • Parameters

          • value: T

          Returns U

    Returns CharMap<U>

  • Parameters

    Returns boolean

  • Deletes all characters in the given range.

    This is equivalent to [...range].forEach(char => this.delete(char)).

    Parameters

    Returns void

  • Returns all key-value pairs in the map.

    Entries will be returned in the order of ascending ranges.

    Returns IterableIterator<[CharRange, T]>

  • Returns the value associated with the given character of undefined if the character is not key in the map.

    Parameters

    Returns undefined | T

  • Returns whether the given character is a key in the map.

    Parameters

    Returns boolean

  • Returns whether every character in the given range is a key in the map.

    This is equivalent to: [...chars].every(char => this.has(char)).

    Parameters

    Returns boolean

  • Returns whether some character in the given range is a key in the map.

    This is equivalent to: [...chars].some(char => this.has(char)).

    Parameters

    Returns boolean

  • Returns all ranges of characters that are keys in the map.

    Keys will be returned in the same order as this.entries().

    Returns IterableIterator<CharRange>

  • Parameters

    • char: Char
    • value: T

    Returns void

  • Sets the value for all characters in the given character set.

    This is equivalent to [...charSet.characters()].forEach(char => this.set(char, value)).

    Parameters

    Returns void

  • Sets the value for all characters in the given range.

    This is equivalent to [...chars].forEach(char => this.set(char, value)).

    Parameters

    Returns void

  • Returns all values in the map. Values might not be unique if more than one range maps to the same value.

    Values will be returned in the same order as this.entries().

    Returns IterableIterator<T>