Text word diff
text-word-diff · version 1.0.0 · Text · free, no key needed
Diff two texts as whitespace versus non-whitespace word tokens.
Use when you need to: text word diff · word token text diff · diff texts by words.
Supported
- text word diff
- word token text diff
- diff texts by words
Not supported
- locale word break
- Unicode UAX #29 word boundaries
- unicode normalization
- fuzzy matching
- patience/histogram diff
- treat U+00A0 as whitespace
- filesystem access
Behavior
- left and right are tokenized with splitWords: maximal runs of ASCII space, tab, CR, or LF versus maximal runs of everything else.
- U+00A0 is a word character, not whitespace. Empty text yields no tokens.
- The Myers SES uses string === equality; when D-paths tie, the library prefers delete from the left.
- ops is the per-token SES. keep includes left_index and right_index; delete includes left_index; insert includes right_index.
- keeps, deletions, and insertions count those op kinds. Adjacent keeps are not collapsed.
- Unknown input fields are rejected. Prototype-like tokens such as "__proto__" are ordinary strings.
Input
left(string, required): max length 262144right(string, required): max length 262144
Output
ops(array of object, required): max items 4096keeps(integer, required): min 0deletions(integer, required): min 0insertions(integer, required): min 0
Limits
- max text bytes: 262144
- max token count: 8192
- max edit ops: 4096
- max output bytes: 1048576
Example
Request input:
{
"left": "ab cd",
"right": "ab xy"
}
Response:
{
"result": {
"ops": [
{
"op": "keep",
"value": "ab",
"left_index": 0,
"right_index": 0
},
{
"op": "keep",
"value": " ",
"left_index": 1,
"right_index": 1
},
{
"op": "delete",
"value": "cd",
"left_index": 2
},
{
"op": "insert",
"value": "xy",
"right_index": 2
}
],
"keeps": 2,
"deletions": 1,
"insertions": 1
}
}
How to call it
MCP
Connect https://computefirst.net/mcp (setup), then call execute with:
{
"id": "text-word-diff",
"version": "1.0.0",
"input": {
"left": "ab cd",
"right": "ab xy"
}
}
HTTP (no key)
curl -X POST https://computefirst.net/v1/tools/text-word-diff/versions/1.0.0/execute \
-H "Content-Type: application/json" \
-d '{"left":"ab cd","right":"ab xy"}'
The machine-readable contract is at /v1/tools/text-word-diff/versions/1.0.0.
CLI
node cli.mjs run text-word-diff 1.0.0 --input input.json --base-url https://computefirst.net
Get the client at /clients/cli/.
Related tools
- Text line diff: Diff two texts as line records, preserving each line terminator.
- Text apply unified patch: Apply a one-file unified patch to text at original line addresses with exact hunk matches.
- Text diff stats: Summarize a line-record diff as keep, insert, delete, and hunk counts.
- Text invert unified patch: Invert a one-file unified patch by swapping file names and delete/insert ops.
- Text lines chunk: Split parsed lines into consecutive chunks of size lines each.
- Text parse unified patch: Parse a one-file unified patch into path names and 0-based hunks.