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

node-set-theory

v0.0.9

Published

Simple package to calculate sets using javascript...

Downloads

3

Readme

Node Set Theory

A Very brief wrapper for set calculations using Arrays...

Links

Quick Example

const { union, intersect } = require('node-set-theory');

let set1 = [1, 2, 3];
let set2 = [4, 5, 6];

console.log(intersect(union(set1, set2), set2)); // Returns [ 4, 5, 6 ]

Quick Docs

Installation

You can install node-set-theory through npm. You can use Typescript for it too...

npm install node-set-theory

In your index file

const set = require('node-set-theory');

Or when using typescript

import * as set from 'node-set-theory';

Basic Methods

const { belongs } = require('node-set-theory');

// The simple include() method
belongs([1, 2], 0); // Returns false
belongs([1, 2], 1); // Returns true.

Calculation Methods

const { union, intersect, subtract } = require('node-set-theory');

union([1, 2], [3, 2]); // Will return [1, 2, 3]
intersect([1, 2]. [3, 2]); // Will return [2]
subtract([1, 2], [3, 2]); // Will return [1]
subtract([3, 2], [1, 2]); // Will return [3]

Verifying Methods

const { isNull, isProper, isEqual, isSubset, isProperSubset, overlaps } = require('node-set-theory');

// Verify is the set empty aka null set
isNull([]); // Will return false
isNull([1]); // Will return true.

// Simple method to find is the set is proper set or not
isProper([null, 1, 2]); // Will return false because it has null
isProper([1, 2, 3]); // Will return true. 

// Verify is the set equal to the second set
isEqual([1, 0], [0, 1, 5]); // Will return false because the second set has extra element 5
isEqual([1, 0], [0, 1]); // Will return true.

// Method to find is the set are disjoint set or overlapping set
overlaps([1, 2, 3], [4, 5, 6]); // Will return false because none of the elements same between the sets
overlaps([1, 2, 3], [4, 3, 2]); // Will return true as 2 and 3 are common between those 2 sets

// Method to verify is the set is the subset of the given sent
isSubset([1, 2, 3], [1, 2]); // Will return true
isProperSubset([1, 2, 3], [null, 2, 3]); // Will return false because it verifies the proper subset...

Power Set Methods

const { subsets, properSubsets } = require('node-set-theory');

// Method to get all subsets also known as the power set
subsets([1, 2, 3]);
// Returns [ [], [ 1 ], [ 2 ], [ 2, 1 ], [ 3 ], [ 3, 1 ], [ 3, 2 ], [ 3, 2, 1 ] ]

// Get all the proper subsets
properSubsets([1, 2, 3]);
// Returns [ [ 1 ], [ 2 ], [ 2, 1 ], [ 3 ], [ 3, 1 ], [ 3, 2 ], [ 3, 2, 1 ] ]

Types Methods

const { sizeType } = require('node-set-theory');

// Will return 'empty', 'singleton' or 'many' based on the size of the set...
sizeType([]); // Will return 'empty' which means null set
sizeType([1]); // Will return 'singleton' which means it has only 1 element
sizeType([1, 2, 3]); // Will return 'many' which means it has more than 1 element

Shorthand Methods

const { n, P, proper } = require('node-set-theory');

// Find the length of the array
n([1, 2]); // Will return 2 as length

// Get power set of the array
P([1, 2, 3]); // Will return [ [], [ 1 ], [ 2 ], [ 2, 1 ], [ 3 ], [ 3, 1 ], [ 3, 2 ], [ 3, 2, 1 ] ]

// Convert your set to proper set
proper([null, [], 1, 0, 5]); // Will return [1, 5]

Things need to be done

This package is at its extent but has some missing features to be done which you can try to contribute...

  • Only Roster sets: Yes the point is set builder form and the descriptive form cannot be used here. You can still use Roster form of sets. Example: [1, 2, 3]. The second problem with it is that you cannot use {} because of the traditional Javascript Arrays [] uses this kind of brackets...

  • Advanced Calculations: This package misses some advanced calculations with set which i don't know myself what are those? Incase if you feel that you know some, try to contribute in github!

  • Representation of null: So most of the people use {} or to represent null in maths but in this package represents null as [] and null...

  • Shorthand Operations: This package misses up lot of shorthand operations like the following. (A U B) - B. You have to do subtract(union(A, B), B) using this package. So it will be good to give us ideas or contribute in github to make shorthand operations...

  • Universal Sets: You cannot make like universal sets in this. This is possible to create but because of lack of developers, this feature might come in upcomming periods. Or you can try to contribute this feature!