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

immutable-class

v0.11.2

Published

A template for creating immutable classes

Downloads

20,439

Readme

Immutable Class

A little library to facilitate creating and testing serializable, immutable classes.

This library is really just a set of templates and testing tools to allow for quick construction of immutable classes.

Templates

An object Blah is considered a immutable class of it meats the following criteria:

  • It is a JS 'class' that starts with an uppercase letter
  • It has a static Blah.isBlah method for checking if something is an instance of the given class
  • It has a static Blah.fromJS method for deserializing classes
  • It has an instance blah.valueOf method that return a minimally serialized object (preserving all sub classes as immutable classes)
  • It has an instance blah.toJS method that return a fully serialized object (recursively serializing all sub classes)
  • It has an instance blah.toJSON method that returns the same as the toJS method allowing the object to be passed into JSON.stringify
  • It has an instance blah.toString method that is implemented in some way (and returns a string)
  • It has an instance blah.equals method that can be used to compare this object to other classes to check for equivalence.

Testing tools

Immutable Class provides one testing function for testing potential immutable classes: testImmutableClass

It is used like so:

testImmutableClass(MyImmutableClassConstructor, [
  { "potential": 1 }
  { "distinct": 2 }
  { "js": 3 }
  { "immutable classes": 4 }
]);

This function will then try to call fromJS on each candidate and run it through a series of tests to ensure that it corresponds to the rules above. It will also do an equality check of every object with every other object and make sure that it only equals itself.

For an example of the usage of this library look at these files: source, tests.