ℹ️ Diff Checker runs entirely client-side. No server API is needed. Here's the line-by-line comparison logic:
Simple line-by-line diff in JavaScript.
// Client-side diff — no API call needed
function diffLines(original, modified) {
const a = original.split('\n');
const b = modified.split('\n');
const result = [];
const max = Math.max(a.length, b.length);
for (let i = 0; i < max; i++) {
if (a[i] === undefined) result.push({ type: 'add', line: b[i] });
else if (b[i] === undefined) result.push({ type: 'del', line: a[i] });
else if (a[i] === b[i]) result.push({ type: 'same', line: a[i] });
else {
result.push({ type: 'del', line: a[i] });
result.push({ type: 'add', line: b[i] });
}
}
return result;
}
const diff = diffLines("hello\nworld", "hello\nearth");
// → [{ type: "same", line: "hello" }, { type: "del", line: "world" }, { type: "add", line: "earth" }]