set-helpers
v1.3.1
Published
Helpers for Set objects.
Downloads
30
Maintainers
Readme
This implements many array methods that are missing for Set
s, 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