Skip to content

oconnore/harmony-enumerables

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Harmony-Enumerables for everywhere

Build Status

What is this?

A small polyfill for ES6 collections that leverages non-enumerable Node.js Map/WeakMap where possible. It's designed to leverage the incomplete --harmony Map/Set/WeakMap implementation where possible, while adding iterators. In vanilla node, or Chrome, Map, Set, and WeakMap are polyfilled.

Unsuprisingly, the polyfill does some weird stuff. Specifically, it creates random, non-enumerable properties on your objects. If you don't like that, that's fine, just use one of the other, less imposing ES6 polyfills for Map, Set, and WeakMap.

For example:

var eSet = require('harmony-enumerables').Set;

var s = new eSet();
s.add({value: 2});
s.add({value: 3});
s.add({value: 4});

var x = 0;
s.forEach(function(y) {
  x += y.value;
})

assert.equal(x, 9); // true

In addition to forEach, it also adds an iterator interface:

var eMap = require('harmony-enumerables').Map;
var m = new eMap();
m.set(18, 2);
m.set(34, 3);
m.set(76, 4);

var x = 0;
var iter = m.entries();
while (!iter.done) {
  var keyValue = iter.next();
  var key = keyValue[0];
  var value = keyValue[1];
  x += value;
}

assert.equal(x, 9); // true

if you call .polyfill(), it will overwrite the global definitions.

require('harmony-enumerables').polyfill();

About

Enumerable collections for everywhere.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published