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-base

v0.1.4

Published

Utilities for creating immutable classes

Downloads

5

Readme

immutable-base

A simple utility for creating immutable classes in javascript.

Immutable objects are in vogue because of frameworks like flux. There are some fairly heavyweight libraries out there that do all kinds of cool stuff with collections, such as Immutable.js.

This is really nothing but a handy utility for creating immutable object classes. For example:


const Immutable = require(immutable-base);

const MyClass = Immutable({ name: "", address, "", tel: ""});

Creates a class MyClass which has immutable properties name, address, and tel all of which default to the empty string. Attempting to change these properties results in an error, but the class has setter methods which create a new instance of the class with the change applied.

The created class also has a constructor which will take arguments to set name, address, and tel in that order OR take an object with optional name, address, and tel properties and assign the values appropriately. Thus:


let person = new MyClass("jonathan", "1 road lane", "0800-999-888-777");
let person2 = new MyClass({name: "robert"});
let person3 = person2.setAddress(person1.address);

Would be perfectly valid code given only the class definition above. Equally:


person3.address = "22 field park";

Would throw an exception.