Options
All
  • Public
  • Public/Protected
  • All
Menu

Class default<Key, Value>

name

Es6TimedMap An es6-map-like utility class with time based functions and support.

Due to the similar surface area, use the Map doc reference from here

Type Parameters

  • Key

  • Value

Hierarchy

  • default

Index

Constructors

  • new default<Key, Value>(_entries?: null | ([Key, Value, number, ExpirationCallback<Key, Value>] | [Key, Value, number])[]): default<Key, Value>
  • Type Parameters

    • Key

    • Value

    Parameters

    • Optional _entries: null | ([Key, Value, number, ExpirationCallback<Key, Value>] | [Key, Value, number])[]

      list of entires to pre-populate the timed-map with

    Returns default<Key, Value>

Properties

_core: Map<Key, Value> = ...

The core map data, used to keep track of the data itself.

_timers: Map<Key, Timeout<Key, Value>> = ...

A map of timers where the key is the same key provided to the _core map.

onExpire: null | ((key: Key, value: Value) => void) = null

Event handler triggered whenever an item from the map is expired

Accessors

  • get size(): number
  • Returns the number of key/value pairs in the TimedMap object

    Returns number

Methods

  • [iterator](): IterableIterator<[Key, Value]>
  • Returns IterableIterator<[Key, Value]>

  • clear(params?: { triggerExpirationCallback?: boolean; triggerOnExpire?: boolean }): void
  • Removes all key-value pairs from the TimedMap object.

    params

    params param object, is optional

    params

    params.triggerExpirationCallback if we are to trigger the expiration callback for all timers.

    params

    params.triggerOnExpire if we are to trigger the general onExpire callback

    Parameters

    • Optional params: { triggerExpirationCallback?: boolean; triggerOnExpire?: boolean }
      • Optional triggerExpirationCallback?: boolean
      • Optional triggerOnExpire?: boolean

    Returns void

  • delete(key: Key): boolean
  • Returns true if the element in the Map object existed and has been removed, or false if the element does not exist. has will return false afterwards.

    Parameters

    • key: Key

      the key to remove

    Returns boolean

  • entries(): IterableIterator<[Key, Value]>
  • Returns a new Iterator object that containers an array of [key, value] for each element in the Map object in insertion order.

    Returns IterableIterator<[Key, Value]>

  • forEach(callback: ((value: Value, key: Key, timedMap: default<Key, Value>) => void), thisArg?: default<Key, Value>): void
  • Calls ``callbackFnonce each key-value pair present in theMapobject, in insertion order. If athisArgparameter is provided toforEach, it will be used as this` value for each callback

    Parameters

    • callback: ((value: Value, key: Key, timedMap: default<Key, Value>) => void)

      TODO: check typing for thisArg object

        • (value: Value, key: Key, timedMap: default<Key, Value>): void
        • Parameters

          • value: Value
          • key: Key
          • timedMap: default<Key, Value>

          Returns void

    • Optional thisArg: default<Key, Value>

    Returns void

  • get(key: Key): undefined | Value
  • Returns the value at the given key, if there is one

    Parameters

    • key: Key

      the key to get

    Returns undefined | Value

  • getTimeLeft(key: Key): undefined | number
  • Gets the remaining time for an entry given a key. This is just an estimation - the environment ultimately determines when the removal is executed.

    Parameters

    • key: Key

      the key of an entry in the map

    Returns undefined | number

    The amount of milliseconds left before the entry is ejected, or undefined if the key or timer does not exist

  • has(key: Key): boolean
  • Returns a boolean asserting whether a value has been associated to the key in the Map object or not.

    Parameters

    • key: Key

    Returns boolean

  • keys(): IterableIterator<Key>
  • Returns a new Iterator object that contains the keys for each element in the Map object in insertion order

    Returns IterableIterator<Key>

  • timers(order?: number | "insertion" | "expiration"): IterableIterator<[Key, Timeout<Key, Value>]>
  • Gets a list of remaining timers.

    Parameters

    • Optional order: number | "insertion" | "expiration"

      sort key to determine order of timers. Defaults to insertion order.

    Returns IterableIterator<[Key, Timeout<Key, Value>]>

    A list of remaining timers sorted using order

  • touch(key: Key, newtime?: number): boolean
  • Resets a timer or updates its expiration time

    Parameters

    • key: Key
    • Optional newtime: number

      time to set the timer to

    Returns boolean

  • values(): IterableIterator<Value>
  • Returns a new Iterator object that contains values for each element in the Map object in insertion order.

    Returns IterableIterator<Value>

Generated using TypeDoc