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

cute-set

v2.0.1

Published

A minimalistic es6 implementation of set

Downloads

10

Readme

CuteSet

Build badge codecov

This is minimalistic es6 implementation of set and its basic operations, based on native javascript Set.

Version 1.0.11 changes

  • Added filter map reduce functionality, works the same way as array.
  • length and size are no longer functions, so instead of doing mySet.length() do mySet.length

Installation

npm i --save cute-set

API

Require CuteSet library in your project:

//Node.js
const CuteSet = require("cute-set");

CuteSet is iterable

So this code will be perfectly valid:

  let mySet = new CuteSet([1, 2, 3, 4, 5]);
  for (let val of mySet){
    process(val);
  }

or

  let mySet = new CuteSet([1, 2, 3, 4, 5]);
  mySet.forEach((val, i, arr)=>{
    process(val);
  })

In the last example above val is the same as i, just like in native JS set, arr points to this CuteSet instance. Note, there is no acces by index, so mySet[0] will be undefined.


To create new instance of CuteSet you can use constructor or static method CuteSet.FromString()

constructor(input)

  let mySet = new CuteSet(input)

V.2 Changes Input can be anything: Single object, number or string new CuteSet instance with that object returned Array new CuteSet instance with all elements of the array returned (duplicates obviously removed) CuteSet instance copy of CuteSet instance with be returned.

static fromString(input, delimiter = " ", parseNumbers = false)

Parses passed string and creates CuteSet instance. Delimiter is optional and by default it is one empty space. parseNumbers - for each element in string parseFloat will be applied. See tests for examples


complement(x) +

Given "universe" x returns self complement x or basically x difference self

subsetGenerator()

Returns a subset generator. Call generator.next() to get next subset. Generator will deplete once all subsets are yielded. No length limit.

permutationGenerator()

Returns permutation generator. Call generator.next() to get next permutation. Generator will deplete once all permutations are yielded. No length limit.

powerSet()

Generates and returns a set of all subsets of itself. Length of self is limited by 21 elements

permutations()

Generates and returns a set of all permutations of itself Length of self is limited by 9 elements

sort(fn)

Sorts internal order of elements in javascript Array.prototype.sort() fashion. It can be used with function expressions (and closures). For reference see official MDN documentation.

union(x) +

Performs union operation on given set with set x

join(x) +

Alias of union

difference(x) +

Returns difference of given set with set x

  const res = set1.difference(set2)

minus(x) +

Alias of difference

intersection(x) +

Returns intersection of given set with set x

symmetricDifference(x) +

Returns symmetric difference of given set with set x

equal(x) +

Returns true or false - whether given set is equal to set x

subsetOf(x) +

Returns true or false - whether given set is subset of set x

has(x)

Returns true or false - whether given set contains element x

length()

returns set length

empty()

returns true or false - whether given set is empty

add(x)

adds given x element to this set

remove(x)

removes element x from this set returns true if element was deleted, or false if element was not found

delete(x)

alias of remove

toString(delimiter = " ")

returns string representation of a given set; Delimiter is optional. By default it is 1 space;

print(delimiter = " ")

prints string representation of a given set; Delimiter is optional. By default it is 1 space;

toArray()

turns set into native Array and returns it


*Methods marked with + may take any input as CuteSet constructor. Passed input will be implicitly turned into a CuteSet instance before processing.

let a = new CuteSet([1, 2, 3]).union([2, 3, 4, 5]); // Results in {1, 2, 3, 4, 5}

let b = a.intersection([3, 4, 8, 9, 12]); // Results in {3, 4}
let b = a.intersection(3); // Results in {3}
let b = a.minus(3); // Results in {1, 2, 4, 5}

b.subsetOf([1, 3, 4, 5, 67]) // true