Skip to main content
Home

Built and signed on GitHub Actions

Modern JS/TS and Unicode-friendly version of diff-match-patch.

This package works with Node.js, Deno, Bun, BrowsersIt is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
100%
Published
a year ago (0.1.1)
class Differ

A class for performing diffs. Wraps the DiffMatchPatch class from the original library with more ergonomic and Unicode-friendly methods.

Constructors

new
Differ(config?: Partial<DiffMatchPatchConfig>)

Methods

Cleanup function to increase human readability by factoring out commonalities which are likely to be coincidental.

diff(
before: string,
after: string,
options?: Partial<DiffOptions>,
): Diff[]

Diff two strings. Fully Unicode-aware by default.

Pass a segmenter option to customize the units of calculation for the diff (char, line, word, grapheme, sentence, etc).

diffCodeUnits(
before: string,
after: string,
options?: Pick<Partial<DiffOptions>, "checkLines">,
): Diff[]

Diff two strings by UTF-16 code unit. May not work as expected for non-BMP characters. This is simply a wrapper around diff-match-patch's diff_main, which may be a preferable way to create char diffs compared to diff where full Unicode support is not critical and in performance-sensitive scenarios.

diffWithin(
diffs: Diff[],
options?: Partial<DiffOptions>,
): Diff[][]

Convert an less-granular array of diffs to a 2d array of more-granular diffs-within-diffs.

For example, get word diffs within line diffs.

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@clearlylocal/diff-match-patch-unicode

Import symbol

import { Differ } from "@clearlylocal/diff-match-patch-unicode/Differ";
or

Import directly with a jsr specifier

import { Differ } from "jsr:@clearlylocal/diff-match-patch-unicode/Differ";

Add Package

pnpm i jsr:@clearlylocal/diff-match-patch-unicode
or (using pnpm 10.8 or older)
pnpm dlx jsr add @clearlylocal/diff-match-patch-unicode

Import symbol

import { Differ } from "@clearlylocal/diff-match-patch-unicode/Differ";

Add Package

yarn add jsr:@clearlylocal/diff-match-patch-unicode
or (using Yarn 4.8 or older)
yarn dlx jsr add @clearlylocal/diff-match-patch-unicode

Import symbol

import { Differ } from "@clearlylocal/diff-match-patch-unicode/Differ";

Add Package

vlt install jsr:@clearlylocal/diff-match-patch-unicode

Import symbol

import { Differ } from "@clearlylocal/diff-match-patch-unicode/Differ";

Add Package

npx jsr add @clearlylocal/diff-match-patch-unicode

Import symbol

import { Differ } from "@clearlylocal/diff-match-patch-unicode/Differ";

Add Package

bunx jsr add @clearlylocal/diff-match-patch-unicode

Import symbol

import { Differ } from "@clearlylocal/diff-match-patch-unicode/Differ";