{"id":10869,"library":"fast-diff","title":"Fast Diff","description":"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.","status":"maintenance","version":"1.3.0","language":"javascript","source_language":"en","source_url":"https://github.com/jhchen/fast-diff","tags":["javascript","diff","typescript"],"install":[{"cmd":"npm install fast-diff","lang":"bash","label":"npm"},{"cmd":"yarn add fast-diff","lang":"bash","label":"yarn"},{"cmd":"pnpm add fast-diff","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"While CommonJS `require` works, ESM `import` is the modern standard, especially in TypeScript and browser-targeted projects. `fast-diff` exports a default function.","wrong":"const diff = require('fast-diff');","symbol":"diff","correct":"import diff from 'fast-diff';"},{"note":"Constants are exported as named exports. Ensure you use named imports for these values in an ESM context.","wrong":"const { INSERT, EQUAL, DELETE } = require('fast-diff');","symbol":"INSERT, EQUAL, DELETE","correct":"import { INSERT, EQUAL, DELETE } from 'fast-diff';"}],"quickstart":{"code":"import diff from 'fast-diff';\n\nconst good = 'Good dog';\nconst bad = 'Bad dog';\n\nconst result = diff(good, bad);\n// result: [[-1, \"Goo\"], [1, \"Ba\"], [0, \"d dog\"]]\n\n// Respect suggested edit location (cursor position), added in v1.1\nconst resultWithCursor = diff('aaa', 'aaaa', 1);\n// resultWithCursor: [[0, \"a\"], [1, \"a\"], [0, \"aa\"]]\n\nimport { INSERT, EQUAL, DELETE } from 'fast-diff';\n\nconsole.log(`Insert code: ${INSERT}`); // Expected: 1\nconsole.log(`Equal code: ${EQUAL}`);   // Expected: 0\nconsole.log(`Delete code: ${DELETE}`); // Expected: -1","lang":"typescript","description":"Demonstrates basic string diffing, including the optional cursor position parameter, and usage of the exported constants."},"warnings":[{"fix":"For matching or patching, consider using the full `diff-match-patch` library or another diff/patch specific package.","message":"This 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"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.","message":"The 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.","severity":"gotcha","affected_versions":"<=1.3.0"},{"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.","message":"Older 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.","severity":"gotcha","affected_versions":"<=1.3.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Use a default import: `import diff from 'fast-diff';`. If you are in a CommonJS module, use `const diff = require('fast-diff');`.","cause":"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.","error":"TypeError: diff is not a function"},{"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.","cause":"Attempting to access `match` or `patch` functions, which were explicitly removed from this simplified `diff-match-patch` port.","error":"Property 'match' does not exist on type '(...args: any[]) => DiffResult[]'."}],"ecosystem":"npm"}