@pierre/diffs 1.0.10 → 1.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11735,7 +11735,7 @@ function attachResolvedThemes(themes, highlighter$1) {
11735
11735
  }
11736
11736
 
11737
11737
  //#endregion
11738
- //#region ../../node_modules/.bun/diff@8.0.2/node_modules/diff/libesm/diff/base.js
11738
+ //#region ../../node_modules/.bun/diff@8.0.3/node_modules/diff/libesm/diff/base.js
11739
11739
  var Diff = class {
11740
11740
  diff(oldStr, newStr, options = {}) {
11741
11741
  let callback;
@@ -11959,7 +11959,7 @@ var Diff = class {
11959
11959
  };
11960
11960
 
11961
11961
  //#endregion
11962
- //#region ../../node_modules/.bun/diff@8.0.2/node_modules/diff/libesm/diff/character.js
11962
+ //#region ../../node_modules/.bun/diff@8.0.3/node_modules/diff/libesm/diff/character.js
11963
11963
  var CharacterDiff = class extends Diff {};
11964
11964
  const characterDiff = new CharacterDiff();
11965
11965
  function diffChars(oldStr, newStr, options) {
@@ -11967,7 +11967,7 @@ function diffChars(oldStr, newStr, options) {
11967
11967
  }
11968
11968
 
11969
11969
  //#endregion
11970
- //#region ../../node_modules/.bun/diff@8.0.2/node_modules/diff/libesm/util/string.js
11970
+ //#region ../../node_modules/.bun/diff@8.0.3/node_modules/diff/libesm/util/string.js
11971
11971
  function longestCommonPrefix(str1, str2) {
11972
11972
  let i$2;
11973
11973
  for (i$2 = 0; i$2 < str1.length && i$2 < str2.length; i$2++) {
@@ -12076,8 +12076,8 @@ function leadingWs(string) {
12076
12076
  }
12077
12077
 
12078
12078
  //#endregion
12079
- //#region ../../node_modules/.bun/diff@8.0.2/node_modules/diff/libesm/diff/word.js
12080
- const extendedWordChars = "a-zA-Z0-9_\\u{C0}-\\u{FF}\\u{D8}-\\u{F6}\\u{F8}-\\u{2C6}\\u{2C8}-\\u{2D7}\\u{2DE}-\\u{2FF}\\u{1E00}-\\u{1EFF}";
12079
+ //#region ../../node_modules/.bun/diff@8.0.3/node_modules/diff/libesm/diff/word.js
12080
+ const extendedWordChars = "a-zA-Z0-9_\\u{AD}\\u{C0}-\\u{D6}\\u{D8}-\\u{F6}\\u{F8}-\\u{2C6}\\u{2C8}-\\u{2D7}\\u{2DE}-\\u{2FF}\\u{1E00}-\\u{1EFF}";
12081
12081
  const tokenizeIncludingWhitespace = new RegExp(`[${extendedWordChars}]+|\\s+|[^${extendedWordChars}]`, "ug");
12082
12082
  var WordDiff = class extends Diff {
12083
12083
  equals(left, right, options) {
@@ -12094,7 +12094,15 @@ var WordDiff = class extends Diff {
12094
12094
  if (segmenter.resolvedOptions().granularity != "word") {
12095
12095
  throw new Error("The segmenter passed must have a granularity of \"word\"");
12096
12096
  }
12097
- parts = Array.from(segmenter.segment(value), (segment) => segment.segment);
12097
+ parts = [];
12098
+ for (const segmentObj of Array.from(segmenter.segment(value))) {
12099
+ const segment = segmentObj.segment;
12100
+ if (parts.length && /\s/.test(parts[parts.length - 1]) && /\s/.test(segment)) {
12101
+ parts[parts.length - 1] += segment;
12102
+ } else {
12103
+ parts.push(segment);
12104
+ }
12105
+ }
12098
12106
  } else {
12099
12107
  parts = value.match(tokenizeIncludingWhitespace) || [];
12100
12108
  }
@@ -12222,7 +12230,7 @@ function diffWordsWithSpace(oldStr, newStr, options) {
12222
12230
  }
12223
12231
 
12224
12232
  //#endregion
12225
- //#region ../../node_modules/.bun/diff@8.0.2/node_modules/diff/libesm/util/params.js
12233
+ //#region ../../node_modules/.bun/diff@8.0.3/node_modules/diff/libesm/util/params.js
12226
12234
  function generateOptions(options, defaults) {
12227
12235
  if (typeof options === "function") {
12228
12236
  defaults.callback = options;
@@ -12238,7 +12246,7 @@ function generateOptions(options, defaults) {
12238
12246
  }
12239
12247
 
12240
12248
  //#endregion
12241
- //#region ../../node_modules/.bun/diff@8.0.2/node_modules/diff/libesm/diff/line.js
12249
+ //#region ../../node_modules/.bun/diff@8.0.3/node_modules/diff/libesm/diff/line.js
12242
12250
  var LineDiff = class extends Diff {
12243
12251
  constructor() {
12244
12252
  super(...arguments);
@@ -12291,7 +12299,7 @@ function tokenize(value, options) {
12291
12299
  }
12292
12300
 
12293
12301
  //#endregion
12294
- //#region ../../node_modules/.bun/diff@8.0.2/node_modules/diff/libesm/diff/sentence.js
12302
+ //#region ../../node_modules/.bun/diff@8.0.3/node_modules/diff/libesm/diff/sentence.js
12295
12303
  function isSentenceEndPunct(char) {
12296
12304
  return char == "." || char == "!" || char == "?";
12297
12305
  }
@@ -12324,7 +12332,7 @@ function diffSentences(oldStr, newStr, options) {
12324
12332
  }
12325
12333
 
12326
12334
  //#endregion
12327
- //#region ../../node_modules/.bun/diff@8.0.2/node_modules/diff/libesm/diff/css.js
12335
+ //#region ../../node_modules/.bun/diff@8.0.3/node_modules/diff/libesm/diff/css.js
12328
12336
  var CssDiff = class extends Diff {
12329
12337
  tokenize(value) {
12330
12338
  return value.split(/([{}:;,]|\s+)/);
@@ -12336,7 +12344,7 @@ function diffCss(oldStr, newStr, options) {
12336
12344
  }
12337
12345
 
12338
12346
  //#endregion
12339
- //#region ../../node_modules/.bun/diff@8.0.2/node_modules/diff/libesm/diff/json.js
12347
+ //#region ../../node_modules/.bun/diff@8.0.3/node_modules/diff/libesm/diff/json.js
12340
12348
  var JsonDiff = class extends Diff {
12341
12349
  constructor() {
12342
12350
  super(...arguments);
@@ -12410,7 +12418,7 @@ function canonicalize(obj, stack, replacementStack, replacer, key$1) {
12410
12418
  }
12411
12419
 
12412
12420
  //#endregion
12413
- //#region ../../node_modules/.bun/diff@8.0.2/node_modules/diff/libesm/diff/array.js
12421
+ //#region ../../node_modules/.bun/diff@8.0.3/node_modules/diff/libesm/diff/array.js
12414
12422
  var ArrayDiff = class extends Diff {
12415
12423
  tokenize(value) {
12416
12424
  return value.slice();
@@ -12428,7 +12436,7 @@ function diffArrays(oldArr, newArr, options) {
12428
12436
  }
12429
12437
 
12430
12438
  //#endregion
12431
- //#region ../../node_modules/.bun/diff@8.0.2/node_modules/diff/libesm/patch/line-endings.js
12439
+ //#region ../../node_modules/.bun/diff@8.0.3/node_modules/diff/libesm/patch/line-endings.js
12432
12440
  function unixToWin(patch) {
12433
12441
  if (Array.isArray(patch)) {
12434
12442
  return patch.map((p$1) => unixToWin(p$1));
@@ -12468,7 +12476,7 @@ function isWin(patch) {
12468
12476
  }
12469
12477
 
12470
12478
  //#endregion
12471
- //#region ../../node_modules/.bun/diff@8.0.2/node_modules/diff/libesm/patch/parse.js
12479
+ //#region ../../node_modules/.bun/diff@8.0.3/node_modules/diff/libesm/patch/parse.js
12472
12480
  /**
12473
12481
  * Parses a patch into structured data, in the same structure returned by `structuredPatch`.
12474
12482
  *
@@ -12485,9 +12493,9 @@ function parsePatch(uniDiff) {
12485
12493
  if (/^(---|\+\+\+|@@)\s/.test(line)) {
12486
12494
  break;
12487
12495
  }
12488
- const header = /^(?:Index:|diff(?: -r \w+)+)\s+(.+?)\s*$/.exec(line);
12489
- if (header) {
12490
- index.index = header[1];
12496
+ const headerMatch = /^(?:Index:|diff(?: -r \w+)+)\s+/.exec(line);
12497
+ if (headerMatch) {
12498
+ index.index = line.substring(headerMatch[0].length).trim();
12491
12499
  }
12492
12500
  i$2++;
12493
12501
  }
@@ -12508,14 +12516,14 @@ function parsePatch(uniDiff) {
12508
12516
  }
12509
12517
  }
12510
12518
  function parseFileHeader(index) {
12511
- const fileHeader = /^(---|\+\+\+)\s+(.*)\r?$/.exec(diffstr[i$2]);
12512
- if (fileHeader) {
12513
- const data = fileHeader[2].split(" ", 2), header = (data[1] || "").trim();
12519
+ const fileHeaderMatch = /^(---|\+\+\+)\s+/.exec(diffstr[i$2]);
12520
+ if (fileHeaderMatch) {
12521
+ const prefix = fileHeaderMatch[1], data = diffstr[i$2].substring(3).trim().split(" ", 2), header = (data[1] || "").trim();
12514
12522
  let fileName = data[0].replace(/\\\\/g, "\\");
12515
- if (/^".*"$/.test(fileName)) {
12523
+ if (fileName.startsWith("\"") && fileName.endsWith("\"")) {
12516
12524
  fileName = fileName.substr(1, fileName.length - 2);
12517
12525
  }
12518
- if (fileHeader[1] === "---") {
12526
+ if (prefix === "---") {
12519
12527
  index.oldFileName = fileName;
12520
12528
  index.oldHeader = header;
12521
12529
  } else {
@@ -12579,7 +12587,7 @@ function parsePatch(uniDiff) {
12579
12587
  }
12580
12588
 
12581
12589
  //#endregion
12582
- //#region ../../node_modules/.bun/diff@8.0.2/node_modules/diff/libesm/util/distance-iterator.js
12590
+ //#region ../../node_modules/.bun/diff@8.0.3/node_modules/diff/libesm/util/distance-iterator.js
12583
12591
  function distance_iterator_default(start, minLine, maxLine) {
12584
12592
  let wantForward = true, backwardExhausted = false, forwardExhausted = false, localOffset = 1;
12585
12593
  return function iterator() {
@@ -12609,7 +12617,7 @@ function distance_iterator_default(start, minLine, maxLine) {
12609
12617
  }
12610
12618
 
12611
12619
  //#endregion
12612
- //#region ../../node_modules/.bun/diff@8.0.2/node_modules/diff/libesm/patch/apply.js
12620
+ //#region ../../node_modules/.bun/diff@8.0.3/node_modules/diff/libesm/patch/apply.js
12613
12621
  /**
12614
12622
  * attempts to apply a unified diff patch.
12615
12623
  *
@@ -12828,7 +12836,7 @@ function applyPatches(uniDiff, options) {
12828
12836
  }
12829
12837
 
12830
12838
  //#endregion
12831
- //#region ../../node_modules/.bun/diff@8.0.2/node_modules/diff/libesm/patch/reverse.js
12839
+ //#region ../../node_modules/.bun/diff@8.0.3/node_modules/diff/libesm/patch/reverse.js
12832
12840
  function reversePatch(structuredPatch$1) {
12833
12841
  if (Array.isArray(structuredPatch$1)) {
12834
12842
  return structuredPatch$1.map((patch) => reversePatch(patch)).reverse();
@@ -12859,7 +12867,22 @@ function reversePatch(structuredPatch$1) {
12859
12867
  }
12860
12868
 
12861
12869
  //#endregion
12862
- //#region ../../node_modules/.bun/diff@8.0.2/node_modules/diff/libesm/patch/create.js
12870
+ //#region ../../node_modules/.bun/diff@8.0.3/node_modules/diff/libesm/patch/create.js
12871
+ const INCLUDE_HEADERS = {
12872
+ includeIndex: true,
12873
+ includeUnderline: true,
12874
+ includeFileHeaders: true
12875
+ };
12876
+ const FILE_HEADERS_ONLY = {
12877
+ includeIndex: false,
12878
+ includeUnderline: false,
12879
+ includeFileHeaders: true
12880
+ };
12881
+ const OMIT_HEADERS = {
12882
+ includeIndex: false,
12883
+ includeUnderline: false,
12884
+ includeFileHeaders: false
12885
+ };
12863
12886
  function structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
12864
12887
  let optionsObj;
12865
12888
  if (!options) {
@@ -12973,17 +12996,27 @@ function structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, ne
12973
12996
  * creates a unified diff patch.
12974
12997
  * @param patch either a single structured patch object (as returned by `structuredPatch`) or an array of them (as returned by `parsePatch`)
12975
12998
  */
12976
- function formatPatch(patch) {
12999
+ function formatPatch(patch, headerOptions) {
13000
+ if (!headerOptions) {
13001
+ headerOptions = INCLUDE_HEADERS;
13002
+ }
12977
13003
  if (Array.isArray(patch)) {
12978
- return patch.map(formatPatch).join("\n");
13004
+ if (patch.length > 1 && !headerOptions.includeFileHeaders) {
13005
+ throw new Error("Cannot omit file headers on a multi-file patch. " + "(The result would be unparseable; how would a tool trying to apply " + "the patch know which changes are to which file?)");
13006
+ }
13007
+ return patch.map((p$1) => formatPatch(p$1, headerOptions)).join("\n");
12979
13008
  }
12980
13009
  const ret = [];
12981
- if (patch.oldFileName == patch.newFileName) {
13010
+ if (headerOptions.includeIndex && patch.oldFileName == patch.newFileName) {
12982
13011
  ret.push("Index: " + patch.oldFileName);
12983
13012
  }
12984
- ret.push("===================================================================");
12985
- ret.push("--- " + patch.oldFileName + (typeof patch.oldHeader === "undefined" ? "" : " " + patch.oldHeader));
12986
- ret.push("+++ " + patch.newFileName + (typeof patch.newHeader === "undefined" ? "" : " " + patch.newHeader));
13013
+ if (headerOptions.includeUnderline) {
13014
+ ret.push("===================================================================");
13015
+ }
13016
+ if (headerOptions.includeFileHeaders) {
13017
+ ret.push("--- " + patch.oldFileName + (typeof patch.oldHeader === "undefined" ? "" : " " + patch.oldHeader));
13018
+ ret.push("+++ " + patch.newFileName + (typeof patch.newHeader === "undefined" ? "" : " " + patch.newHeader));
13019
+ }
12987
13020
  for (let i$2 = 0; i$2 < patch.hunks.length; i$2++) {
12988
13021
  const hunk = patch.hunks[i$2];
12989
13022
  if (hunk.oldLines === 0) {
@@ -13008,14 +13041,14 @@ function createTwoFilesPatch(oldFileName, newFileName, oldStr, newStr, oldHeader
13008
13041
  if (!patchObj) {
13009
13042
  return;
13010
13043
  }
13011
- return formatPatch(patchObj);
13044
+ return formatPatch(patchObj, options === null || options === void 0 ? void 0 : options.headerOptions);
13012
13045
  } else {
13013
13046
  const { callback } = options;
13014
13047
  structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, Object.assign(Object.assign({}, options), { callback: (patchObj) => {
13015
13048
  if (!patchObj) {
13016
13049
  callback(undefined);
13017
13050
  } else {
13018
- callback(formatPatch(patchObj));
13051
+ callback(formatPatch(patchObj, options.headerOptions));
13019
13052
  }
13020
13053
  } }));
13021
13054
  }
@@ -13038,7 +13071,7 @@ function splitLines(text$1) {
13038
13071
  }
13039
13072
 
13040
13073
  //#endregion
13041
- //#region ../../node_modules/.bun/diff@8.0.2/node_modules/diff/libesm/convert/dmp.js
13074
+ //#region ../../node_modules/.bun/diff@8.0.3/node_modules/diff/libesm/convert/dmp.js
13042
13075
  /**
13043
13076
  * converts a list of change objects to the format returned by Google's [diff-match-patch](https://github.com/google/diff-match-patch) library
13044
13077
  */
@@ -13060,7 +13093,7 @@ function convertChangesToDMP(changes) {
13060
13093
  }
13061
13094
 
13062
13095
  //#endregion
13063
- //#region ../../node_modules/.bun/diff@8.0.2/node_modules/diff/libesm/convert/xml.js
13096
+ //#region ../../node_modules/.bun/diff@8.0.3/node_modules/diff/libesm/convert/xml.js
13064
13097
  /**
13065
13098
  * converts a list of change objects to a serialized XML format
13066
13099
  */