diff Diff two text blocks line by line
Examples
Compare two text blocks line by line
Usage
"the quick brown fox
jumps over
the lazy dog
---
the quick re..." | diff Compare two versions of marketing copy
Usage
"Our product helps teams work faster.
Built for modern workfl..." | diff Spot changes between two versions of a company policy
Usage
"PTO: 15 days
Remote: 2 days/week
Bonus: up to 10%
---
PTO: 2..." | diff View source
async (input)=>{
const sep = input.indexOf("\n---\n");
if (sep === -1) return "Error: separate two text blocks with a line containing only ---";
const oldText = input.slice(0, sep);
const newText = input.slice(sep + 5);
const { diffLines } = await import('diff').then(async (m)=>{
await m.__tla;
return m;
});
const changes = diffLines(oldText, newText);
const result = [];
for (const part of changes){
const prefix = part.added ? "+ " : part.removed ? "- " : " ";
const lines = part.value.replace(/\n$/, "").split("\n");
for (const line of lines)result.push(prefix + line);
}
return result.join("\n");
}