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

@datastructures-js/set

v4.2.1

Published

Enhanced Set that extends javascript ES6 Set

Downloads

10,965

Readme

@datastructures-js/set

build:? npm npm npm

extends javascript ES6 global Set class and implements new functions in it.

Contents

Install

npm install --save @datastructures-js/set

require

const { EnhancedSet } = require('@datastructures-js/set');

import

import { EnhancedSet } from '@datastructures-js/set';

API

constructor

JS
const set1 = new EnhancedSet(['A', 'B', 'C', 'D']);
const set2 = new EnhancedSet(['C', 'D', 'E', 'F']);
TS
const set1 = new EnhancedSet<string>(['A', 'B', 'C', 'D']);
const set2 = new EnhancedSet<string>(['C', 'D', 'E', 'F']);

union

applies union with another set and returns a set with all elements of the two.

console.log(set1.union(set2)); // EnhancedSet { 'A', 'B', 'C', 'D', 'E', 'F' }

intersect

applies intersection between the set and another set and returns the existing elements in both.

console.log(set1.intersect(set2)); // EnhancedSet { 'C', 'D' }

complement (diff)

finds the complement of another set from the set elements.

console.log(set1.complement(set2)); // EnhancedSet { 'A', 'B' }
console.log(set2.diff(set1)); // EnhancedSet { 'E', 'F' }

isSubsetOf

checks if the set is a subset of another set and returns true if all elements of the set exist in the other set.

console.log(set1.isSubsetOf(new Set(['A', 'B', 'C', 'D', 'E']))); // true
console.log(set1.isSubsetOf(set2)); // false

isSupersetOf

checks if the set is a superset of another set and returns true if all elements of the other set exist in the set.

console.log(set1.isSupersetOf(new Set(['A', 'B']))); // true
console.log(set1.isSupersetOf(set2)); // false

product

applies cartesian product between two sets. Default separator is empty string ''.

console.log(set1.product(set2));
/*
EnhancedSet {
  'AC',
  'AD',
  'AE',
  'AF',
  'BC',
  'BD',
  'BE',
  'BF',
  'CC',
  'CD',
  'CE',
  'CF',
  'DC',
  'DD', 
  'DE',
  'DF'
}
*/

console.log(set1.product(set2, ','));
/*
EnhancedSet {
  'A,C',
  'A,D',
  'A,E',
  'A,F',
  'B,C',
  'B,D',
  'B,E',
  'B,F',
  'C,C',
  'C,D',
  'C,E',
  'C,F',
  'D,C',
  'D,D', 
  'D,E',
  'D,F'
}
*/

power

applies cartesian product on the set itself and accepts a second param as a separator with default as empty string.

const x = new EnhancedSet(['A', 'B']);

const y = x.power(2);
console.log(y);
/*
EnhancedSet(4) [Set] {
  'AA',
  'AB',
  'BA',
  'BB'
}
*/

const z = y.power(2);
console.log(z);
/*
EnhancedSet(16) [Set] {
  'AAAA',
  'AAAB',
  'AABA',
  'AABB',
  'ABAA',
  'ABAB',
  'ABBA',
  'ABBB',
  'BAAA',
  'BAAB',
  'BABA',
  'BABB',
  'BBAA',
  'BBAB',
  'BBBA',
  'BBBB'
}
*/

permutations

generates m permutations from the set elements. It also accepts a second param as the separator, default is empty string ''.

const x = new EnhancedSet(['A', 'B', 'C', 'D']);

const y = x.permutations(2);
console.log(y);
/*
EnhancedSet(12) [Set] {
  'AB',
  'AC',
  'AD',
  'BA',
  'BC',
  'BD',
  'CA',
  'CB',
  'CD',
  'DA',
  'DB',
  'DC'
}
*/

equals

checks if two sets are equal.

console.log(set1.equals(new Set(['B', 'A', 'D', 'C']))); // true
console.log(set1.equals(new EnhancedSet(['D', 'C']))); // false

filter

filters the set based on a callback and returns the filtered set.

console.log(set1.filter((el) => el > 'B')); // EnhancedSet { 'C', 'D' }

toArray

converts the set into an array.

console.log(set1.toArray()); // [ 'A', 'B', 'C', 'D' ]

clone

clones the set.

console.log(set1.clone()); // EnhancedSet { 'A', 'B', 'C', 'D' }

Build

grunt build

License

The MIT License. Full License is here