# ai/diff

> Word-level Myers diff: text is split into words, whitespace runs and punctuation, and the shortest edit script between the two token lists is found in O(ND).

Word-level Myers diff (F-51): text is split into words, whitespace runs and punctuation, and the shortest edit script between the two token lists is found in O(ND).

```js
import { diffWords, hunks } from 'verbal-editor/ai/diff';
```

| JS gzip | CSS gzip |
| --- | --- |
| 0.65 KB | — |

See it live on [AI review](#/examples/ai) — every example page on the landing is editable.

## Acceptance

| Feature | Acceptance | Budget |
| --- | --- | --- |
| F-51 · Diff rendering | Insertions and deletions visually distinct; original text remains readable and selectable | ≤ 2KB |

## API

### `diffWords(a, b)`

Shortest edit script from `a` to `b`; changes separated only by whitespace form one hunk.

### `hunks(parts)`

Hunks of a diff: where each starts in the old text, what it removes and what it inserts.
