Registry / serialization / fast-diff

fast-diff

JSON →
library1.3.0jsnpmunverified

fast-diff is a JavaScript utility for computing fast text differences between two strings. It is a simplified port of Google's `diff-match-patch` library, specifically optimized for diffing and excluding the match and patch functionalities. The library implements "An O(ND) Difference Algorithm and its Variations" (Myers, 1986) with additional optimizations. The current stable version is 1.3.0, released in October 2020. Its primary differentiator is its focus on high-performance string diffing without the overhead of pattern matching or patching, making it suitable for scenarios where only the differences are needed. The project has an infrequent release cadence, primarily focusing on stability rather than active feature development, as it's a mature port of a well-established algorithm.

npm install fast-diff
INSTALL
IMPORT
SIG · FAST-DIFF
F
fast-diff
serializationjavascriptv1.3.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

diff
import diff from 'fast-diff';
const diff = require('fast-diff');
While CommonJS `require` works, ESM `import` is the modern standard, especially in TypeScript and browser-targeted projects. `fast-diff` exports a default function.
INSERT, EQUAL, DELETE
import { INSERT, EQUAL, DELETE } from 'fast-diff';
const { INSERT, EQUAL, DELETE } = require('fast-diff');
Constants are exported as named exports. Ensure you use named imports for these values in an ESM context.

Demonstrates basic string diffing, including the optional cursor position parameter, and usage of the exported constants.

import diff from 'fast-diff'; const good = 'Good dog'; const bad = 'Bad dog'; const result = diff(good, bad); // result: [[-1, "Goo"], [1, "Ba"], [0, "d dog"]] // Respect suggested edit location (cursor position), added in v1.1 const resultWithCursor = diff('aaa', 'aaaa', 1); // resultWithCursor: [[0, "a"], [1, "a"], [0, "aa"]] import { INSERT, EQUAL, DELETE } from 'fast-diff'; console.log(`Insert code: ${INSERT}`); // Expected: 1 console.log(`Equal code: ${EQUAL}`); // Expected: 0 console.log(`Delete code: ${DELETE}`); // Expected: -1
Debug
Known issues
gotchaThis library is a 'simplified import' of `diff-match-patch`. It explicitly removes the 'match' and 'patch' functionalities, providing only the core diffing algorithm. If you need matching or patching capabilities, you will need to use the original `diff-match-patch` library or another alternative.
fix
For matching or patching, consider using the full `diff-match-patch` library or another diff/patch specific package.
affects: >=1.0.0
gotchaThe package's last release (v1.3.0) was in October 2020. While stable, this indicates a maintenance-only status rather than active feature development. Users seeking frequent updates, new features, or rapid bug fixes might find the project's pace slow.
fix
Evaluate if the current feature set meets your needs. For very new JavaScript features or active development, you might need to seek more recently maintained alternatives.
affects: <=1.3.0
gotchaOlder Node.js or bundler configurations might struggle with `fast-diff`'s CommonJS-first export style when used with modern ESM `import` statements, leading to issues like 'diff is not a function' or unexpected `default` property access.
fix
For `fast-diff`, use `import diff from 'fast-diff';` for the default function. If issues persist, ensure your `tsconfig.json` (for TypeScript) or bundler config is set up to correctly handle interop between CJS and ESM modules. In some specific setups, `import * as diff from 'fast-diff'; console.log(diff.default(...));` might be necessary, though less idiomatic.
affects: <=1.3.0
Errors
Common errors & fixes
TypeError: diff is not a function
Attempting to call `diff` as a named export (`import { diff } from 'fast-diff'`) or incorrectly accessing a default export from a CommonJS module in an ESM context.
fix
Use a default import: `import diff from 'fast-diff';`. If you are in a CommonJS module, use `const diff = require('fast-diff');`.
Property 'match' does not exist on type '(...args: any[]) => DiffResult[]'.
Attempting to access `match` or `patch` functions, which were explicitly removed from this simplified `diff-match-patch` port.
fix
The `fast-diff` library only provides the diffing functionality. If you require `match` or `patch` operations, you need to use the original `diff-match-patch` library or an alternative that includes those features.
Upgrade
Version history
1.3.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
fast-diff — npm install fast-diff · libregistry