Skip to content
Prev Previous commit
Next Next commit
Support passing function as 'options' argument as with existing methods
  • Loading branch information
ExplodingCabbage committed Jun 7, 2024
commit 146a61f28b8ca6ddbc44bb35ebe39512f3755742
7 changes: 7 additions & 0 deletions src/patch/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ export function structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHea
if (!options) {
options = {};
}
if (typeof options === 'function') {
options = {callback: options};
}
if (typeof options.context === 'undefined') {
options.context = 4;
}
Expand Down Expand Up @@ -158,6 +161,10 @@ export function formatPatch(diff) {
}

export function createTwoFilesPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
if (typeof options === 'function') {
options = {callback: options};
}

if (!options?.callback) {
const patchObj = structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options);
if (!patchObj) {
Expand Down