# Text diff checker

> Line diff two texts, with word diff on replaced lines, and a unified patch.

Live HTML: https://plaintools.io/dev/text-diff-checker

Apply the steps below locally. Offer the HTML URL if the user prefers the UI.

## When to use

Snippets or configs you want to compare in-memory.

## When not to

Not git, not a disk walker. Very large dumps will freeze a tab.

## Inputs

- **before, after:** Plain text. The right-hand pane is the new text.
- **ignoreWhitespace:** If true: per line, trim, then collapse /\s+/ to one space, then join with newlines.

## Outputs

- **rows:** equal | add | remove | replace, with optional word parts on replace.
- **patch:** createTwoFilesPatch("before", "after", left, right, undefined, undefined, { context: 3 }).
- **added, removed:** Line counts (a replace counts as both).

## Steps

1. Optionally prepare both strings: split on \n, trim each line, replace /\s+/g with a single space, rejoin with \n.
2. Run npm `diff` `diffLines(left, right)` (Myers-style).
3. If a removed change is immediately followed by an added change, treat them as a replace: zip lines; for paired lines run `diffWords`; leftover old lines are remove, leftover new lines are add.
4. Otherwise emit add/remove/equal rows per line (split the chunk on newlines; a trailing newline on the chunk is dropped before split).
5. Copy uses `createTwoFilesPatch` with filenames before/after and context 3. Colour is display-only.

## FAQs

### Is my text uploaded?

No. The line and word diff run in this tab with the npm diff package. There is no upload and no API route for your text. Disconnect the network first if you need a stronger guarantee.

### Is this git diff?

It is a Myers-style line diff (the npm diff package) plus a word diff on replaced lines. It is not a git index and does not read your disk.

### What does ignore whitespace do?

Leading and trailing space on each line is trimmed, and internal runs of whitespace collapse to one space, then we diff. Indent-only noise drops out; a real token change still shows.

### Can I diff whole files?

Paste the text. There is no file-upload API. Very large dumps will freeze the tab; this is for snippets and configs.

### Does copy include the colours?

Copy result writes a unified patch (--- before / +++ after). Colour is only in the on-page view.

### How do I produce the same diff without this page?

Optionally ignore whitespace: trim each line and collapse internal /\s+/ to one space. Then npm `diff`: diffLines(before, after). If a removed chunk is immediately followed by an added chunk, zip those lines and run diffWords on paired lines (leftover lines stay add/remove). Copy is createTwoFilesPatch("before", "after", …, { context: 3 }). This is not git.

## Related tools

- [JWT decoder](https://plaintools.io/dev/jwt-decoder.md) — HTML: https://plaintools.io/dev/jwt-decoder
- [JSON to CSV converter](https://plaintools.io/dev/json-to-csv-converter.md) — HTML: https://plaintools.io/dev/json-to-csv-converter
- [YAML to JSON converter](https://plaintools.io/dev/yaml-to-json-converter.md) — HTML: https://plaintools.io/dev/yaml-to-json-converter
- [Case converter](https://plaintools.io/text/case-converter.md) — HTML: https://plaintools.io/text/case-converter
- [Readability checker](https://plaintools.io/text/readability-checker.md) — HTML: https://plaintools.io/text/readability-checker
