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

@shapeshift-labs/frontier

v0.1.9

Published

Fast compact JSON diff and patch primitives for JavaScript values.

Downloads

13,954

Readme

Frontier

Fast compact JSON diff and patch primitives for JavaScript values.

Frontier compares JSON-shaped data and emits a replayable compact patch. It is built for application state, cached API results, editor models, game state, compiler data, and other in-memory JSON values where the useful output is not just "different", but "what compact operations reproduce the new value?".

This package is the small core package. It has no runtime dependencies and does not include Frontier query helpers, codecs, engine planning, state subscriptions, caches, schema helpers, logging, mutation planning, CRDTs, sync, or rich text. It also exposes dependency-free ./runtime and ./registry subpaths for sharing scheduler and traceable feature-graph contracts across Frontier packages without creating higher-layer imports.

Related Packages

The published Frontier package family is generated from one shared package catalog so READMEs stay in sync across packages:

Package source repositories:

Install

npm install @shapeshift-labs/frontier

Usage

import { applyPatchImmutable, diff } from '@shapeshift-labs/frontier';

const before = {
  todos: [
    { id: 'a', done: false },
    { id: 'b', done: false }
  ],
  meta: { version: 1 }
};

const after = {
  todos: [
    { id: 'a', done: true },
    { id: 'b', done: false },
    { id: 'c', done: false }
  ],
  meta: { version: 2 }
};

const patch = diff(before, after, { arrayKey: 'id' });
const next = applyPatchImmutable(before, patch);

console.log(next);

API

import {
  diff,
  diffInto,
  diffStable,
  applyPatch,
  applyPatchImmutable,
  applyJsonPatch,
  applyJsonPatchImmutable,
  normalizePatch,
  assertPatch,
  cloneJson,
  equalsJson,
  equalsJsonFast,
  parsePointer,
  stringifyPointer
} from '@shapeshift-labs/frontier';

diff(before, after, options?)

Returns a compact Frontier patch.

Useful options:

  • arrayKey: key or getter used to match object-array rows.
  • autoArrayKey: enables conservative key detection for reordered object arrays.
  • dirtyPaths: trusted changed paths supplied by a producer.
  • dirtyRows: compact row-oriented dirty frontier.
  • fingerprintKey / versionKey: trusted subtree tokens that skip unchanged branches.
  • maxPatchOperations: emits one root replacement when a patch would be too long.
  • stable: sorts object keys for deterministic patch order.

diffInto(before, after, reusablePatch, options?)

Writes into a caller-owned patch array to reduce allocation in hot loops.

const patch = [];
for (const frame of frames) {
  diffInto(frame.before, frame.after, patch);
  send(patch);
}

applyPatch(value, patch, options?)

Applies a Frontier patch mutably where possible. Pass { cloneValues: true } if inserted patch values should be cloned before assignment.

applyPatchImmutable(value, patch, options?)

Applies a Frontier patch without mutating the input root. This is usually the safest API for app state.

JSON Pointer Helpers

import { getPointer, parsePointer, stringifyPointer } from '@shapeshift-labs/frontier';

const path = parsePointer('/todos/0/done');
const pointer = stringifyPointer(path);
const value = getPointer(document, pointer);

Registry Graphs

@shapeshift-labs/frontier/registry defines the shared feature/method graph used by state engines, mutation actions, DOM manifests/devtools, Playwright probes, and logging telemetry:

import {
  createFrontierRegistry,
  frontierRegistryExplain,
  frontierRegistryImpact,
  frontierRegistryTrace
} from '@shapeshift-labs/frontier/registry';

const registry = createFrontierRegistry();
registry.register({
  id: 'todo.toggle',
  kind: 'action',
  package: '@app/todos',
  feature: 'todos',
  source: { file: 'src/features/todos/actions.ts', exportName: 'toggleTodo' },
  reads: ['/todos/*/done'],
  writes: ['/todos/*/done'],
  invalidates: ['todo.visible'],
  touches: ['route:/todos'],
  tags: ['mutation']
});

const graph = registry.inspect();
const impact = frontierRegistryImpact(graph, {
  paths: ['/todos/a/done']
});
const explain = frontierRegistryExplain(graph, {
  features: ['todos'],
  validation: { requireFeature: true, requireSource: true }
});
const trace = frontierRegistryTrace(graph, {
  ids: ['todo.toggle'],
  targets: { nodes: ['route:/todos'] }
});

The graph stores declarative edges and observed records as data. Production code can keep direct imports/calls while tools consume the sidecar graph for impact analysis, replay, validation, feature/package/tag/source-file indexes, and AI-readable traces.

Equality And Clone Helpers

import { cloneJson, equalsJson, equalsJsonFast } from '@shapeshift-labs/frontier';

const copy = cloneJson(value);
const same = equalsJsonFast(copy, value);

Runtime Budget Helpers

import { diff } from '@shapeshift-labs/frontier';
import { createRuntimeScheduler } from '@shapeshift-labs/frontier/runtime';

const scheduler = createRuntimeScheduler({ maxUnits: 48 });
const patch = diff(before, after);

scheduler.schedule({ area: 'diff', run: () => patch });
scheduler.schedule({ area: 'codec', run: () => JSON.stringify(patch) });
scheduler.schedule({ area: 'logging', priority: 'low', run: () => JSON.stringify({ event: 'patch', ops: patch.length }) });

const result = scheduler.run();

