map-or-similar
A JavaScript (JS) Map or Similar object polyfill if Map is not available.
Last updated 9 years ago by thinkloop .
MIT · Repository · Bugs · Original npm
$ cnpm install map-or-similar 
SYNC missed versions from official npm registry.

Map Or Similar

Returns a JavaScript Map() or a similar object with the same interface, if Map is not available. Focuses on performance. No dependencies. Made for the browser and nodejs.

Install

npm install map-or-similar --save

Use

var MapOrSimilar = require('map-or-similar');

// make a new map or similar object
var myMap = new MapOrSimilar();

// use it like a map
myMap.set('key1', 'value1');
myMap.set({ val: 'complex object as key' }, 'value2');

The following methods and properties are supported identically to Map():

set(key, val)     : Sets a value to a key. Key can be a complex object, array, etc.
get(key)          : Returns the value of a key.
has(key)          : Returns true if the key exists, otherwise false.
delete(key)       : Deletes a key and its value.
forEach(callback) : Invokes callback(val, key, object) once for each key-value pair in insertion order.
size              : Returns the number of keys-value pairs.

Does not support other Map methods or properties.

Test

npm run test

License

Released under an MIT license.

Other Libs

  • Memoizerific: Fastest, smallest, most-efficient JavaScript memoization lib to memoize JS functions.
  • Multi Key Cache: A JavaScript (JS) cache that can have multiple complex values as keys.

Current Tags

  • 1.5.0                                ...           latest (9 years ago)

1 Versions

  • 1.5.0                                ...           9 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (4)
Dependents (0)
None

Copyright 2013 - present © cnpmjs.org