# JavaScript diff libraries

JavaScript diff libraries compare two versions of text or data and describe the changes between them. A text diff reports the characters or lines inserted and deleted, while an object diff reports the paths whose values changed. These libraries produce the changes shown in code review views, test failure messages, and collaborative editors.

## Popularity

| Library | Monthly downloads | Stars | Last release | License |
| --- | --- | --- | --- | --- |
| [jsdiff](#jsdiff) | 735.9M | 9.2K | Apr 2026 | BSD-3-Clause |
| [jest-diff](#jest-diff) | 387.6M | 45.5K | Sep 2026 | MIT |
| [fast-diff](#fast-diff) | 178.1M | 715 | May 2023 | Apache-2.0 |
| [fast-json-patch](#fast-json-patch) | 47.1M | 2.0K | Mar 2022 | MIT |
| [diff-match-patch](#diff-match-patch) | 42.8M | 269 | May 2020 | Apache-2.0 |
| [just-diff](#just-diff) | 35.4M | 6.2K | Mar 2023 | MIT |
| [microdiff](#microdiff) | 21.7M | 3.9K | Aug 2026 | MIT |
| [deep-object-diff](#deep-object-diff) | 19.4M | 1.1K | Nov 2022 | MIT |

Downloads: npm, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

[jsdiff](#jsdiff) has the most monthly downloads in this comparison, at 735.9M.

## Capabilities

| Library | Text edit operations | Object field deltas | Applies patches |
| --- | --- | --- | --- |
| [jsdiff](#jsdiff) | Yes | No | Yes |
| [jest-diff](#jest-diff) | Yes | No | No |
| [fast-diff](#fast-diff) | Yes | No | No |
| [fast-json-patch](#fast-json-patch) | No | Yes | Yes |
| [diff-match-patch](#diff-match-patch) | Yes | No | Yes |
| [just-diff](#just-diff) | No | Yes | Via plugin |
| [microdiff](#microdiff) | No | Yes | No |
| [deep-object-diff](#deep-object-diff) | No | Yes | No |

## Libraries

### jsdiff

[GitHub](https://github.com/kpdecker/jsdiff) · [npm](https://www.npmjs.com/package/diff) · [Docs](https://github.com/kpdecker/jsdiff#readme)

Compares text tokens and creates or applies unified patches.

- Downloads / mo: 735.9M
- Stars: 9.2K
- Last release: 9.0.0
- License: BSD-3-Clause
- Capabilities: [From the jsdiff docs](https://github.com/kpdecker/jsdiff#readme)

**Strengths**

- **Compares different text units.** Choose character, word, or line comparisons.
- **Creates reversible unified patches.** Generate a structured patch and reverse it to undo changes.

**Watch out for**

- **Bounded comparisons can return undefined.** Handle an aborted comparison when using timeout or maxEditLength.
- **Patch context must still match.** Deleted lines and insertion boundaries must match even with fuzzFactor.

```sh
npm install diff@9.0.0
```

**google-gemini/gemini-cli** (108.9K stars)

[google-gemini/gemini-cli](https://github.com/google-gemini/gemini-cli) 

```typescript
export function getDiffStat(
  fileName: string,
  oldStr: string,
  aiStr: string,
  userStr: string,
): DiffStat {
  const getStats = (patch: Diff.StructuredPatch) => {
    let addedLines = 0;
    let removedLines = 0;
    let addedChars = 0;
    let removedChars = 0;

    patch.hunks.forEach((hunk: Diff.StructuredPatchHunk) => {
      hunk.lines.forEach((line: string) => {
        if (line.startsWith('+')) {
          addedLines++;
          addedChars += line.length - 1;
        } else if (line.startsWith('-')) {
          removedLines++;
          removedChars += line.length - 1;
        }
      });
    });
    return { addedLines, removedLines, addedChars, removedChars };
  };

  const modelPatch = Diff.structuredPatch(
    fileName,
    fileName,
    oldStr,
    aiStr,
    'Current',
    'Proposed',
    DEFAULT_STRUCTURED_PATCH_OPTS,
  );
  const modelStats = getStats(modelPatch);

  const userPatch = Diff.structuredPatch(
    fileName,
    fileName,
    aiStr,
    userStr,
    'Proposed',
    'User',
    DEFAULT_STRUCTURED_PATCH_OPTS,
  );
  const userStats = getStats(userPatch);

  return {
    model_added_lines: modelStats.addedLines,
    model_removed_lines: modelStats.removedLines,
    model_added_chars: modelStats.addedChars,
    model_removed_chars: modelStats.removedChars,
    user_added_lines: userStats.addedLines,
    user_removed_lines: userStats.removedLines,
    user_added_chars: userStats.addedChars,
    user_removed_chars: userStats.removedChars,
  };
}

```

[packages/core/src/tools/diffOptions.ts](https://github.com/google-gemini/gemini-cli/blob/4fa64e71b9b4e1bb65a86cc2863574f561b82340/packages/core/src/tools/diffOptions.ts#L20-L78) · [More projects using jsdiff →](https://dashboard.exa.ai/playground/search?q=Projects%20using%20diff%20to%20compare%20revisions%20and%20apply%20patches&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```typescript
const { diffChars } = require('diff');

console.log(diffChars('hello', 'hello world'));

```

From [node_example.js](https://github.com/kpdecker/jsdiff/blob/master/README.md)

### jest-diff

[GitHub](https://github.com/jestjs/jest) · [npm](https://www.npmjs.com/package/jest-diff) · [Docs](https://github.com/jestjs/jest#readme)

Formats the differences between two values as text for people to review.

- Downloads / mo: 387.6M
- Stars: 45.5K
- Last release: 30.5.2
- License: MIT
- Capabilities: [From the jest-diff docs](https://github.com/jestjs/jest#readme)

**Strengths**

- **Diffs any two values.** Pass two values of any type to get a formatted difference string.
- **Customizes annotations and colors.** Set annotations, colors, and context lines through DiffOptions.

```sh
npm install jest-diff@30.5.2
```

**phenomnomnominal/betterer** (638 stars)

[phenomnomnominal/betterer](https://github.com/phenomnomnominal/betterer) 

```javascript
export function diffStrings__(a: string, b: string, diffOptions: DiffOptions): string {
  // jest-diff recommends using `diffLinesUnified` if string lengths are above 20,000 for performance
  if (a.length > 20_000 || b.length > 20_000) {
    return diffLinesUnified(a.split('\n'), b.split('\n'), diffOptions);
  }

  return diffStringsUnified(a, b, diffOptions);
}

```

[packages/logger/src/diff.ts](https://github.com/phenomnomnominal/betterer/blob/69a83c14975b6ef2e4e42736e686ffba0f28895f/packages/logger/src/diff.ts#L19-L26) · [More projects using jest-diff →](https://dashboard.exa.ai/playground/search?q=jest-diff%20GitHub%20projects)

**Quickstart**

```javascript
const { diff } = require('jest-diff');

console.log(diff({ count: 1 }, { count: 2 }));

```

From [README.md](https://registry.npmjs.org/jest-diff/latest)

### fast-diff

[GitHub](https://github.com/jhchen/fast-diff) · [npm](https://www.npmjs.com/package/fast-diff) · [Docs](https://github.com/jhchen/fast-diff#readme)

Computes a text diff between two strings.

- Downloads / mo: 178.1M
- Stars: 715
- Last release: 1.3.0
- License: Apache-2.0
- Capabilities: [From the fast-diff docs](https://github.com/jhchen/fast-diff#readme)

**Strengths**

- **Returns edit tuples.** Read each change as a delete, insert, or equal tuple.
- **Respects the cursor position.** Pass a cursor position to place an ambiguous edit where the user typed.

**Watch out for**

- **No match or patch functions.** Patching and fuzzy matching stay in diff-match-patch.

```sh
npm install fast-diff@1.3.0
```

**CherryHQ/cherry-studio** (53.7K stars)

[CherryHQ/cherry-studio](https://github.com/CherryHQ/cherry-studio) 

```javascript
export function prepareCodeChanges(oldCode: string, newCode: string) {
  const diffResult = diff(oldCode, newCode)

  const changes: { from: number; to: number; insert: string }[] = []
  let offset = 0

  // operation: 1=insert, -1=delete, 0=equal
  for (const [operation, text] of diffResult) {
    if (operation === 1) {
      changes.push({
        from: offset,
        to: offset,
        insert: text
      })
    } else if (operation === -1) {
      changes.push({
        from: offset,
        to: offset + text.length,
        insert: ''
      })
      offset += text.length
    } else {
      offset += text.length
    }
  }

  return changes
}

```

[packages/ui/src/components/composites/code-editor/utils.ts](https://github.com/CherryHQ/cherry-studio/blob/68ba05ba5f362e5f34501659be223441a67a2976/packages/ui/src/components/composites/code-editor/utils.ts#L23-L50) · [More projects using fast-diff →](https://dashboard.exa.ai/playground/search?q=fast-diff%20GitHub%20projects)

**Quickstart**

```javascript
const diff = require('fast-diff');

console.log(diff('hello', 'hello world'));

```

From [README.md](https://registry.npmjs.org/fast-diff/latest)

### fast-json-patch

[GitHub](https://github.com/Starcounter-Jack/JSON-Patch) · [npm](https://www.npmjs.com/package/fast-json-patch)

Generates, validates, and applies JSON Patch operations on object trees.

- Downloads / mo: 47.1M
- Stars: 2.0K
- Last release: 3.1.1
- License: MIT
- Capabilities: [From the fast-json-patch docs](https://github.com/Starcounter-Jack/JSON-Patch)

**Strengths**

- **Tracks changes to observed objects.** Observe an object and generate the pending patch operations.
- **Validates patches against a document.** Validate operation sequences against the target object tree.

**Watch out for**

- **Patch application mutates by default.** Disable mutateDocument or clone the document before applying changes.
- **Undefined values change meaning.** Undefined object properties disappear; undefined array entries become null.

```sh
npm install fast-json-patch@3.1.1
```

**Unleash/unleash** (14.3K stars)

[Unleash/unleash](https://github.com/Unleash/unleash) 

```typescript
async patchFeature(
    project: string,
    featureName: string,
    createdBy: string,
    operations: Operation[],
): Promise<FeatureToggle> {
    const featureToggle = await this.getFeatureMetadata(featureName);

    if (operations.some((op) => op.path.indexOf('/variants') >= 0)) {
        throw new OperationDeniedError(
            `Changing variants is done via PATCH operation to /api/admin/projects/:project/features/:feature/variants`,
        );
    }
    const { newDocument } = applyPatch(
        deepClone(featureToggle),
        operations,
    );

    const updated = await this.updateFeatureToggle(
        project,
        newDocument,
        createdBy,
    );

    if (featureToggle.stale !== newDocument.stale) {
        const tags = await this.tagStore.getAllTagsForFeature(featureName);

        await this.eventStore.store(
            new FeatureStaleEvent({
                stale: newDocument.stale,
                project,
                featureName,
                createdBy,
                tags,
            }),
        );
    }

    return updated;
}

```

[src/lib/services/feature-toggle-service.ts](https://github.com/Unleash/unleash/blob/2b59a4219a049e87984a99e1dde25d402f74a064/src/lib/services/feature-toggle-service.ts#L143-L182) · [More projects using fast-json-patch →](https://dashboard.exa.ai/playground/search?q=Projects%20using%20fast-json-patch%20to%20compare%20revisions%20and%20apply%20patches&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```typescript
const { applyPatch } = require('fast-json-patch');

const document = { name: 'Ada' };
const patch = [{ op: 'replace', path: '/name', value: 'Grace' }];
const result = applyPatch(document, patch);
console.log(result.newDocument);

```

From [README.md](https://registry.npmjs.org/fast-json-patch/latest)

### diff-match-patch

[GitHub](https://github.com/JackuB/diff-match-patch) · [npm](https://www.npmjs.com/package/diff-match-patch) · [Docs](https://github.com/JackuB/diff-match-patch#readme)

Diffs text, finds approximate matches, and applies text patches.

- Downloads / mo: 42.8M
- Stars: 269
- Last release: 1.0.5
- License: Apache-2.0
- Capabilities: [From the diff-match-patch docs](https://github.com/JackuB/diff-match-patch#readme)

**Strengths**

- **Cleans up readable text differences.** Semantic cleanup groups coincidental matches into more understandable edits.
- **Reports individual patch outcomes.** patch_apply returns changed text and success flags.

**Watch out for**

- **Timed diffs can be nonoptimal.** A timeout returns a valid difference without guaranteeing the smallest edit.
- **Large patches complicate success tracking.** Internal splitting can make result flags outnumber the original patches.

```sh
npm install diff-match-patch@1.0.5
```

**Quickstart**

```typescript
import DiffMatchPatch from 'diff-match-patch';
const dmp = new DiffMatchPatch();

console.log(dmp.diff_main('hello', 'hello world'));

```

From [README.md](https://github.com/JackuB/diff-match-patch/blob/master/README.md) · [Find projects using diff-match-patch →](https://dashboard.exa.ai/playground/search?q=Projects%20using%20diff-match-patch%20to%20compare%20revisions%20and%20apply%20patches&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

### just-diff

[GitHub](https://github.com/angus-c/just) · [npm](https://www.npmjs.com/package/just-diff) · [Docs](https://github.com/angus-c/just#readme)

Returns the differences between two objects, with an option to format them as JSON Patch.

- Downloads / mo: 35.4M
- Stars: 6.2K
- Last release: 6.0.2
- License: MIT
- Capabilities: [From the just-diff docs](https://github.com/angus-c/just#readme)

**Strengths**

- **Formats changes as JSON Patch.** Pass jsonPatchPathConverter to get standard JSON Patch paths.

```sh
npm install just-diff@6.0.2
```

**lobehub/lobe-cli-toolbox** (421 stars)

[lobehub/lobe-cli-toolbox](https://github.com/lobehub/lobe-cli-toolbox) 

```javascript
export const diff = (
  entry: LocaleObj,
  target: LocaleObj,
  config?: Pick<I18nConfig, 'keyStyle'>,
) => {
  const keyStyle = config?.keyStyle ?? 'nested';
  const diffResult = justDiff(target, entry);
  const add = diffResult.filter((item) => item.op === 'add');
  const remove = diffResult.filter((item) => item.op === 'remove');

  const cloneTarget = cloneDeep(target);
  const extra: LocaleObj = {};

  for (const item of remove) {
    const path = resolveDiffPath(target, item.path as DiffPath, keyStyle);
    unset(cloneTarget, path);
  }

  for (const item of add) {
    const path = resolveDiffPath(entry, item.path as DiffPath, keyStyle);
    // Use custom setByPath to preserve numeric string keys as object keys
    const pathArray = Array.isArray(path) ? path : [path];
    setByPath(extra, pathArray, item.value);
  }

  return {
    add,
    entry: extra,
    remove,
    target: cloneTarget,
  };
};

```

[packages/lobe-i18n/src/utils/diffJson.ts](https://github.com/lobehub/lobe-cli-toolbox/blob/f8a881752bfd13fc201e114de7909c38fd1a6df6/packages/lobe-i18n/src/utils/diffJson.ts#L38-L69) · [More projects using just-diff →](https://dashboard.exa.ai/playground/search?q=just-diff%20GitHub%20projects)

**Quickstart**

```javascript
const { diff } = require('just-diff');

console.log(diff({ count: 1 }, { count: 2 }));

```

From [README.md](https://registry.npmjs.org/just-diff/latest)

### microdiff

[GitHub](https://github.com/AsyncBanana/microdiff) · [npm](https://www.npmjs.com/package/microdiff) · [Docs](https://github.com/AsyncBanana/microdiff#readme)

Compares objects and arrays deeply with no dependencies.

- Downloads / mo: 21.7M
- Stars: 3.9K
- Last release: 1.6.0
- License: MIT
- Capabilities: [From the microdiff docs](https://github.com/AsyncBanana/microdiff#readme)

**Strengths**

- **Returns typed change records.** Read each change as CREATE, REMOVE, or CHANGE with its path.
- **Compares dates and regular expressions.** Compare Date and RegExp values by their content.

```sh
npm install microdiff@1.6.0
```

**Quickstart**

```javascript
import diff from 'microdiff';

console.log(diff({ count: 1 }, { count: 2 }));

```

From [README.md](https://registry.npmjs.org/microdiff/latest) · [Find projects using microdiff →](https://dashboard.exa.ai/playground/search?q=microdiff%20GitHub%20projects)

### deep-object-diff

[GitHub](https://github.com/mattphillips/deep-object-diff) · [npm](https://www.npmjs.com/package/deep-object-diff) · [Docs](https://github.com/mattphillips/deep-object-diff#readme)

Compares two objects deeply, including nested arrays and objects, and returns the difference.

- Downloads / mo: 19.4M
- Stars: 1.1K
- Last release: 1.1.9
- License: MIT
- Capabilities: [From the deep-object-diff docs](https://github.com/mattphillips/deep-object-diff#readme)

**Strengths**

- **Splits added, deleted, and updated values.** Call detailedDiff to get added, deleted, and updated values separately.

```sh
npm install deep-object-diff@1.1.9
```

**storybookjs/storybook** (91.6K stars)

[storybookjs/storybook](https://github.com/storybookjs/storybook) 

```javascript
export const ensure = (input: ThemeVars): StorybookTheme => {
  if (!input) {
    return convert(light);
  }
  const missing = deletedDiff(light, input);
  if (Object.keys(missing).length) {
    logger.warn(
      dedent`
          Your theme is missing properties, you should update your theme!

          theme-data missing:
        `,
      missing
    );
  }

  return convert(input);
};

```

[code/core/src/theming/ensure.ts](https://github.com/storybookjs/storybook/blob/0cdcdc9c2552760b66339943dfd83a2de587c269/code/core/src/theming/ensure.ts#L10-L27) · [More projects using deep-object-diff →](https://dashboard.exa.ai/playground/search?q=deep-object-diff%20GitHub%20projects)

**Quickstart**

```javascript
const { diff } = require('deep-object-diff');

console.log(diff({ count: 1 }, { count: 2 }));

```

From [README.md](https://registry.npmjs.org/deep-object-diff/latest)

## FAQ

### What is jsdiff?

[jsdiff](#jsdiff), published on npm as diff, compares text by characters, words, or lines and creates or applies unified patches.

### What is fast-json-patch?

[fast-json-patch](#fast-json-patch) implements JSON Patch, a format that describes changes to a JSON document as a list of operations. It can also observe an object and generate the operations for its changes.

### How do I compare two objects in JavaScript?

[Microdiff](#microdiff), [just-diff](#just-diff), and [deep-object-diff](#deep-object-diff) compare two objects and report the changed paths. [fast-json-patch](#fast-json-patch) returns the same changes as JSON Patch operations.

### Which JavaScript diff library fits each kind of change?

jsdiff compares text tokens and supports unified patches. fast-json-patch compares objects and generates operations from observations. diff-match-patch returns text differences and applies text patches.

### Does fast-json-patch modify the original document?

applyPatch mutates by default; mutateDocument controls whether it clones first.

### Does jsdiff diffJson produce structural path operations?

diffJson first sorts object properties, serializes them as pretty JSON, and compares the lines.

## How this page was built

Data checked Nov 20, 2026.

Reproduce it with the Exa API:

```json
{
  "endpoint": "/search",
  "body": {
    "query": "Best JavaScript diff libraries jsdiff jsondiffpatch fast-json-patch diff-match-patch code examples",
    "numResults": 5
  }
}
```

Docs: https://exa.ai/docs/reference/search
