Skip to content
Rejected ESNext Proposal: Map#toJSON
JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github/workflows
test
.eslintrc
.gitignore
.npmrc
.travis.yml
CHANGELOG.md
LICENSE
README.md
auto.js
implementation.js
index.js
package.json
polyfill.js
requireMap.js
shim.js

README.md

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

You can’t perform that action at this time.