@ls-stack/utils 3.66.0 → 3.67.0

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.
@@ -36,6 +36,7 @@ interface DiffFileBase {
36
36
  newMode: string | undefined;
37
37
  index: string[] | undefined;
38
38
  diff: string | undefined;
39
+ rawDiff: string;
39
40
  }
40
41
  interface DiffFileModified extends DiffFileBase {
41
42
  type: 'modified';
@@ -57,7 +58,22 @@ interface DiffFileCombined extends DiffFileBase {
57
58
  type: 'combined';
58
59
  froms: string[] | undefined;
59
60
  }
61
+ /**
62
+ * Parsed diff file metadata and hunks.
63
+ *
64
+ * The `type` discriminator indicates the kind of change this diff represents.
65
+ * Combined diffs (e.g. `diff --cc`) may include multiple parent paths via
66
+ * `froms`.
67
+ */
60
68
  type DiffFile = DiffFileModified | DiffFileNew | DiffFileDeleted | DiffFileRenamed | DiffFileBinary | DiffFileCombined;
69
+ /**
70
+ * Parse unified diff text (git, hg, svn) into structured file hunks.
71
+ *
72
+ * @example
73
+ * ```ts
74
+ * const files = diffParser('@@ -1 +1 @@\\n-old\\n+new');
75
+ * ```;
76
+ */
61
77
  declare function diffParser(input: string): DiffFile[];
62
78
  //#endregion
63
79
  export { DiffFile, diffParser };
@@ -1,4 +1,12 @@
1
1
  //#region src/diffParser.ts
2
+ /**
3
+ * Parse unified diff text (git, hg, svn) into structured file hunks.
4
+ *
5
+ * @example
6
+ * ```ts
7
+ * const files = diffParser('@@ -1 +1 @@\\n-old\\n+new');
8
+ * ```;
9
+ */
2
10
  function diffParser(input) {
3
11
  if (!input) return [];
4
12
  if (typeof input !== "string" || input.match(/^\s+$/)) return [];
@@ -37,7 +45,8 @@ function diffParser(input) {
37
45
  oldMode: void 0,
38
46
  newMode: void 0,
39
47
  index: void 0,
40
- diff: void 0
48
+ diff: void 0,
49
+ rawDiff: ""
41
50
  };
42
51
  fromLineCount = 0;
43
52
  pendingFroms = void 0;
@@ -84,6 +93,9 @@ function diffParser(input) {
84
93
  renamedFile.similarityIndex = Number(match[1]);
85
94
  }
86
95
  };
96
+ const indexFile = (line) => {
97
+ start(line);
98
+ };
87
99
  const renameFrom = (line) => {
88
100
  restart();
89
101
  if (currentFile) {
@@ -301,6 +313,7 @@ function diffParser(input) {
301
313
  }
302
314
  };
303
315
  const schemaHeaders = [
316
+ [/^Index:\s/, indexFile],
304
317
  [/^diff\s/, start],
305
318
  [/^new file mode (\d+)$/, newFile],
306
319
  [/^deleted file mode (\d+)$/, deletedFile],
@@ -351,6 +364,7 @@ function diffParser(input) {
351
364
  const parseLine = (line) => {
352
365
  if (currentFileChanges) parseContentLine(line);
353
366
  else parseHeaderLine(line);
367
+ if (currentFile) currentFile.rawDiff = currentFile.rawDiff.length === 0 ? line : `${currentFile.rawDiff}\n${line}`;
354
368
  };
355
369
  for (const line of lines) parseLine(line);
356
370
  for (const file of files) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ls-stack/utils",
3
3
  "description": "Universal TypeScript utilities for browser and Node.js",
4
- "version": "3.66.0",
4
+ "version": "3.67.0",
5
5
  "license": "MIT",
6
6
  "files": [
7
7
  "dist",