1.3.1 • Published 5 years ago

set-helpers v1.3.1

Weekly downloads
13
License
ISC
Repository
github
Last release
5 years ago

Build Status

This implements many array methods that are missing for Sets, like map, reduce, and every. It also adds some Set-specific functions like intersection. The complete list is in functions/.

Almost everything is done with Set operations. There are no conversions to arrays and back.

Install

npm install --save set-helpers

Use

Functions can be used as-is or added to the Set prototype.

As-is:

const setHelpers = require('set-helpers');
setHelpers.intersection(new Set([1, 2, 3]), new Set([0, 2, 6]));

Prototype:

require('set-helpers')({ extendPrototype: true });
(new Set([1, 2, 3])).intersection(new Set([0, 2, 6]));

A combination of both:

const setHelpers = require('set-helpers')({ extendPrototype: true });
setHelpers.join(new Set([1, 2, 3]));
(new Set([1, 2, 3])).join();

Selectively extending the prototype:

require('set-helpers')({ extendPrototype: ['reduce'] });
Set.prototype.reduce;  // => [Function]
Set.prototype.map;     // => undefined

API