Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Dict<K, V>

Dict (or Dictionary) is an extended Map with additional helper methods used for manager caches in the PteroJS library.

Type Parameters

  • K

  • V

Hierarchy

  • Map<K, V>
    • Dict

Index

Constructors

  • new Dict<K, V>(entries?: null | readonly (readonly [K, V])[]): Dict<K, V>
  • new Dict<K, V>(iterable?: null | Iterable<readonly [K, V]>): Dict<K, V>
  • Type Parameters

    • K

    • V

    Parameters

    • Optional entries: null | readonly (readonly [K, V])[]

    Returns Dict<K, V>

  • Type Parameters

    • K

    • V

    Parameters

    • Optional iterable: null | Iterable<readonly [K, V]>

    Returns Dict<K, V>

Properties

[toStringTag]: string
constructor: DictConstructor
size: number
[species]: MapConstructor

Accessors

  • get limit(): number

Methods

  • [iterator](): IterableIterator<[K, V]>
  • Returns an iterable of entries in the map.

    Returns IterableIterator<[K, V]>

  • clear(): void
  • Returns void

  • delete(key: K): boolean
  • Parameters

    • key: K

    Returns boolean

  • difference(dict: Dict<K, V>): Dict<K, V>
  • Parameters

    • dict: Dict<K, V>

      The dict to compare differences to.

    Returns Dict<K, V>

    A dict containing the different entries between both dicts.

  • entries(): IterableIterator<[K, V]>
  • Returns an iterable of key, value pairs for every entry in the map.

    Returns IterableIterator<[K, V]>

  • every(fn: ((value: V, key: K, dict: Dict<K, V>) => boolean)): boolean
  • Checks if all the entries in the dict pass the function.

    Parameters

    • fn: ((value: V, key: K, dict: Dict<K, V>) => boolean)

      The function to apply to the dict.

        • (value: V, key: K, dict: Dict<K, V>): boolean
        • Parameters

          • value: V
          • key: K
          • dict: Dict<K, V>

          Returns boolean

    Returns boolean

  • filter(fn: ((value: V, key: K, dict: Dict<K, V>) => boolean)): Dict<K, V>
  • Applies the function to each entry in the dict and returns a dict of the results that passed.

    Parameters

    • fn: ((value: V, key: K, dict: Dict<K, V>) => boolean)

      The function to apply to the dict.

        • (value: V, key: K, dict: Dict<K, V>): boolean
        • Parameters

          • value: V
          • key: K
          • dict: Dict<K, V>

          Returns boolean

    Returns Dict<K, V>

    The filtered dict.

  • find(fn: ((value: V, key: K, dict: Dict<K, V>) => boolean)): undefined | V
  • Applies a function to each entry in the dict and returns the first one that passes.

    Parameters

    • fn: ((value: V, key: K, dict: Dict<K, V>) => boolean)

      The function to apply to the dict.

        • (value: V, key: K, dict: Dict<K, V>): boolean
        • Parameters

          • value: V
          • key: K
          • dict: Dict<K, V>

          Returns boolean

    Returns undefined | V

  • first<T>(amount?: T): T extends undefined ? V : V[]
  • Returns the first entry (or entries if otherwise specified) in the dict.

    Type Parameters

    • T extends undefined | number

    Parameters

    • Optional amount: T

    Returns T extends undefined ? V : V[]

  • firstKey<T>(amount?: T): T extends undefined ? K : K[]
  • Returns the first key (or keys if otherwise specified) in the dict.

    Type Parameters

    • T extends undefined | number

    Parameters

    • Optional amount: T

    Returns T extends undefined ? K : K[]

  • forEach(callbackfn: ((value: V, key: K, map: Map<K, V>) => void), thisArg?: any): void
  • Parameters

    • callbackfn: ((value: V, key: K, map: Map<K, V>) => void)
        • (value: V, key: K, map: Map<K, V>): void
        • Parameters

          • value: V
          • key: K
          • map: Map<K, V>

          Returns void

    • Optional thisArg: any

    Returns void

  • get(key: K): undefined | V
  • Parameters

    • key: K

    Returns undefined | V

  • has(key: K): boolean
  • Parameters

    • key: K

    Returns boolean

  • hasAll(...keys: K[]): boolean
  • Checks that all of the specified keys exist in the dict.

    Parameters

    • Rest ...keys: K[]

      The keys to check for.

    Returns boolean

  • hasAny(...keys: K[]): boolean
  • Checks that any of the specified keys exist in the dict.

    Parameters

    • Rest ...keys: K[]

      The keys to check for.

    Returns boolean

  • isLimited(): boolean
  • Joins one or more dicts with the current one and returns the value.

    Parameters

    • Rest ...dict: Dict<K, V>[]

      The dicts to join.

    Returns Dict<K, V>

    The joined dicts.

  • keys(): IterableIterator<K>
  • Returns an iterable of keys in the map

    Returns IterableIterator<K>

  • last<T>(amount?: T): T extends undefined ? V : V[]
  • Returns the last entry (or entries if otherwise specified) in the dict.

    Type Parameters

    • T extends undefined | number

    Parameters

    • Optional amount: T

    Returns T extends undefined ? V : V[]

  • lastKey<T>(amount?: T): T extends undefined ? K : K[]
  • Returns the last key (or keys if otherwise specified) in the dict.

    Type Parameters

    • T extends undefined | number

    Parameters

    • Optional amount: T

    Returns T extends undefined ? K : K[]

  • map<T>(fn: ((value: V, key: K, dict: Dict<K, V>) => T)): T[]
  • Applies the function to each entry in the dict and returns an array of the results.

    Type Parameters

    • T

    Parameters

    • fn: ((value: V, key: K, dict: Dict<K, V>) => T)

      The function to apply to the dict.

        • (value: V, key: K, dict: Dict<K, V>): T
        • Parameters

          • value: V
          • key: K
          • dict: Dict<K, V>

          Returns T

    Returns T[]

    The mapped results.

  • part(fn: ((value: V, key: K, dict: Dict<K, V>) => boolean)): Dict<K, V>[]
  • Applies a function to each entry in the dict and returns 2 dicts, the first containing entries that passed the function and the second containing the failed entries.

    Parameters

    • fn: ((value: V, key: K, dict: Dict<K, V>) => boolean)

      The function to apply to the dict.

        • (value: V, key: K, dict: Dict<K, V>): boolean
        • Parameters

          • value: V
          • key: K
          • dict: Dict<K, V>

          Returns boolean

    Returns Dict<K, V>[]

    The passed and failed dicts.

  • random<T>(amount?: T): T extends undefined ? V : V[]
  • Returns a random entry (or entries if otherwise specified) in the dict.

    Type Parameters

    • T extends undefined | number

    Parameters

    • Optional amount: T

    Returns T extends undefined ? V : V[]

  • randomKey<T>(amount?: T): T extends undefined ? K : K[]
  • Returns a random key (or keys if otherwise specified) in the dict.

    Type Parameters

    • T extends undefined | number

    Parameters

    • Optional amount: T

    Returns T extends undefined ? K : K[]

  • reduce<T>(fn: ((value: V, key: K, dict: Dict<K, V>) => T), acc: T): T
  • Reduces each entry in the dict to a single value.

    Type Parameters

    • T

    Parameters

    • fn: ((value: V, key: K, dict: Dict<K, V>) => T)

      The function to apply to the dict.

        • (value: V, key: K, dict: Dict<K, V>): T
        • Parameters

          • value: V
          • key: K
          • dict: Dict<K, V>

          Returns T

    • acc: T

    Returns T

    The reduced value.

  • set(key: K, value: V): Dict<K, V>
  • setLimit(amount: number): void
  • Sets a limit for the number of entries the dict can have. Note: this cannot be changed once set. Attempting to will throw an error.

    Parameters

    • amount: number

      The number of entries allowed for the dict.

    Returns void

  • some(fn: ((value: V, key: K, dict: Dict<K, V>) => boolean)): boolean
  • Checks if at least one of the entries in the dict pass the function.

    Parameters

    • fn: ((value: V, key: K, dict: Dict<K, V>) => boolean)

      The function to apply to the dict.

        • (value: V, key: K, dict: Dict<K, V>): boolean
        • Parameters

          • value: V
          • key: K
          • dict: Dict<K, V>

          Returns boolean

    Returns boolean

  • sweep(fn: ((value: V, key: K, dict: Dict<K, V>) => boolean)): number
  • Applies a function to each entry in the dict and returns the number of items removed.

    Parameters

    • fn: ((value: V, key: K, dict: Dict<K, V>) => boolean)

      The function to apply to the dict.

        • (value: V, key: K, dict: Dict<K, V>): boolean
        • Parameters

          • value: V
          • key: K
          • dict: Dict<K, V>

          Returns boolean

    Returns number

    The number of sweeped entries.

  • update(dict: Dict<K, V>): void
  • Updates the values of the current dict with the specified dict, settings the values in place.

    Parameters

    • dict: Dict<K, V>

      The dict to update with.

    Returns void

  • values(): IterableIterator<V>
  • Returns an iterable of values in the map

    Returns IterableIterator<V>

Generated using TypeDoc