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

full-set

v1.0.2

Published

A batteries include Set class built on top of ES6 sets

Downloads

8

Readme

FullSet

Full-Set is a wrapper class around the native ES6 set object which adds the classical set operations.

For pedagogical purposes mostly, probably not production ready.

Install

npm i --save full-set

Requirements

This library relies on ES6 Sets, and so either a recent version of Node or the browsers will be required

Documentation

Methods

constructor

Creates and adds elements to a set.

Arguments

  • ...elements - Variadic, any number of elements as arguments

Example

    let A = new FullSet('1','2','3');

add

Adds elements to the set

Arguments

  • ...elements - Variadic, any number of elements as arguments
    let A = new FullSet('A','B');
    A.add('C','D','E');

clone

Creates a copy of a set

Example

    let A = new FullSet('TOAST','EGGS','BACON');
    let B = A.clone();

contains

Given an element will reply with a boolean if the set containts that element

Arguments

  • element - An element to query the set for

Example

    let A = new FullSet('A','B','C','D','E');
    A.contains('D') //true

equal

This will compare another set for equality, when both sets contain the same elements

Arguments

  • other_set - Another FullSet object to compare

Example

    let A = new FullSet('1','2');
    let B = new FullSet('1','2');
    let E = new FullSet('1','2','1','2');
    A.equal(B) //equal sets should equal
    A.equal(E) //duplicates don't matter

remove

Remove elements from a set

Arguments

  • ...elements - Variadic, any number of elements to remove from the set as arguments

Example

    let A = new FullSet('A','B','C','D','E');
    A.contains('D') //true
    A.contains('E') //true
    A.remove('D','E')
    A.contains('D') //false
    A.contains('E') //false

values

Returns an iterator of the elements in the set

Example

    let A = new FullSet('A','B','C','D','E');
    let iterator = A.values();
    iterator.next().value //A;

union

Create a new set which has all the elements of both sets.

Arguments

  • other_set - Another FullSet object

Example

    let A = new FullSet("A","B");
    let B = new FullSet("D","E");  
    let C = A.union(B); //A,B,D,E

intersect

Create a new set which only has elements this set and the other set contain.

Arguments

  • other_set - Another FullSet object

Example

     let A = new FullSet(1,2,3,4);
     let B = new FullSet(3,4,5,6);
     let inty = A.intersect(B); //3,4

complement

Given a universe set, it will return all of the elements not in this set.

Arguments

  • other_set - Another FullSet object

Example

    let universe = new FullSet(1,2,3,4,5);
    let A = new FullSet(1);
    let compA = A.complement(universe); //2,3,4,5

relativeComplement

Given another set, it will return a set of elements that are only in this set relative to the other set.

Arguments

  • other_set - Another FullSet object

Example

     let A = new FullSet(1,2,3,4);
     let B = new FullSet(3,4,5,6);
     let AminusB = A.relativeComplement(B); //1,2

symmetricDifference

Given another set, it will return a set of elements that are in this set and in the other set, but not the elements that are in both.

Arguments

  • other_set - Another FullSet object

Example

     let A = new FullSet(1,2,3,4);
     let B = new FullSet(3,4,5,6);
     let AtriangleB = A.symmetricDifference(B); // 1,2,5,6

crossProduct

Given another set, it will return a new set of ordered pairs (Arrays) of every combination of this set elements and the other sets elements.

Arguments

  • other_set - Another FullSet object

Example

     let A = new FullSet(1,2);
     let B = new FullSet(3,4);
     let AcrossB = A.crossProduct(B); //[1,3],[2,3],[1,4],[2,4]

powerSetIter

Iterator for all subsets of the set

Example

     let A = new FullSet(1,2,3);
     let powerIterator = A.powerSet();
     powerSet.next().value();

powerSet

Set of all subsets

warning the size of this set is exponential, 2 ^ this.size();

Example

     let A = new FullSet(1,2,3);
     let Apower = A.powerSet();

cardinality

Returns the number of elements in the set.

Example

     let A = new FullSet(1,2,3);
     A.cardinality() //3

size

Returns the number of elements in the set.

Example

     let A = new FullSet(1,2,3);
     A.size() //3