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

js-sets

v1.0.3

Published

A JavaScript implementation of Set

Downloads

3

Readme

js-sets [by BUILDBROTHERS.COM]

A JavaScript implementation of Set.

Features

  • Return the Union of two sets
  • Return the Intersection of two sets
  • Check for the Equality of two sets
  • check if two sets are Equivalent
  • Return the Compliment of two sets
  • Check if two sets are disjoint
  • Check if a set is empty
  • Return the size of a set
  • Clear a set (make it empty)
  • add an element to a set

Here is how to get started.

Installation

Install using NPM

npm i js-sets

Install using yarn

yarn add js-sets

Example 1

const Set = require('js-sets')
const vowels = new Set(['a', 'e', 'i', 'i', 'o', 'u'])
console.log(vowels.value)
// will return ['a', 'e', 'i', 'o', 'u']
const consonants = new Set(['b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z'])

To use all the Set's method (e.g to unite two sets, to find set intersection or to check for equality of a set), you simply call the method from the set instance and pass the other set as a paramater on the method.

Example 2

let alphabets = vowels.union(consonants)
console.log(alphabets.result())
// will return ['a','e','i','o', 'u', 'b', 'c', 'd', 'f', 'g', ...]

In the above example we are joining vowels and consonants using the union() method, the method is available in all the set instances. To get the final value, you can use the result() method.

Instead of passing an initial value as a parameter when creating a new Set, like in the first example, you can create a new set passing no parameter and then later use the set() method to set the values of the set, you can also use this method to change the the entire elements of a set.

Example 3

const alphabets = new Set()
alphabets.set(consonants.union(vowels).result())
console.log(alphabets.value)
// will return ['a','e','i','o', 'u', 'b', 'c', 'd', 'f', 'g', ...]

You can also use the chain commands, calling a method after a method to get the resuts you want.

Example 4

alphabets.intersect(vowels).equal(new Set(['a', 'e', 'i', 'o', 'u']))
// wil return true

Using the equal() method will return either a Boolean value, so there so there is no need to call the result() method after it, hence calling it will return the value of the set.

List of Supported Set Methods

| method | use | | ------------------- | ------------------------------------------------------------------------------- | | size() | Get the size of the set | | empty() | Check if a set is empty | | clear() | Clear all the elements in a set | | set(param) | Set the value of a set | | add(param) | add a new element to a set | | remove(param) | remove an element from a set | | equal(param) | check if a set is equal to a given set | | equaivalent(param) | check if a set has the same number of elements with a given set | | compliment(param) | return the elements that are in the current set which are not in the given set | | intersection(param) | return similar elements that are in two sets | | disjoint(param) | check if two sets have no elements in common | | power() | return the power of a set | | result() | Get the final result (value) after a certain method is use to compare two sets. |

Note:

All methods that accept parameters except for the equivalent() method, the result() method has to be called at the end as chain method in order to get the result of the operation.

Contributors


License

This program is licensed under the GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007. Please read the LICENSE.txt text document included with the source code if you would like to read the terms of the license.