# arraysetjs

> A dependency-free library for treating arrays like sets and performing [set operations]() with an intuitive interface.

Latest version **1.0.14** (published 2024-06-29) · (MIT OR GPL-3.0) license · 0 weekly downloads

## Install

```sh
npm install arraysetjs
pnpm add arraysetjs
yarn add arraysetjs
bun add arraysetjs
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.14 |
| Published | 2024-06-29 |
| First published | 2018-05-26 |
| Weekly downloads | 0 |
| License | (MIT OR GPL-3.0) |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 23.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Ethan Brown |

## Links

- npm: https://www.npmjs.com/package/arraysetjs
- Repository: https://github.com/EthanRBrown/arrayset.js
- Homepage: https://github.com/EthanRBrown/arrayset.js#readme
- Issues: https://github.com/EthanRBrown/arrayset.js/issues
- npm.io page: https://npm.io/package/arraysetjs

## Recent versions

- 1.0.14 (latest) — 2024-06-29
- 1.0.13 — 2024-04-03
- 1.0.12 — 2021-10-17
- 1.0.11 — 2021-10-17
- 1.0.10 — 2020-02-06
- 1.0.9 — 2020-02-05
- 1.0.8 — 2018-07-24
- 1.0.6 — 2018-07-19
- 1.0.4 — 2018-07-16
- 1.0.3 — 2018-07-16
- 1.0.2 — 2018-06-19
- 1.0.1 — 2018-05-26
- 1.0.0 — 2018-05-26

## README

# arrayset

A dependency-free library for treating arrays like sets and performing [set operations](<https://en.wikipedia.org/wiki/Set_(mathematics)#Basic_operations>) with an intuitive interface.

This library also includes a mutable version (ideal for use with [Automerge](https://github.com/automerge/automerge) or [Immer](https://github.com/immerjs/immer)).

## Notes

- arrayset is now an ESM-only library; if you need CommonJS, use version 1.0.11 (versions 1.0.12 and 1.0.13 are broken). No, you won't have TypeScript types, but...you should really be using ESM!
- arrayset will not itself introduce duplicates with any of its operations; however, it will not police the arrays you provide to remove duplicates.
- arrayset does not guarantee the order of elements after set operations.
- arrayset does not check arguments; make sure you're using it correctly!
- arrayset supports providing comparison functions for use with objects, but this has not been tested or documented.

## Normal (immutable) usage

```javascript
import set from 'arraysetjs'

// existence:

set([1, 2, 3]).contains(2) // true
set([1, 2, 3]).contains(4) // false

// add/remove elements:

set([1, 2, 3]).add(4) // [1, 2, 3, 4]
set([1, 2, 3]).remove(2) // [1, 3]

// union:

set([1, 2, 3]).union([4, 5, 6]) // [1, 2, 3, 4, 5, 6]
set([1, 2, 3]).union([3, 4, 5]) // [1, 2, 3, 4, 5]

// intersection:

set([1, 2, 3]).intersection([4, 5, 6]) // []
set([1, 2, 3]).intersection([3, 4, 5]) // [3]

// difference:

set([1, 2, 3]).minus([1, 3]) // [2]

// create an arrayset instance:

set.fromArray([1, 2, 3, 2, 3]) // [1, 2, 3]
```

## Mutable usage

The interface for mutable usage is exactly the same except the source array is modified. For example:

```javascript
import set from 'arraysetjs'

const a = [1, 2, 3]
set.mutable(a).union([3, 4]) // a is now [1, 2, 3, 4]
// (which is also returned)
```

## Contributing

This is a small library without a lot of activity, so generally I'll accept any reasonable enhancements. If there are big changes you would like to see, please raise an issue first to discuss.

1. Fork repository
2. Make code changes & write tests (in \_src\_\_tests\_\_\_)
3. Make sure all tests pass (`pnpm test`)
4. Make sure build is successful (`pnpm build`)
5. Update _README.md_ with documentation (if necessary)

Do not update _CHANGELOG.md_; the maintainer will do that with version releases.

---
_Source: https://npm.io/package/arraysetjs · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
