Package detail

es6-map

medikoo5.8mMIT0.1.5

ECMAScript6 Map polyfill

collection, es6, shim, harmony

readme

es6-map

Map collection as specified in ECMAScript6

Warning:
v0.1 version does not ensure O(1) algorithm complexity (but O(n)). This shortcoming will be addressed in v1.0

Usage

It’s safest to use es6-map as a ponyfill – a polyfill which doesn’t touch global objects:

var Map = require('es6-map');

If you want to make sure your environment implements Map globally, do:

require('es6-map/implement');

If you strictly want to use the polyfill even if the native Map exists, do:

var Map = require('es6-map/polyfill');

Installation

$ npm install es6-map

To port it to Browser or any other (non CJS) environment, use your favorite CJS bundler. No favorite yet? Try: Browserify, Webmake or Webpack

API

Best is to refer to specification. Still if you want quick look, follow examples:

var Map = require('es6-map');

var x = {}, y = {}, map = new Map([['raz', 'one'], ['dwa', 'two'], [x, y]]);

map.size;                 // 3
map.get('raz');           // 'one'
map.get(x);               // y
map.has('raz');           // true
map.has(x);               // true
map.has('foo');           // false
map.set('trzy', 'three'); // map
map.size                  // 4
map.get('trzy');          // 'three'
map.has('trzy');          // true
map.has('dwa');           // true
map.delete('dwa');        // true
map.size;                 // 3

map.forEach(function (value, key) {
  // { 'raz', 'one' }, { x, y }, { 'trzy', 'three' } iterated
});

// FF nightly only:
for (value of map) {
 // ['raz', 'one'], [x, y], ['trzy', 'three'] iterated
}

var iterator = map.values();

iterator.next(); // { done: false, value: 'one' }
iterator.next(); // { done: false, value: y }
iterator.next(); // { done: false, value: 'three' }
iterator.next(); // { done: true, value: undefined }

map.clear(); // undefined
map.size; // 0

Tests Build Status

$ npm test

changelog

v0.1.5 -- 2017.03.17

  • Update dependencies
  • Improve documentation

v0.1.4 -- 2016.06.03

  • Update dependencies

v0.1.3 -- 2015.11.18

  • Relax validation of native implementation (do not require proper stringification of Map.prototype)

v0.1.2 -- 2015.10.15

  • Improve native detection
  • Ensure proper inheritance
  • Update up to specification
  • Fix spelling of LICENSE
  • Update dependencies

v0.1.1 -- 2014.10.07

  • Fix isImplemented so native Maps are detected properly
  • Configure lint scripts

v0.1.0 -- 2014.04.29

  • Assure strictly npm hosted dependencies
  • Update to use latest versions of dependencies

v0.0.1 -- 2014.04.25

  • Provide @@toStringTag symbol, and use other ES 6 symbols
  • Fix iterators handling
  • Fix isImplemented so it doesn't crash
  • Update up to changes in dependencies

v0.0.0 -- 2013.11.10

  • Initial (dev) version