Objectmap

mapobject

Use a ES6 map, like an object.

This module is one of those rare hidden gems in npm, it's already a year old, it makes uses of ES6 reflect API with proxy to make give us a convience method so that maps can be used like an Object.

What other advantages apart from syntax sugar?

  • Iterate it like a regular object with (for in) without worrying about hasOwnProperty checks.

  • Iterate it (for of) you will get arrays of length 2 of both keys and values.

Install it: npm install --save objectmap

Sample usage:

1
2
3
4
5
6
7
8
9
var oMap = require('objectmap');

var map = oMap();

map.answer = 42; // Same as `map.set('answer',42);`

map.answer; // Same as `map.get('abc');`

delete map.abc; // Same as `map.delete('abc');`

Caveat: map[3] implies map.set('3') not map.set(3)

GIF FTW!

Thanks to Calvin for this useful util :)

Suggest a module

Comments