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 🙏

© 2025 – Pkg Stats / Ryan Hefner

immutable-transform

v1.2.0

Published

Immutable object merge helper

Readme

JS Immutability Helper for merging objects

See https://facebook.github.io/react/docs/update.html for the backstory on why this is helpful.

Why?

The update() function from React can be really helpful when dealing with immutable state trees in Redux. I found the syntax of mongo style $ prefixed operation keys to be confusing though and thought there must be a better way.

You can think of this library as very similar to React's update() but the only possible transform is $apply. Wherever you need a computed value, you provide a function instead and that function will be called with the current value at that point in the state tree, the function's return value becomes the new value placed back into the state tree. Simple but powerful and composable.

The API

// import the package
import transform from 'immutable-transform'

// apply some changes to a state...
transform(state, changes)

// if you only pass one argument then is is assumed to be changes and you get a curried function back which can be used to apply the changes to a given state...
transformer = transform(changes)
transformer(state)

Examples

Simple value merging...

const state = {name: 'Andy', age: 30}
transform(state, {name: 'Josh'})
// => {name: 'Josh', age: 30}

Updating simple values...

const state = {name: 'Andy'}
transform(state, {
  name: (name) => name + ' Kent'
})
// => {name: 'Andy Kent'}

A counter implementation...

const state = {count: 0}
const increment = transform({count: (n) => n + 1})
increment(state)
increment(state)
// => {count: 2}

Updating arrays... the mutation here looks scary but modifiers always receive a shallow clone of the value so mutations are 'safe'

const state = {people: ['Andy', 'Ashley']}
transform(state, {
  people: (people) => people.splice(0, 1)
})
// => {people: ['Andy']}

Updating nested objects...

const state = {name: {first: 'Andy', last: 'Kent'}}
transform(state, {
  name: {
    first: 'Gareth',
    last: (old) => old.replace(/K/, 'L')
  }
})
// => {name: {first: 'Gareth', last: 'Lent'}}

Using currying for applying nested transforms...

const state = {person: {name: {first: 'Andy', last: 'Kent'}}}
transform(state, {
  person: {
    name: transform({first: 'Nick'})
    email: '[email protected]'
})
// => {person: {name: {first: 'Nick', last: 'Kent'}, email: '[email protected]'}}

Pro Mode

OK so that's nice and all but now things get awesome!

There are some optional helper functions that make common operations much clearer.

For example, adding to a list...

import transform, { push } from 'immutable-transform'

const state = {people: ['Andy']}
transform(state, {
  people: push('Ashley')
})
// => {people: ['Andy', 'Ashley']}

removing a key...

import transform, { remove } from 'immutable-transform'

const state = {people: {andy: 'Andy Kent', ashley: 'Ashley St Pier'}}
transform(state, {
  people: remove('ashley')
})
// => {people: {andy: 'Andy Kent'}}

inserting a key/value...

import transform, { insert } from 'immutable-transform'

const state = {people: {andy: 'Andy Kent'}}
transform(state, {
  people: insert('ashley', 'Ashley St Pier')
})
// => {people: {andy: 'Andy Kent', ashley: 'Ashley St Pier'}}