TextDiff
MMO.git · 1 symbol · generated 27 Oct 2026
TextDiff
TextDiff.js:13The diff of two texts, without git: lines with Myers' algorithm, cut into hunks shaped as DiffController's ({oldStart, oldCount, newStart, newCount, context, lines: [{type, old, new, text}]}), so that what is not in a repository (a page's two revisions...) is drawn like a commit. And the words that changed inside a line.
- Namespace
MMO.git
Index
| Lines(text) static | ||
| Edits(a, b) static | The shortest edit script between two lists (Myers, O((N+M)D)). | |
| Middle(a, b, x0, x1, y0, y1) static | [internal] Myers' search between a[x0..x1) and b[y0..y1), walked back from its trace | |
| hunks(oldText, newText, context) static | The hunks of a diff, with $context unchanged lines around each change, a removal before the additions it is replaced by (as git writes them). | |
| Flush(hunk) static | [internal] move a hunk's pending removals then additions into its lines | |
| Before(lines, side) static | [internal] @return {number} the line before a hunk that has none on $side | |
| Words(text) static | The words of a line: runs of letters and digits, of spaces, and each other character alone. | |
| words(oldText, newText) static | The parts of two lines that differ, as character ranges -- what is darker in a modified line. |
Methods8
Lines(text)
staticTextDiff.js:18| text | ?string | |
| returns | Array<string> | its lines, without their ends; a final end of line makes no extra empty line |
Edits(a, b)
staticTextDiff.js:31The shortest edit script between two lists (Myers, O((N+M)D)).
| a | Array<string> | |
| b | Array<string> | |
| returns | Array<Array> | [type, indexInA, indexInB] in order: ' ' both, '-' a only, '+' b only (the absent index is null) |
Middle(a, b, x0, x1, y0, y1)
staticTextDiff.js:48[internal] Myers' search between a[x0..x1) and b[y0..y1), walked back from its trace
| a | ||
| b | ||
| x0 | ||
| x1 | ||
| y0 | ||
| y1 |
hunks(oldText, newText, context)
staticTextDiff.js:93The hunks of a diff, with $context unchanged lines around each change, a removal before the additions it is replaced by (as git writes them).
| oldText | ?string | |
| newText | ?string | |
| context = 3 | number | |
| returns | Array<Object> |
Flush(hunk)
staticTextDiff.js:134[internal] move a hunk's pending removals then additions into its lines
| hunk |
Before(lines, side)
staticTextDiff.js:141[internal] @return {number} the line before a hunk that has none on $side
| lines | ||
| side |
Words(text)
staticTextDiff.js:152The words of a line: runs of letters and digits, of spaces, and each other character alone.
| text | string | |
| returns | Array<string> |
words(oldText, newText)
staticTextDiff.js:163The parts of two lines that differ, as character ranges -- what is darker in a modified line.
| oldText | string | |
| newText | string | |
| returns | ?{old: Array<Array<number>>, new: Array<Array<number>> | } [start, end) ranges on each side; null when the lines have too little in common for it to mean anything |