npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

arraysetjs

v1.0.14

Published

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.

Downloads

19

Readme

arrayset

A dependency-free library for treating arrays like sets and performing set operations with an intuitive interface.

This library also includes a mutable version (ideal for use with Automerge or 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

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:

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.