temporary-map
v1.0.1
Published
Temporary Map with auto deletion of items that have not been used for a long time.
Downloads
7
Readme
TemporaryMap ⇐ Map
Kind: global class
Extends: Map
See: JavaScript Map
- TemporaryMap ⇐ Map
- new TemporaryMap(timeout)
- .clear()
- .delete(key) ⇒ Boolean
- .entries() ⇒ Iterator
- .forEach(callback, [thisArg])
- .get(key, [updateTimeout]) ⇒ Mixed
- .set()
- .values() ⇒ Iterator
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.
| Param | Type | Default | | --- | --- | --- | | timeout | integer | 1000 |
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
| Param | Type | | --- | --- | | key | Mixed |
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
| Param | Type | Description | | --- | --- | --- | | callback | function | Function to execute for each element. | | [thisArg] | Mixed | Value 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
| Param | Type | Default | Description | | --- | --- | --- | --- | | key | Mixed | | Required. The key of the element to return from the Map object. | | [updateTimeout] | Boolean | true | |
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