set-tojson
Version:
ES7 Proposal: Set#toJSON https://github.com/DavidBruant/Map-Set.prototype.toJSON
57 lines (45 loc) • 2.02 kB
Markdown
[![Build Status][3]][4]
[![dependency status][5]][6]
[![dev dependency status][7]][8]
[![License][license-image]][license-url]
[![Downloads][downloads-image]][downloads-url]
[![npm badge][11]][1]
Rejected ESNext Proposal: Set
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
```js
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(), []);
```
Simply clone the repo, `npm install`, and run `npm test`
[]: https://npmjs.org/package/set-tojson
[]: http://versionbadg.es/es-shims/set-tojson.svg
[]: https://travis-ci.org/es-shims/set-tojson.svg
[]: https://travis-ci.org/es-shims/set-tojson
[]: https://david-dm.org/es-shims/set-tojson.svg
[]: https://david-dm.org/es-shims/set-tojson
[]: https://david-dm.org/es-shims/set-tojson/dev-status.svg
[]: https://david-dm.org/es-shims/set-tojson#info=devDependencies
[]: https://nodei.co/npm/set-tojson.png?downloads=true&stars=true
[]: http://img.shields.io/npm/l/set-tojson.svg
[]: LICENSE
[]: http://img.shields.io/npm/dm/set-tojson.svg
[]: http://npm-stat.com/charts.html?package=set-tojson
[]: https://github.com/es-shims/es6-shim