Miss any of our Open RFC calls?Watch the recordings here! »


1.4.0 • Public • Published

Javascript Set Extensions

Polyfill for extending the Javascript Set class in order to support properties and operations from basic set theory.

Project Status: Active – The project has reached a stable, usable state and is being actively developed. Build Status JavaScript Style Guide GitHub npm bundle size


Please read this first, to a get a better understanding, whether this package suits your needs.

Completeness vs. Performance

Focus of this package is to provide a Set implementation, which can be used in context of axiomatic set theory.

Set's class Methods are primarily designed to

  • run with any values, but also values as Sets (of Sets, arbitrary depth)
  • work with arbitrary (but finite) numbers of sets (depending on operation, see documentation)
  • conform with their respective properties (Associative, Commutative etc.)
  • don't mutate any of the given but return a new Set as result

Set's prototype Methods are in contrast designed to work as a binary operation on the current instance but they also won't mutate any of the involved Sets.

Some algorithms have runtimes that grow exponentially as you increase the number of sets they act on.
Please, see the documentation notes on the respective methods.

Future Implementations

Currently this package only supports finite sets. A future implementation could include generators to support infinite sets and function-based operations with infinite sets. Ideas and contributions are very welcome.

Installation and Usage

Install this package as usual:

$ npm install --save set-extensions

Import this package in your startup code. The package automatically extends the global Set object.

import 'set-extensions'

You can verify the presence of this polyfill by checking for the __isExtended__ property:

Set.__isExtended__ // true if this package is installed

API Documentation

There is a markdown version and a html version of the API documentation. If you think this documentation can be improved, please leave a pull request or open an issue.

Run the tests

You can run the tests like the following:

cd js-set-extension/package
$ npm install

To run tests in watch mode use

$ npm run test-watch

or for a single run use

$ npm run test

The tests are written in mocha but it should not be that hard to get into it as it is written very intuitively.


Please note, that the tests are very strict about code style and you can check for code style related errors using

npm run lint

You should fix these lint errors, since the CI server will refuse to run any tests when the linter has thrown an error.

The scripts to run these commands are also in the package.json file:





npm i set-extensions

DownloadsWeekly Downloads






Unpacked Size

163 kB

Total Files


Last publish


  • avatar