https://github.com/jankapunkt/js-set-extension
Extending the Set class in order to support mathematical set properties and operations.
https://github.com/jankapunkt/js-set-extension
complement difference hacktoberfest intersection javascript math powerset proper-subset proper-superset set set-theory subset superset symmetric-difference union
Last synced: about 1 month ago
JSON representation
Extending the Set class in order to support mathematical set properties and operations.
- Host: GitHub
- URL: https://github.com/jankapunkt/js-set-extension
- Owner: jankapunkt
- License: mit
- Created: 2018-09-16T15:30:02.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-07-20T14:16:40.000Z (almost 2 years ago)
- Last Synced: 2025-04-22T22:18:58.112Z (about 1 month ago)
- Topics: complement, difference, hacktoberfest, intersection, javascript, math, powerset, proper-subset, proper-superset, set, set-theory, subset, superset, symmetric-difference, union
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/set-extensions
- Size: 1.15 MB
- Stars: 13
- Watchers: 3
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
![]()
Javascript Set Extensions
Polyfill for extending the Javascript [Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set) class in order to support properties and operations from basic set theory.
[](https://github.com/jankapunkt/js-set-extension/actions/workflows/tests.yml)
[](https://github.com/jankapunkt/js-set-extension/actions/workflows/codeql-analysis.yml)
[](https://www.repostatus.org/#active)
[](https://standardjs.com)

## Scope
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 resultSet'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 may grow exponentially with a raising number of sets to be processes.
Please, see the documentation notes on the respective methods.### Extending `Set`
This package builds upon the `Set` implementation, instead of providing an own.
Some suggest it's bad design to extend core implementations.However, the core functionality of `Set` is stable and proven and this
package tries to be minimally invasive on the `Set` implementation.Please, leave an issue, in case this extension breaks your setup by
whatever unexpected or undefined behaviour.### 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.concepts and contributions are very welcomed.## 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.```javascript
import 'set-extensions'
```You can verify the presence of this polyfill by checking for the `__isExtended__` property:
```javascript
Set.__isExtended__ // true if this package is installed
```## API Documentation
There is a [markdown version](./API.md) and a [html version](https://jankapunkt.github.io/js-set-extension/) of the API documentation.
If you think this documentation can be improved, please leave a pull request or open an issue.## Run the tests
Add the description about testing in the README:
You can run the tests like the following:
```bash
$ cd js-set-extension/package
$ npm install
```To run tests in watch mode use
```bash
$ npm run test-watch
```or for a single run use
```bash
$ 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 intuitive.
### Linter
Please note, that the tests are very strict about code style and you can check for code style related errors using
```bash
npm run lint
```You should fix these lint errors, since the CI server will reject to run any tests when the linter as thrown an error.
You can also run lint and tests all in one process using
```bash
npm run lint-test
```The scripts to run these commands are also in the package.json file:
https://github.com/jankapunkt/js-set-extension/blob/master/package/package.json
## License
MIT