diff-match-patch-typescript is a direct, strongly-typed TypeScript port of Google's `diff-match-patch` library. It provides robust algorithms for computing differences between two texts, finding approximate string matches, and applying patches. This package, currently at version 1.1.3, aims for full functional parity with the original Java/JavaScript implementation, ensuring that developers leveraging TypeScript benefit from type safety and modern tooling while utilizing a widely-used and proven diffing solution. It's actively maintained with continuous integration, making it a reliable choice for text manipulation tasks where precise diffing, matching, and patching are required. Its core differentiators include its faithfulness to the original algorithm and its full TypeScript support.
npm install diff-match-patch-typescriptVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates the core functionalities: `diff_main` for comparing texts, `match_main` for finding a substring, and `patch_make`/`patch_apply` for creating and applying changes.
Review the `DiffMatchPatch` class configuration options (e.g., `dmp.diffTimeout = 0;` for infinite timeout) and adjust them based on your specific text characteristics and performance requirements.
Familiarize yourself with the original `diff-match-patch` documentation if you encounter unexpected results, as the underlying algorithms and their tuning parameters are identical. Consider profiling performance for very large inputs.
For most common text diffing tasks, this library remains robust. However, for highly specialized scenarios (e.g., real-time collaborative editing with granular character tracking), research newer algorithms like Myers diff or Longest Common Subsequence variants.
Ensure you use `import { DiffMatchPatch } from 'diff-match-patch-typescript';` and then create an instance with `const dmp = new DiffMatchPatch();` before attempting to call methods like `dmp.diff_main`.Add `DiffOperation` to your import statement: `import { DiffMatchPatch, DiffOperation } from 'diff-match-patch-typescript';`.Always use the `DiffOperation` enum for clarity and type safety: `if (op[0] === DiffOperation.DIFF_EQUAL) { ... }` instead of `if (op[0] === 0) { ... }`.No dependency data recorded yet.