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

jackscript-js

v2.1.4

Published

Discrete mathematics library

Downloads

189

Readme

About jackscriptjs

Jackscript-js is a javascript math library of sets. It covers a few useful functions involving sets that are otherwise not available in the standard Javascript library.

Version 2.1.4 - Change log

Installation

install jackscript-js npm i jackscriptjs --save

import {Coordinate} from 'jackscriptjs';
How this library works:

This library is about sets. Jackscript implements Set. This library is Generic, meaning you can use any primitive. You are allowed to use strings, numbers, or any other type.

The Coordinate declaration is as follows: This is basically a tuple.

type Coordinate<T, V> = [T, V];

We also introduce a type called Relation which is of the type Jacksript of which we introduce in the next section:

type Relation<T, V> = JackscriptSet<Coordinate<T, V>> | JackscriptSet<T>;

How to create a set:

Sets are created how you would normally create your set in javascript. Therefore all set methods from the javascript standard library will work like usual

let mySet = set()

However, we also introduce a new Set called JackscriptSet and this is how you use it:


// first import the set and the coordinate type:
import {JackscriptSet, Coordinate} from 'jackscriptjs';

// instantiate your set:
let a = new JackscriptSet<number>();
let b = new JackscriptSet<number>();

// use the usual set methods, like you would in an other javascipt program:
a.add(100);
a.add(200)
console.log(a);

This will return:

JackscriptSet {
  internalSet: Set(2) { 100, 200 },
  [Symbol(Symbol.toStringTag)]: 'JackscriptSet'
}

A minor difference between Set() and JackscriptSet(), is that in Jackscript the methods add() and delete() are a bit different. In Set(), you are only allowed to pass in one argument for these methods. Whereas in Jackscript, you may pass in multiple arguments:

import {JackscriptSet, Coordinate} from 'jackscriptjs';

let a = new JackscriptSet<number>();
a.add(1,2,3); // this is allowed
a.delete(2,3); // this is also allowed

// All other Set methods are the same. 

...And that is the core difference between Set and Jacksript set.

Print your set:

This is how you print your set:

let a = new JackscriptSet<number>();
a.add(1,2,3); 
a.print();

This will return:

1
2
3

Static set methods:

Intersects, union, domain, range:


let setA = new JackscriptSet<number>();
let setB = new JackscriptSet<number>();
setA.add(1,2,6);
setB.add(6,7);

// setC is a union of setA and B:
let setC = JackscriptSet.intersect(setA, setB);
setC.print(); // returns 6

let setD_relation: Relation<number, number> = setA.createCartesian(setB);

let domainVariable = JackscriptSet.domain(setD_relation);
let rangeVariable = JackscriptSet.range(setD_relation);
console.log(domainVariable); // returns 1,2,6
console.log(rangeVariable); // returns 6,7

IsSubsetOf() and IsSupersetOf()

IsSubsetOf() and IsSuperSetOf() are used exactly how you would if your were to use Javascript Sets.

let mySet = new JackscriptSet<number>([3,4,5,7]);
let mySetSubset = new JackscriptSet<number>([3,4]);

console.log(mySetSubset.isSubsetOf(mySet)); // prints true
console.log(mySet.isSupersetOf(mySetSubset)); // prints true

-----------------------------------