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

json-undo

v1.0.1

Published

A lightweight library for tracking changes in JSON objects with undo and redo functionality. Efficiently manages changes without duplicating entire objects, ideal for memory-sensitive applications.

Readme

JSON Undo

JSON Undo is a lightweight library for tracking changes in JSON objects with undo and redo functionality. It is designed for memory-sensitive applications by efficiently managing changes without duplicating entire objects.

Installation

npm install json-undo

Usage

Example 1: Basic Usage with Undo and Redo

const JSONChangesTracker = require('json-undo');

const original = { name: "Alice", age: 25 };
const tracker = new JSONChangesTracker(original);

console.log(tracker.get()); 
// Output: { name: "Alice", age: 25 }

original.name = "Bob"; 
tracker.update(original); 

console.log(tracker.get()); 
// Output: { name: "Bob", age: 25 }

original.age = 26; 
tracker.update(original);

console.log(tracker.get()); 
// Output: { name: "Bob", age: 26 }

// Undo the last change
tracker.undo();
console.log(tracker.get()); 
// Output: { name: "Bob", age: 25 }

// Redo the undone change
tracker.redo();
console.log(tracker.get()); 
// Output: { name: "Bob", age: 26 }

Example 2: Complex JSON Object with Nested Changes

const JSONChangesTracker = require('json-undo');

const original = { 
  user: { name: "Charlie", details: { age: 30, city: "New York" } }, 
  active: true 
};

const tracker = new JSONChangesTracker(original);

console.log(tracker.get()); 
// Output: { user: { name: "Charlie", details: { age: 30, city: "New York" } }, active: true }

original.user.name = "David"; 
tracker.update(original);

console.log(tracker.get()); 
// Output: { user: { name: "David", details: { age: 30, city: "New York" } }, active: true }

original.user.details.city = "San Francisco"; 
tracker.update(original);

console.log(tracker.get()); 
// Output: { user: { name: "David", details: { age: 30, city: "San Francisco" } }, active: true }

original.active = false; 
tracker.update(original);

console.log(tracker.get()); 
// Output: { user: { name: "David", details: { age: 30, city: "San Francisco" } }, active: false }

// Undo all changes
tracker.undo();
console.log(tracker.get()); 
// Output: { user: { name: "David", details: { age: 30, city: "New York" } }, active: true }

tracker.undo();
console.log(tracker.get()); 
// Output: { user: { name: "Charlie", details: { age: 30, city: "New York" } }, active: true }

// Redo the last undo
tracker.redo();
console.log(tracker.get()); 
// Output: { user: { name: "David", details: { age: 30, city: "New York" } }, active: true }

tracker.redo();
console.log(tracker.get()); 
// Output: { user: { name: "David", details: { age: 30, city: "San Francisco" } }, active: true }

Example 3: Checking if Undo/Redo is Possible

const JSONChangesTracker = require('json-undo');

const original = { item: "Laptop", price: 1000 };
const tracker = new JSONChangesTracker(original);

console.log(tracker.canUndo()); // Output: false (No changes yet)
console.log(tracker.canRedo()); // Output: false (No undone changes)

original.price = 1200; 
tracker.update(original);
console.log(tracker.get()); // Output: { item: "Laptop", price: 1200 }

console.log(tracker.canUndo()); // Output: true (Undo possible)
console.log(tracker.canRedo()); // Output: false (No redo yet)

tracker.undo();
console.log(tracker.get()); // Output: { item: "Laptop", price: 1000 }

console.log(tracker.canUndo()); // Output: false (No more undo)
console.log(tracker.canRedo()); // Output: true (Redo possible)

tracker.redo();
console.log(tracker.get()); // Output: { item: "Laptop", price: 1200 }

Features

  • Track JSON object changes.
  • Undo and redo functionality.
  • Memory-efficient change tracking.
  • Suitable for large objects.

API

new JSONChangesTracker(initialJson: object)

Creates an instance of JSONChangesTracker.

update(updatedJson: object)

Tracks the changes in the provided JSON object.

undo(): object

Reverts the JSON object to the previous state.

redo(): object

Restores the JSON object to the state before the undo.

get(): object

Returns the current state of the JSON object.

canUndo(): boolean

Returns true if there is a history of changes to undo.

canRedo(): boolean

Returns true if there are undone changes to redo.

License

This project is licensed under the MIT License.

Author

Manish Gun