set-helpers
TypeScript icon, indicating that this package has built-in type declarations

1.3.1 • Public • Published

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

Package Sidebar

Install

npm i set-helpers

Weekly Downloads

3

Version

1.3.1

License

ISC

Unpacked Size

23.3 kB

Total Files

24

Last publish

Collaborators

  • tyler-murphy