MMOframework
Why AI Playground Libraries Documentation Search Agency
FR EN
Index

TextDiff

MMO.git · 1 symbol · generated 27 Oct 2026

class

TextDiff

TextDiff.js:13

The 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.

class MMO.git.TextDiff
Namespace
MMO.git
const hunks = MMO.git.TextDiff.hunks('a\nb\nc\n', 'a\nB\nc\n'); //[{oldStart: 1, oldCount: 3, newStart: 1, newCount: 3, context: '', lines: [{type: ' ', old: 1, new: 1, text: 'a'}, {type: '-', ...}, ...]}]

Index

Lines(text) static
Edits(a, b) staticThe 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) staticThe 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) staticThe words of a line: runs of letters and digits, of spaces, and each other character alone.
words(oldText, newText) staticThe parts of two lines that differ, as character ranges -- what is darker in a modified line.

Methods8

Lines(text)

staticTextDiff.js:18
static Lines(text)
text?string
returnsArray<string>its lines, without their ends; a final end of line makes no extra empty line

Edits(a, b)

staticTextDiff.js:31

The shortest edit script between two lists (Myers, O((N+M)D)).

static Edits(a, b)
aArray<string>
bArray<string>
returnsArray<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

static Middle(a, b, x0, x1, y0, y1)
a
b
x0
x1
y0
y1

hunks(oldText, newText, context)

staticTextDiff.js:93

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).

static hunks(oldText, newText, context = 3)
oldText?string
newText?string
context = 3number
returnsArray<Object>

Flush(hunk)

staticTextDiff.js:134

[internal] move a hunk's pending removals then additions into its lines

static Flush(hunk)
hunk

Before(lines, side)

staticTextDiff.js:141

[internal] @return {number} the line before a hunk that has none on $side

static Before(lines, side)
lines
side

Words(text)

staticTextDiff.js:152

The words of a line: runs of letters and digits, of spaces, and each other character alone.

static Words(text)
textstring
returnsArray<string>

words(oldText, newText)

staticTextDiff.js:163

The parts of two lines that differ, as character ranges -- what is darker in a modified line.

static words(oldText, newText)
oldTextstring
newTextstring
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