This is a module extendeds native Map providing some extra features:
- return default value if the requested key does not exist
- protect against overrite of existing keys
npm install @itavy/extended-map
const ExtendedMap = require('@itavy/extended-map').ExtendedMap;
const eMap = new ExtendedMap({
defaultValue: 'myDefaultValue'
});
console.log('return value:', eMap.get('unknownkey'));
this will produce:
return value: myDefaultValue
- itavy/extended-map :
object
- ExtendedMapOptions :
Object
Kind: global namespace
- itavy/extended-map :
object
- .ExtendedMap
- .PromisedExtendedMap
- new PromisedExtendedMap([options])
- .defaultValue :
*
- .allowOverrite :
Boolean
- .doNotRejectHas :
Boolean
- .doNotRejectDelete :
Boolean
- .get() ⇒
Promise.<*>
- .set() ⇒
Promise.<PromisedExtendedMap>
- .has() ⇒
Promise.<Boolean>
- .clear() ⇒
Promise.<undefined>
- .delete() ⇒
Promise.<Boolean>
- .values() ⇒
Promise.<Iterator>
- .valuesAsArray() ⇒
Promise.<Array>
- .keys() ⇒
Promise.<Iterator>
- .keysAsArray() ⇒
Promise.<Array>
- .entries() ⇒
Promise.<Iterator>
- .entriesAsArray() ⇒
Promise.<Array>
- .forEach() ⇒
Promise.<undefined>
ExtendedMap native map wth a few enhancements
Kind: static class of itavy/extended-map
Param | Type | Default | Description |
---|---|---|---|
[options] | itavy/extended-map.ExtendedMapOptions |
{} |
Map options |
Wrapper for get if no value is found then default value will be returned
Kind: instance method of ExtendedMap
Access: public
See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get
Wrapper for set if override is not allowed it will throw an error
Kind: instance method of ExtendedMap
Access: public
See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get
ExtendedMap native map wth a few enhancements
Kind: static class of itavy/extended-map
- .PromisedExtendedMap
- new PromisedExtendedMap([options])
- .defaultValue :
*
- .allowOverrite :
Boolean
- .doNotRejectHas :
Boolean
- .doNotRejectDelete :
Boolean
- .get() ⇒
Promise.<*>
- .set() ⇒
Promise.<PromisedExtendedMap>
- .has() ⇒
Promise.<Boolean>
- .clear() ⇒
Promise.<undefined>
- .delete() ⇒
Promise.<Boolean>
- .values() ⇒
Promise.<Iterator>
- .valuesAsArray() ⇒
Promise.<Array>
- .keys() ⇒
Promise.<Iterator>
- .keysAsArray() ⇒
Promise.<Array>
- .entries() ⇒
Promise.<Iterator>
- .entriesAsArray() ⇒
Promise.<Array>
- .forEach() ⇒
Promise.<undefined>
Param | Type | Default | Description |
---|---|---|---|
[options] | itavy/extended-map.ExtendedMapOptions |
{} |
Map options |
Default value for non existing keys
Kind: instance property of PromisedExtendedMap
Default: undefined
Read only: true
Allow updating the keys
Kind: instance property of PromisedExtendedMap
Default: true
Read only: true
Weather to reject or not if the key does not exist
Kind: instance property of PromisedExtendedMap
Default: false
Read only: true
Weather to reject or not if key to be deleted does not exist
Kind: instance property of PromisedExtendedMap
Default: false
Read only: true
Promisified wrapper for get
Kind: instance method of PromisedExtendedMap
Returns: Promise.<*>
- resolves with requested value or default value if none found
Access: public
Promisified wrapper for set it will resolve
Kind: instance method of PromisedExtendedMap
Returns: Promise.<PromisedExtendedMap>
- resolves with the new map if overriting
is allowed or the key does not exists, otherwise it will reject with an error
Access: public
Promisified wrapper for has
Kind: instance method of PromisedExtendedMap
Returns: Promise.<Boolean>
- resolves with true if key exists or with false
if doNotRejectHas is set otherwise it will reject with an error
Access: public
Promisified wrapper for clear
Kind: instance method of PromisedExtendedMap
Returns: Promise.<undefined>
- resolves on success
Access: public
Promisified wrapper for delete
Kind: instance method of PromisedExtendedMap
Returns: Promise.<Boolean>
- resolves with true if key has been removed or with false
if doNotRejectDelete is set otherwise it will reject with an error
Access: public
Promisified wrapper for values
Kind: instance method of PromisedExtendedMap
Returns: Promise.<Iterator>
- resolves on success
Access: public
Iterate over all values and put them into an array
Kind: instance method of PromisedExtendedMap
Returns: Promise.<Array>
- resolves with an array with all values
Promisified wrapper for keys
Kind: instance method of PromisedExtendedMap
Returns: Promise.<Iterator>
- resolves on success
Access: public
Iterate over all keys and put them into an array
Kind: instance method of PromisedExtendedMap
Returns: Promise.<Array>
- resolves with an array with all keys
Promisified wrapper for entries
Kind: instance method of PromisedExtendedMap
Returns: Promise.<Iterator>
- resolves on success
Access: public
Iterate over all elements and put them into an array
Kind: instance method of PromisedExtendedMap
Returns: Promise.<Array>
- resolves with an array with all elements
Promisified wrapper for forEach
Kind: instance method of PromisedExtendedMap
Returns: Promise.<undefined>
- resolves on success
Access: public
Kind: global typedef
Properties
Name | Type | Default | Description |
---|---|---|---|
defaultValue | * |
default value to return when none is found | |
allowOverrite | Boolean |
true |
if it is allowed to overrite an existing key |
see Example
- refactor jsdoc
- add examples
- promisify some methods