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

cell-multiset

v0.0.3

Published

Fast JS MultiSet implementation.

Downloads

8

Readme

Build Status Coverage Status Inline docs MIT license

Fast & consistent JavaScript MultiSet (AKA bag, bunch) implementation. Implemented as part of my upcoming(...loading...) cell game engine, but perfectly usable as a standalone lib.

Features

  • Fast!
  • Fully tested
  • Fully documented
  • Pascal case operands can be used to output new multisets
  • Chaining
  • Lots of aliases
  • Prototypal & Classical inheritance ready
  • Supports amd, node, globals, es6 modules
  • Lots of output options
  • ES6 & ES5 binaries (as well as intermediate version)
  • Made with bits of love!

Installation

bower

bower install cell-multiset

npm

npm install cell-multiset

Usage

var obj = {iam: 'object'};

var ms1 = MultiSet.create([7, 67, 7, 7, 'text', obj, 'text', obj]); // use an iterable for initialization.
var ms2 = Object.create(MultiSet).init([7, 67, 7, 'text', obj, 'text2', obj, 99]);
var ms3 = new MultiSet.constructor([7, 67, 7, 7, 'text', obj, 'text', obj]); // or use the constructor function. Preferably you'd want to use the CMultiSet export for this.

expect(ms1.size).to.eql(8); // cardinality (@alias) of the multiset.
expect(ms1.toString()).to.eql('{7 => 3, 67 => 1, text => 2, [object Object] => 2}');
expect(ms1.has(7)).to.be.true;
expect(ms1.multiplicity(obj)).to.eql(2);
expect(ms1.multiplicity(undefined)).to.eql(0); // non existent elements have multiplicity 0.
expect(ms1.equals(ms3)).to.be.true; // checks equality between 2 multisets.

ms1.union(ms2);

expect(ms1.toString()).to.eql('{7 => 3, 67 => 1, text => 2, [object Object] => 2, text2 => 1, 99 => 1}');
expect(ms1.size).to.eql(10);

var ms4 = ms3.Union(ms2); // use Pascal case Union to output a new MultiSet and leave ms3 unchanged.

expect(ms3.toString(1)).to.eql('[7, 7, 7, 67, text, text, [object Object], [object Object]]'); // use mode=1 to output single dimension array-like string.
expect(ms4.toString()).to.eql('{7 => 3, 67 => 1, text => 2, [object Object] => 2, text2 => 1, 99 => 1}');

For more usage example see the unit tests @ /test/unit/MultiSet-spec.js

Prototypal(OLOO) vs 'Classical' inheritance

By default prototypal(OLOO) inheritance is supported. Practically this means that the default export will be the MultiSet prototype. Also all static properties will be directly available on the prototype (as well as on the constructor function). If you prefer 'classical' inheritance a CMultiSet export is also provided.

Documentation

Documentation can be generated by running the command below and is outputted @ /doc.

npm run docs

Make sure you'll run a npm install first.