MCPcopy Index your code
hub / github.com/kpdecker/jsdiff / createTwoFilesPatch

Function createTwoFilesPatch

src/patch/create.ts:527–567  ·  view source on GitHub ↗
(
  oldFileName: string,
  newFileName: string,
  oldStr: string,
  newStr: string,
  oldHeader?: string,
  newHeader?: string,
  options?: CreatePatchOptionsAbortable | CreatePatchOptionsNonabortable | CreatePatchCallbackNonabortable
)

Source from the content-addressed store, hash-verified

525 options?: CreatePatchOptionsNonabortable
526): string
527export function createTwoFilesPatch(
528 oldFileName: string,
529 newFileName: string,
530 oldStr: string,
531 newStr: string,
532 oldHeader?: string,
533 newHeader?: string,
534 options?: CreatePatchOptionsAbortable | CreatePatchOptionsNonabortable | CreatePatchCallbackNonabortable
535): string | undefined {
536 if (typeof options === 'function') {
537 options = {callback: options};
538 }
539
540 if (!options?.callback) {
541 const patchObj = structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options as any);
542 if (!patchObj) {
543 return;
544 }
545 return formatPatch(patchObj, options?.headerOptions);
546 } else {
547 const {callback} = options;
548 structuredPatch(
549 oldFileName,
550 newFileName,
551 oldStr,
552 newStr,
553 oldHeader,
554 newHeader,
555 {
556 ...options,
557 callback: patchObj => {
558 if (!patchObj) {
559 (callback as CreatePatchCallbackAbortable)(undefined);
560 } else {
561 callback(formatPatch(patchObj, options.headerOptions));
562 }
563 }
564 }
565 );
566 }
567}
568
569/**
570 * creates a unified diff patch.

Callers 2

create.jsFile · 0.85
createPatchFunction · 0.85

Calls 3

structuredPatchFunction · 0.85
formatPatchFunction · 0.85
callbackFunction · 0.85

Tested by

no test coverage detected