The runtime subpath is intentionally structural and dependency-free. It provides createRuntimeBudget(), createRuntimeScheduler(), and the standard work areas diff, apply, codec, sync, cache, and logging. Higher packages can use the same budget object shape without the core package importing any of those packages.

Why Frontier Patches Are Compact

Frontier's patch format uses numeric tuple opcodes instead of verbose JSON Patch objects. It can represent common state changes directly:

  • OP_SET for replacing a value.
  • OP_REMOVE for deleting an object field or array item.
  • OP_APPEND and OP_ARRAY_SPLICE for array edits.
  • OP_STRING_SPLICE and OP_STRING_COPY for localized text changes.
  • OP_ARRAY_MOVE for keyed row movement.
  • OP_ASSIGN, OP_ARRAY_OBJECT_ASSIGN, and tuple/field assign ops for batches of related updates.

The normal invariant is:

applyPatchImmutable(before, diff(before, after)) === after

Use diffStable() or { stable: true } when deterministic object-key walk order matters more than raw speed.

Patch Format

A Frontier patch is an array of tuples. You normally do not need to construct these by hand, but the constants are exported for tooling and tests.

import { OP_SET, type Patch } from '@shapeshift-labs/frontier';

const patch: Patch = [[OP_SET, ['status'], 'done']];

The tuple format is optimized for in-memory replay and for compact transport once a codec is added above this core package.

Subpath Imports

Use subpaths when you want a narrower import surface:

import { diff } from '@shapeshift-labs/frontier/diff';
import { applyPatchImmutable } from '@shapeshift-labs/frontier/patch';
import { parsePointer } from '@shapeshift-labs/frontier/pointer';
import { equalsJsonFast } from '@shapeshift-labs/frontier/equal';
import { createRuntimeScheduler } from '@shapeshift-labs/frontier/runtime';

Package Scope

This package is intentionally limited to:

  • JSON diffing.
  • Compact patch replay.
  • RFC6902-style JSON Patch apply helpers.
  • JSON Pointer helpers.
  • JSON clone/equality/validation helpers.
  • Unicode string utilities used by the diff core.
  • Dependency-free runtime budget and scheduler contracts for coordinating work in higher packages.

Query helpers, codecs, engine planning, state, state-cache, schema, event logs, logging, mutation, CRDT, sync, rich text, and package-specific tooling belong in companion packages. The core package stays focused on JSON diff/apply primitives and has no runtime dependencies.

TypeScript

Frontier ships first-party TypeScript declarations for the root package and every core subpath. The runtime package is plain ESM JavaScript, and the types are included in dist/*.d.ts.

import { diff, applyPatchImmutable, type DiffOptions, type JsonValue, type Patch } from '@shapeshift-labs/frontier';
import type { JsonPath, PatchOperation } from '@shapeshift-labs/frontier/types';

const options: DiffOptions = { arrayKey: 'id' };
const patch: Patch = diff(before as JsonValue, after as JsonValue, options);
const next = applyPatchImmutable(before as JsonValue, patch);

Subpath declarations are also exported:

import { diff } from '@shapeshift-labs/frontier/diff';
import { applyPatchImmutable, type Patch } from '@shapeshift-labs/frontier/patch';

The package includes exports.types, a ./types subpath, and typesVersions mappings for TypeScript projects that still use older Node-style package resolution.

Validation

The standalone package repository includes package-level tests that run against the built JavaScript distribution:

npm test
npm run fuzz
npm run bench
npm run pack:dry

The test suite covers:

  • TypeScript consumer checks against the published declarations.
  • Smoke tests for root and subpath imports.
  • Deterministic core diff/apply API tests.
  • A seedable diff/apply fuzzer covering nested JSON objects, arrays, strings, scalars, stable diffing, patch validation, mutable apply, immutable apply, and normalized patch replay.

The fuzzer can be run directly:

node test/diff-fuzz.mjs --cases 5000 --seed 1234

Benchmarks

Run the package-local benchmark:

npm run bench

Latest local package benchmark on Node v26.1.0, darwin arm64, 9 rounds. Timings are median microseconds per operation; p95 is shown to make noise visible.

| Fixture | Patch | Bytes | diff() median | diff() p95 | applyPatchImmutable() median | | --- | ---: | ---: | ---: | ---: | ---: | | Small object field edit | 1 op | 26 B | 0.56 us | 0.65 us | 0.09 us | | 1k keyed rows, one field edit | 1 op | 31 B | 268.79 us | 272.13 us | 0.32 us | | 1k keyed rows with dirty path hint | 2 ops | 66 B | 0.59 us | 0.71 us | 0.39 us | | 10k text middle insert | 1 op | 32 B | 2.89 us | 3.02 us | 0.10 us |

The package benchmark also includes a runtime scheduling fixture. It compares independent per-area slices with one shared scheduler slice over mixed diff, apply, codec, sync, cache, and logging work.

| Runtime fixture | Target units | Completed units | Overrun | Median | | --- | ---: | ---: | ---: | ---: | | Ad hoc per-area slices | 48 | 288 | 240 | 2,353.42 us | | Central scheduler slice | 48 | 48 | 0 | 449.21 us | | Direct full mixed work | 384 | 384 | 0 | 3,099.61 us | | Scheduler full mixed work | 384 | 384 | 0 | 3,267.48 us |

These numbers are Frontier-only package measurements, not a competitor comparison. Hardware, Node version, and data shape will affect absolute timings.

License

MIT. See LICENSE.