Skip to content

Tyler-Murphy/set-helpers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Helpers for native javascript Sets

Resources

Stars

Watchers

Forks

Packages

No packages published