
Text diff
Compare two texts and show a unified diff by line, word or character. Runs entirely on your device, nothing is uploaded.
Text diff compares two texts and prints their differences by line, word, or character, chosen with the granularity option. With one file dropped, the compareTo text stands in as the second side; with two files, they compare directly. The diff runs the Myers shortest-edit-script algorithm. Combined inputs over 60,000 tokens are refused, since cost grows with their size.
Questions
What algorithm builds the diff?
The Myers shortest-edit-script algorithm, which finds a minimal sequence of insertions and deletions turning one text into the other; it is the same class of algorithm behind most line-based diff tools.
What is the difference between line, word and character granularity?
Line granularity produces a classic unified diff with @@ hunk headers and 3 lines of context, merging adjacent changed regions. Word and character granularity instead produce one inline result using [-removed-] and {+added+} markers around consecutive runs of the same change type, with no separate hunks.
What happens with only one file and no compareTo text?
It refuses with "text-diff needs a second file, or a compareTo text to diff the single input against", since there is nothing to compare the one file to.
Is there a size limit on what it can diff?
Yes. Once the two tokenized inputs together exceed 60,000 tokens, whether lines, words or characters depending on the granularity, it refuses, naming the exact combined count, since the algorithm's cost grows with input size.
What does it report when the two texts are identical?
For line granularity it prints "[name] and [name] are identical."; for word or character granularity it prints "Identical." instead of an empty diff.