Something went wrong. Try again.
🌿 Collaborative wiki on ATProto forked from juprodh.me/lichen.wiki
Something went wrong. Try again.
576 B · 18 lines
TypeScript
at main
12345678910111213141516171819import DiffMatchPatch from "diff-match-patch";
const dmp = new DiffMatchPatch();
export function createDiff(oldText: string, newText: string): string { const patches = dmp.patch_make(oldText, newText); return dmp.patch_toText(patches);}
export function applyDiff(text: string, patchText: string): string { const patches = dmp.patch_fromText(patchText); const [result, applied] = dmp.patch_apply(patches, text); const failed = applied.filter((ok) => !ok); if (failed.length > 0) { throw new Error(`Failed to apply ${failed.length} patch(es)`); } return result;}