setify-array

1.0.6 • Public • Published

setify-array: make Arrays set-like

ES2025 introduced some really great Set methods. These work with any Set-like object — including Maps out of the box.

Notably, though, Arrays aren't Set-like. Most developers would compose a new Set object from an array they'd like to compare with another Set. Turns out, you don't actually need this overhead, though; we just need to expose the existing Array API in a different way, which is what this library does.

For example:

import setify from "setify-array";

const foo = [1, 2, 3];
const bar = new Set([1, 2, 4]);

console.log(bar.union(setify(foo))); // Set(4) { 1, 2, 4, 3 }

Check out the full list of Set methods here. Keep in mind that this does not expose the set methods on the "setified" array — you'll need to call these methods on the set you're comparing the array to!

Readme

Keywords

none

Package Sidebar

Install

npm i setify-array

Weekly Downloads

0

Version

1.0.6

License

MIT

Unpacked Size

5.18 kB

Total Files

5

Last publish

Collaborators

  • tjwds