setify-array
v1.0.6
Published
A quick wrapper to turn Arrays into set-like objects for use with ES2025 Set methods.
Downloads
100
Readme
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!