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

immu

v3.0.0

Published

A TINY, fail-fast, lazy, "naked", simple immutable Javascript objects library

Downloads

393

Readme

immu NPM Module NPM download count Build Status

emu

A TINY, fail-fast, lazy, "naked", simple immutable Javascript objects library.

  • By TINY, less than 1k gzipped and minified.
  • By fail-fast, I mean you'll be notified if you try to change a property.
  • By lazy, I mean it doesn't evaluate the mutability of a property until it absolutely has to.
  • By naked, I mean they work like regular objects and arrays.
  • By simple, I mean that it doesn't add any extra features to your code (except immutability, of course).

What Immu Aims To Solve

Immu aims to solve 2 things:

  1. Immutable javascript Objects (Arrays are objects in Javascript).
  2. Fail-fast errors with detailed exceptions upon attempting to mutate Objects.

Immu does not attempt to add functionality to Arrays, introduce complex data structures like Map and Set, or provide a complete solution with cursors and stores. Immu is meant to be the simplest possible solution to providing immutable objects while maintaining the native API for those objects (including Array methods).

Other libraries that are similar but do more:

Each of these libraries are GREAT in their implementation and at the problems they solve:

Why Use Immutable Data?

Bugs happen because developers write them. This just puts one more layer between you and your code exploding. Immutable data can't promise to help you avoid all bugs, but can help you reason about your state much easier!

Install

npm install immu --save

Usage

'use strict';

let immu = require('immu');

let user = {
  name: 'Scott',
  age: 31,
  location: 'somewhere'
};

let immutableUser = immu(user);

try {
  immutableUser.name = 'Unchangeable';
}
catch (e) {
  console.error(e.message); // Cannot change value of an immutable property
}

console.log(immutableUser.name) // Scott

// Get the raw object back
console.log(immutableUser.toJS()); // {name: 'Scott', age: 31, location: 'somewhere'}

let list = immu([1, 2, 3, 4]);
let newList = list
  .map(item => item + 1)
  .filter(item => item % 2 === 0);
  
console.log(Array.isArray(list)) // true

Run Tests

git clone https://github.com/scottcorgan/immu.git && cd immu
npm install
npm test