function
diff.createPatch
Compare two strings line by line and format the result as a unified diff, like diff -u.
The patch, "" if the strings are equal, or undefined if there are more than maxEditLength edits
Bun.diff.createPatch("a\nb\n", "a\nc\n", { oldFileName: "file.txt" });
// --- file.txt
// +++ file.txt
// @@ -1,2 +1,2 @@
// a
// -b
// +cCompare two strings line by line and format the result as a unified diff, like diff -u.
The patch, "" if the strings are equal, or undefined if there are more than maxEditLength edits
Bun.diff.createPatch("a\nb\n", "a\nc\n", { oldFileName: "file.txt" });
// --- file.txt
// +++ file.txt
// @@ -1,2 +1,2 @@
// a
// -b
// +cReferenced types
interface PatchOptions
- context?: number
The number of unchanged lines before and after each change, like
diff -U. An integer from 0, orInfinityfor the whole file. - maxEditLength?: number
Return
undefinedwhen the diff adds and removes more than this many tokens in total. An integer from 0, orInfinity. - newHeader?: string
Text after the name in the
+++line, such as a timestamp. It needs a file name and has to be one line. - oldFileName?: string
The name in the
---line. Defaults tonewFileName. Without either name, the patch has no---and+++lines. - oldHeader?: string
Text after the name in the
---line, such as a timestamp. It needs a file name and has to be one line.