MCPcopy Create free account
hub / github.com/kpdecker/jsdiff / applyPatch

Function applyPatch

src/patch/apply.ts:54–73  ·  view source on GitHub ↗
(
  source: string,
  patch: string | StructuredPatch | [StructuredPatch],
  options: ApplyPatchOptions = {}
)

Source from the content-addressed store, hash-verified

52 * @param patch a string diff or the output from the `parsePatch` or `structuredPatch` methods.
53 */
54export function applyPatch(
55 source: string,
56 patch: string | StructuredPatch | [StructuredPatch],
57 options: ApplyPatchOptions = {}
58): string | false {
59 let patches: StructuredPatch[];
60 if (typeof patch === 'string') {
61 patches = parsePatch(patch);
62 } else if (Array.isArray(patch)) {
63 patches = patch;
64 } else {
65 patches = [patch];
66 }
67
68 if (patches.length > 1) {
69 throw new Error('applyPatch only works with a single input.');
70 }
71
72 return applyStructuredPatch(source, patches[0], options);
73}
74
75function applyStructuredPatch(
76 source: string,

Callers 3

reverse.jsFile · 0.85
apply.jsFile · 0.85
processIndexFunction · 0.85

Calls 2

parsePatchFunction · 0.85
applyStructuredPatchFunction · 0.85

Tested by

no test coverage detected