Get unlimited public & private packages + package-based permissions with npm Pro.Get started »

map-tojson

2.1.0 • Public • Published

map-tojson Version Badge

Build Status dependency status dev dependency status License Downloads

npm badge

Rejected ESNext Proposal: Map#toJSON https://github.com/DavidBruant/Map-Set.prototype.toJSON

This polyfill is spec-compliant (based on the spec so far). It will work in every engine in which Map exists natively, or where it is polyfilled with the (es6-shim)es6-shim-url

Example

var mapToJSON = require('map-tojson');
var assert = require('assert');
var items = ['a', 'b', 'c'];
var entries = [[1, 2], [3, 4]];
 
assert.deepEqual(mapToJSON(new Set()), []);
assert.deepEqual(mapToJSON(new Set(items)), items);
assert.deepEqual(mapToJSON(new Map()), []);
assert.deepEqual(mapToJSON(new Map(entries)), entries);
assert.deepEqual(mapToJSON(''), []);
assert.deepEqual(mapToJSON('abc'), ['a', 'b', 'c']);
assert.deepEqual(mapToJSON([]), []);
assert.deepEqual(mapToJSON(items), items);
assert.deepEqual(mapToJSON(entries), entries);
 
mapToJSON.shim();
assert.deepEqual(new Map(entries).toJSON(), entries);
assert.deepEqual(new Map().toJSON(), []);
 

Tests

Simply clone the repo, npm install, and run npm test

Install

npm i map-tojson

DownloadsWeekly Downloads

585

Version

2.1.0

License

MIT

Unpacked Size

19 kB

Total Files

18

Last publish

Collaborators

  • avatar
  • avatar