set-tojson

2.1.1 • Public • Published

set-tojson Version Badge

Build Status dependency status dev dependency status License Downloads

npm badge

Rejected ESNext Proposal: Set#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 Set exists natively, or where it is polyfilled with the (es6-shim)es6-shim-url

Example

var setToJSON = require('set-tojson');
var assert = require('assert');
var items = ['a', 'b', 'c'];
var entries = [[1, 2], [3, 4]];

assert.deepEqual(setToJSON(new Set()), []);
assert.deepEqual(setToJSON(new Set(items)), items);
assert.deepEqual(setToJSON(new Map()), []);
assert.deepEqual(setToJSON(new Map(entries)), entries);
assert.deepEqual(setToJSON(''), []);
assert.deepEqual(setToJSON('abc'), ['a', 'b', 'c']);
assert.deepEqual(setToJSON([]), []);
assert.deepEqual(setToJSON(items), items);
assert.deepEqual(setToJSON(entries), entries);

setToJSON.shim();
assert.deepEqual(new Set(items).toJSON(), items);
assert.deepEqual(new Set().toJSON(), []);

Tests

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

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 2.1.1
    691
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 2.1.1
    691
  • 2.1.0
    88
  • 2.0.1
    40
  • 2.0.0
    2
  • 1.0.0
    2

Package Sidebar

Install

npm i set-tojson

Weekly Downloads

622

Version

2.1.1

License

MIT

Unpacked Size

21.3 kB

Total Files

18

Last publish

Collaborators

  • ljharb