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

@amatiasq/state-delta

v0.1.0

Published

`diff` two JSON values, send the difference, `patch` it back. Made for state that travels thirty times a second: the delta carries only what changed, and a value the receiver can work out on its own costs nothing at all.

Readme

@amatiasq/state-delta

diff two JSON values, send the difference, patch it back. Made for state that travels thirty times a second: the delta carries only what changed, and a value the receiver can work out on its own costs nothing at all.

npm i --save @amatiasq/state-delta

Usage

import { diff, patch } from '@amatiasq/state-delta';

const delta = diff(previous, next);
if (delta !== undefined) send(JSON.stringify(delta));

// the other end
state = patch(state, JSON.parse(message));

patch never mutates what it is given, so the previous state stays valid and a delta that arrives twice is harmless.

The format

A delta is plain JSON and travels as it is:

| Delta | Means | | ---------------- | ----------------------------------------------------- | | undefined | nothing changed | | [] | this is gone | | [value] | replace the whole object or array with value | | { $: n, 2: … } | an array of length n, with the indices that changed | | anything else | the new value |

A replacement is wrapped in an array so it cannot read as a partial update: { a: 1 } says the key a changed, [{ a: 1 }] says the whole value is now { a: 1 }.

$ is reserved: an array delta keeps its new length there, so diff throws on an object that uses that key rather than let it travel as something else.

UNCHANGED

UNCHANGED is the sender saying "skip this one, you can work it out yourself". The key is left out of the delta and patch keeps whatever the receiver has — zero bytes, not a marker or a code.

diff({ x: 0, hp: 3 }, { x: UNCHANGED, hp: 2 }); // { hp: 2 }

The mirror invariant

Diff against what the receiver holds, never against the last value you built. The sender keeps a mirror of the receiver and moves it forward by patching the very delta it just sent:

const delta = diff(mirror, next);
mirror = patch(mirror, delta);
send(delta);

That is what keeps a skipped value from rotting. Diff against your own truth instead and the field looks unchanged for ever: it never travels again, and the receiver keeps a value nobody is going to correct.