Options
All
  • Public
  • Public/Protected
  • All
Menu

A map for key-to-string or key-to-array-of-strings. Exposes convenient methods for storing and retrieving values from the map.

Hierarchy

  • StringMap

Index

Constructors

Methods

  • [iterator](): Generator<string | string[], void, unknown>
  • Iterates over the map yielding the values.

    yields

    {(string | string[])}

    Returns Generator<string | string[], void, unknown>

  • addArrayToKey(key: string, array: string[]): void
  • Adds an array to a key.

    If no array is associated with the key, assign the array.

    If the key is already associated with a string value, the value will be an array containing both the previous string value and the elements of the new array.

    If the key is already associated with an array of strings, the value will be an array containing both the elements of the previous and new arrays.

    Use {@link StringMap#set}, {@link StringMap#setString}, or {@link StringMap#setArray} to replace the value.

    throws

    {@link RouterError} if the value isn't an array of string

    Parameters

    • key: string

      the key to associate the new value with.

    • array: string[]

      the array to associate the key with.

    Returns void

  • addStringToKey(key: string, value: string): void
  • Adds a string value to a key.

    If no string is associated with the key, assign the string.

    If the key is already associated with a string, the value will be an array containing both the previous string and the new string.

    If an array of strings is associated with the key, append the string.

    throws

    {@link RouterError} if the value isn't a string

    Parameters

    • key: string

      the key to associate the new value with.

    • value: string

      the value to associate the key with.

    Returns void

  • entries(): Generator<[string, string | string[]], void, unknown>
  • Iterates over the map, yielding a tuple of key and values.

    yields

    {[string, string | string[]]}

    Returns Generator<[string, string | string[]], void, unknown>

  • get(key: string): null | string | string[]
  • Returns the value associated with the key. If the key is not found, returns null.

    Parameters

    • key: string

      the key to look up.

      The value associated with the key.

    Returns null | string | string[]

  • getArray(key: string): null | string[]
  • A function for retrieving an array of strings.

    Parameters

    • key: string

      the key for the value.

    Returns null | string[]

    string if the value exists. null if the key isn't an array or doesn't exist.

  • getNumber(key: string): null | number
  • Convenience function for getting a string and converting to a number if possible. It uses the unary plus operator to convert the value.

    Parameters

    • key: string

      the key for the value.

    Returns null | number

    number if the value can be converted to a number. null if the value can't be converted to a number or if the key doesn't exist.

  • getString(key: string): null | string
  • A function for retrieving a string value.

    Parameters

    • key: string

      the key for the value.

    Returns null | string

    A string if the value exists. null if the key doesn't exist.

  • hasKey(key: string): boolean
  • Checks if the key exists in the map.

    Parameters

    • key: string

      the key to check.

    Returns boolean

    true if the key exists. false otherwise.

  • remove(key: string): void
  • Removes the key, and it's value from the map.

    Parameters

    • key: string

      the key to remove.

    Returns void

  • set(key: string, value: string | string[]): void
  • Sets the value of a key in the map.

    NOTE: This will replace the previous value. Use {@link StringMap#addStringToKey}` or {@link StringMap#addArrayToKey} if you want to combine the previous and new values

    Parameters

    • key: string

      the key to associate the new value with.

    • value: string | string[]

      the value to associate the key with.

    Returns void

  • setArray(key: string, value: string[]): void
  • Sets an array as the value of a key in the map.

    NOTE: This will replace the previous value. Use {@link StringMap#addStringToKey}` or {@link StringMap#addArrayToKey} if you want to combine the previous and new values

    Parameters

    • key: string

      the key to associate the new value with.

    • value: string[]

      the array to associate the key with.

    Returns void

  • setString(key: string, value: string): void
  • Sets the value of a key in the map.

    NOTE: This will replace the previous value. Use {@link StringMap#addStringToKey}` or {@link StringMap#addArrayToKey} if you want to combine the previous and new values

    Parameters

    • key: string

      the key to associate the new value with.

    • value: string

      the string to associate the key with.

    Returns void

Generated using TypeDoc