expiryprops
This module manages an object, allows you to set keys and optional values on that object and, after a timeout expires, removes that property from the object.
Installation
$ npm install expiryprops
Example
var assert = ;var expiryprops = ;expiryprops; // set timer to 100msexpiryprops;assert; // ensure the property is removed after 100ms { if expirypropsobj console; else console;} ;
API
The following are exported from the expireProps module:
- obj
- defaultTimer()
- addKey()
- addKeyValue()
- rmKey()
- resetTimer()
obj
The object containing the keys and optional values.
defaultTimer([timeoutMs])
Returns the current timeout in millisseconds. If a number is supplied, that number is set to the new timeout, which is then returned.
addKey(key [, timeoutMs] [, callback])
The string key is set on the object with a value of undefined. If an optional timeout in miliseconds is supplied, that timeout is used instead of the default. Also, if an optional callback is given, the callback is called after the property is deleted with a single argument, the key.
addKeyValue(key, value [, timeoutMs] [, callback])
The string key is set on the object with a value of undefined. The value is then set to be the value on the object property. If an optional timeout in miliseconds is supplied, that timeout is used instead of the default. Also, if an optional callback is given, the callback is called after the property is deleted with a single argument, the key.
rmKey(key)
Removes the key from the object and clears the timeout.
resetTimer(key [, timeoutMs])
Resets the timeout associated with the key to be timeoutMs, if provided. If no timeout is provided, the timeout is the default.
LICENSE
Released under the MIT License.