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

@bybrave/fast-json-patch2

v4.0.0

Published

Maintained fork of fast-json-patch — RFC-6902 JSON Patch with observe/compare, now with a modern exports map, dual ESM+CJS, built-in types, a Date/toJSON compare fix and 0 dependencies

Readme

@bybrave/fast-json-patch2

CI npm

Maintained fork of fast-json-patch — a fast RFC-6902 JSON-Patch implementation with observe/compare (diff) support — with a modern exports map, dual ESM+CJS, built-in TypeScript types, a Date/toJSON compare fix and 0 dependencies.

The original package has ~30M downloads/month and no release since 2022. Its package.json has no exports field (so named ESM imports and modern bundlers break) and compare/observe shred Date values into char-by-char patches. This fork keeps the RFC-6902 apply path byte-for-byte (verified against the official JSON-Patch conformance suite) and fixes the packaging and diff bugs.

npm install @bybrave/fast-json-patch2
// CommonJS
const jsonpatch = require('@bybrave/fast-json-patch2');

// ESM — named imports now work
import { applyPatch, compare, observe, generate } from '@bybrave/fast-json-patch2';

// TypeScript types built in

The Date bug, and how it is fixed

compare and observe clone the document through JSON.stringify, which turns a Date into an ISO string. The live object still holds the Date, so the diff walks a string against an object and emits one add per character:

// original [email protected]
compare({ when: new Date('2024-01-01') }, { when: new Date('2024-06-15') });
// [ {op:'add', path:'/when/0', value:'2'}, {op:'add', path:'/when/1', value:'0'}, … ] 💥

This fork treats any value exposing toJSON (Date, luxon DateTime, Decimal.js, …) as an atomic leaf and diffs it by its serialized form:

// @bybrave/fast-json-patch2
compare({ when: new Date('2024-01-01') }, { when: new Date('2024-06-15') });
// [ { op: 'replace', path: '/when', value: '2024-06-15T00:00:00.000Z' } ]

compare({ t: new Date('2024-01-01') }, { t: new Date('2024-01-01') });
// []  — equal dates, no spurious patch

The apply path is untouched, so this changes nothing about how patches are applied — only how compare/observe generate them.

Fixes over [email protected]

| Fixed | Original issue | |---|---| | No exports map → named ESM imports and bundlers (parcel, webpack 5) fail | #310, #317, #311, #129, #323 | | compare/observe shred Date / toJSON values into char-by-char patches | #325, #272, #278, #318, #332, #183 | | ESM delivered via a sed-based build script | — (replaced with tsup) | | Empty-string key ("") round-trip, undefined-source diff — regression-tested | #260, #280 | | escapePathComponent / unescapePathComponent public and typed | #173 |

By design (documented, not changed)

  • compare is a positional array diff — inserting into an array can produce a cascade of replace ops. The patch is valid and applies correctly; minimal (LCS) array diffing is out of scope (#215, #282).
  • No move generation in compare (#91); observe keeps dirty-checking, not Proxy (#96).
  • The RFC-6902 operation logic, JSON-Pointer handling and the banPrototypeModifications security guard are preserved exactly.

Migrating from fast-json-patch

- const jsonpatch = require('fast-json-patch');
+ const jsonpatch = require('@bybrave/fast-json-patch2');

The API is identical. Named ESM imports that used to fail now work:

import { applyPatch, compare } from '@bybrave/fast-json-patch2';

If you diff documents containing Date values, compare/observe now produce clean replace ops instead of char-by-char patches — no code change needed on your side.

API

// Apply
jsonpatch.applyPatch(document, patch);                 // returns { newDocument, … }
jsonpatch.applyOperation(document, operation);
jsonpatch.applyReducer(document, operation, index);    // reducer signature
jsonpatch.getValueByPointer(document, '/a/b');

// Validate
jsonpatch.validate(patch, document?);                  // returns JsonPatchError | undefined

// Diff & observe
jsonpatch.compare(objA, objB);                         // Operation[]
const observer = jsonpatch.observe(document);
jsonpatch.generate(observer);                          // Operation[] since last generate
jsonpatch.unobserve(document, observer);

// JSON-Pointer helpers
jsonpatch.escapePathComponent('a/b');                  // 'a~1b'
jsonpatch.unescapePathComponent('a~1b');               // 'a/b'

Support

If this package saves you time, you can support maintenance:

Ko-fi Bitcoin

Bitcoin (BTC): bc1q37557q5jpeaxqydzwvf3jgj7zhnfpn2td3q40q

Credits & license

MIT. Based on fast-json-patch by Joachim Wester.