1.0.1 • Published 5 years ago

temporary-map v1.0.1

Weekly downloads
2
License
ISC
Repository
github
Last release
5 years ago

TemporaryMap ⇐ Map

Kind: global class
Extends: Map
See: JavaScript Map

new TemporaryMap(timeout)

Just like the Map, the TemporaryMap object holds key-value pairs and remembers the original insertion order of the keys. Any value (both objects and primitive values) may be used as either a key or a value. TemporaryMap has the same interface as the Map.

ParamTypeDefault
timeoutinteger1000

temporaryMap.clear()

Removes all key/value pairs and clears timeouts from the TemporaryMap object.

Kind: instance method of TemporaryMap
Example

temporaryMap.clear()

temporaryMap.delete(key) ⇒ Boolean

Returns true if an element in the Map object existed and has been removed, or false if the element does not exist. TemporaryMap.prototype.has(key) will return false afterwards.

Kind: instance method of TemporaryMap

ParamType
keyMixed

Example

temporaryMap.delete('key')

temporaryMap.entries() ⇒ Iterator

The entries() method returns a new Iterator object that contains the key, value pairs for each element in the TemporaryMap object in insertion order.

Kind: instance method of TemporaryMap
Example

const iterator = temporaryMap.entries()

for(let [key, value] of iterator) {
  console.log(key, value)
}

temporaryMap.forEach(callback, thisArg)

Calls callbackFn once for each key-value pair present in the TemporaryMap object, in insertion order. If a thisArg parameter is provided to forEach, it will be used as the this value for each callback.

Kind: instance method of TemporaryMap

ParamTypeDescription
callbackfunctionFunction to execute for each element.
thisArgMixedValue to use as this when executing callback.

Example

emporaryMap.forEach(console.log, console)

temporaryMap.get(key, updateTimeout) ⇒ Mixed

The get() method returns a specified element from a TemporaryMap object.

Kind: instance method of TemporaryMap

ParamTypeDefaultDescription
keyMixedRequired. The key of the element to return from the Map object.
updateTimeoutBooleantrue

temporaryMap.set()

Sets the value for the key in the TemporaryMap object. Returns the TemporaryMap object.

Kind: instance method of TemporaryMap

temporaryMap.values() ⇒ Iterator

Returns a new Iterator object that contains the values for each element in the TemporaryMap object in insertion order.

Kind: instance method of TemporaryMap