function
diff.applyPatch
source: string,
): undefined | string;
Apply a patch for one file to source.
The lines that a hunk keeps and removes have to match exactly. If they don't match at oldStart, Bun uses the nearest line where they do. If source only has
\rline endings and the patch only has
, or the reverse, the patch is converted first.
@param patch
A unified diff, or hunks from hunks or parsePatch
@returns
The patched text, or undefined if a hunk does not match
Referenced types
interface Hunk
One @@ section of a unified diff.
- lines: string[]
Each line without its
, after" "(kept),"-"(removed) or"+"(added)."\\ No newline at end of file"follows a line that has no
. - newStart: number
The first line of the hunk in the new text, from 1. If
newLinesis 0, the line after the hunk. - oldStart: number
The first line of the hunk in the old text, from 1. If
oldLinesis 0, the line after the hunk.