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 🙏

© 2026 – Pkg Stats / Ryan Hefner

revise-immutable

v1.1.9

Published

Expression-based utility to change immutable objects.

Readme

revise-immutable

Expression-based utility to create modified copies of immutable objects.

Set

  • Modify properties
  • Build and populate objects with an expression
  • Array operations (find/delete/insert/append)
  • Set values based on existing values

Get

  • Get object values using the same expression language

Setup

npm install revise-immutable

Usage

import revise from "revise-immutable";

// Setter
newObject = revise.set(oldObject, "item.collection[$2.selectedIndex].prop", "value");

// Getter 
value = revise.get(object, `path.to[find(${i => i.selected})].color`);

revise.set(<object>, <expression>, <value|valueSetterFunction>, [expression(n), value(n)...])

returns new object where the value at <expression> is modified to <value> without mutating the original object.

  • <object> Object to create a revision of
  • <expression> Expression describes what to revise relative to <object>
    • Expressions consist of:
      • property specifiers ex: "item.selectedIndex"
      • array specifiers ex: "items[1]" consist of
        • any expression that resolves to an integer in the array

          example: [1] or [(Math.PI * 100)>>0]

        • the remove() special function, which removes an element from the array

          example: "items[remove(1)]"

        • stack variables are defined as $1 to $n (incrementing), where $1 is the array itself, and $n is the root object.

          example: "items[$2.selectedIndex].color"

        • variable functions are available to append() and insert() elements into the array.

  • <value> is the value to set at the given path
  • <valueSetterFunction> optionally, you can provide a function to set the value. This is useful if the value you are setting is based off of an existing value in the object structure. Note that the stack is passed in as individual arguments to this function.
    example: revise.set(o, "users[0].likes", (likes, index, users) => likes + 1)

revise.get(<object>, <expression>)

  • expression is same as above, except that it doesn't support array modification functions insert(), remove(), append().

Advanced Usage

Object Construction

Revise can interpret your expression and build out what isn't there.

revise.set({}, "item.collection[0].description", "Yah!");

// Produces this!
{
    item: {
        collection: [
            {
                description: "Yah!"
            }
        ]
    }
}

Arrays

// insert
// Inserts the value into the array at the specified position
revise.set(o, "gallery.photos[insert($2.selectedPhotoIndex + 1)]", newPhoto);

// append
// Returns the last index in the array plus 1
revise.set(o, "gallery.photos[append()]", newPhoto);

// remove
// Removes the first element that matches the condition
revise.set(o, "gallery.photos[remove($2.selectedPhotoIndex)]");

// find
// Finds the first element that matches the condition
revise.set(o, 
    `gallery.photos[find(${p => p.selected})].description`, 
    newDescription
);

// find or append
// Finds the first element that matches the condition
// If no element is found, returns the last index in the array plus 1
revise.set(o,
    `app.checklist[findOrAppend(i => i.id == ${itemId})])`,
    item => item != null 
        ? {...item, value: value} 
        : {id: itemId, value: value})
)

NOTE : in between [ ]'s, the following "stack variables" are available:

  • $1 : reference to the array.
  • $2 : reference to parent of array (if exists)
  • $<n> : parent of n - 1...

Set Values Dynamically

// Use the existing values to make new ones
revise.set(o, "users[$2.selectedUserIndex].likes", likes => likes + 1);

// The full stack is available
revise.set(o, "a.b.c.d", (d, c, b, a, root) => root.score + c.score)

Batching

Combine multiple expressions together for one result.

const newObject = revise.set(o, 
    "options.preferences.theme", theme
    "options.preferences.editor.font", font
    "user.account.name", name
);

Limitations

  • Revise doesn't handle strings with unmatched square brackets in the expression.
    • example revise.set(o, "items[find(i => i.name == ']')]) will cause an error
  • Revise only understands property names with ASCII characters A-Z, a-z, _, $, 0-9.
  • The find function expects an expression. In some older browsers, arrow functions may not be supported. You may use "function()" syntax instead of the arrow function syntax to remedy this. Another approach that works in some cases is to use string substitution such as a[find(${f => f.})], such that your own transpilation process will substitute the non-arrow function as appropriate. This, however, has the limitation in that it can't read external veriables.