@ls-stack/utils 3.65.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.
Files changed (336) hide show
  1. package/dist/{arrayUtils.d.cts → arrayUtils.d.mts} +24 -23
  2. package/dist/arrayUtils.mjs +249 -0
  3. package/dist/assertions-qMxfVhSu.mjs +207 -0
  4. package/dist/{assertions.d.ts → assertions.d.mts} +4 -3
  5. package/dist/assertions.mjs +3 -0
  6. package/dist/asyncQueue.d.mts +497 -0
  7. package/dist/asyncQueue.mjs +757 -0
  8. package/dist/{awaitDebounce.d.cts → awaitDebounce.d.mts} +11 -6
  9. package/dist/awaitDebounce.mjs +54 -0
  10. package/dist/{cache.d.ts → cache.d.mts} +76 -68
  11. package/dist/cache.mjs +355 -0
  12. package/dist/castValues-DfICShCc.mjs +19 -0
  13. package/dist/{castValues.d.cts → castValues.d.mts} +3 -2
  14. package/dist/castValues.mjs +3 -0
  15. package/dist/{concurrentCalls.d.ts → concurrentCalls.d.mts} +74 -65
  16. package/dist/concurrentCalls.mjs +295 -0
  17. package/dist/consoleFmt.d.mts +55 -0
  18. package/dist/consoleFmt.mjs +63 -0
  19. package/dist/conversions-DTmwEMIu.mjs +12 -0
  20. package/dist/conversions.d.mts +4 -0
  21. package/dist/conversions.mjs +3 -0
  22. package/dist/createThrottleController.d.mts +18 -0
  23. package/dist/createThrottleController.mjs +40 -0
  24. package/dist/debounce.d.mts +47 -0
  25. package/dist/debounce.mjs +117 -0
  26. package/dist/dedent.d.mts +74 -0
  27. package/dist/dedent.mjs +80 -0
  28. package/dist/deepEqual-C7EZEixx.mjs +78 -0
  29. package/dist/{deepEqual.d.cts → deepEqual.d.mts} +3 -2
  30. package/dist/deepEqual.mjs +3 -0
  31. package/dist/{deepReplaceValues.d.cts → deepReplaceValues.d.mts} +4 -3
  32. package/dist/deepReplaceValues.mjs +61 -0
  33. package/dist/diffParser.d.mts +79 -0
  34. package/dist/diffParser.mjs +424 -0
  35. package/dist/enhancedMap.d.mts +21 -0
  36. package/dist/enhancedMap.mjs +69 -0
  37. package/dist/exhaustiveMatch.d.mts +10 -0
  38. package/dist/exhaustiveMatch.mjs +48 -0
  39. package/dist/{filterObjectOrArrayKeys.d.cts → filterObjectOrArrayKeys.d.mts} +15 -8
  40. package/dist/filterObjectOrArrayKeys.mjs +497 -0
  41. package/dist/{getAutoIncrementId.d.cts → getAutoIncrementId.d.mts} +9 -5
  42. package/dist/getAutoIncrementId.mjs +53 -0
  43. package/dist/{getCompositeKey.d.cts → getCompositeKey.d.mts} +3 -2
  44. package/dist/getCompositeKey.mjs +50 -0
  45. package/dist/{getValueStableKey.d.cts → getValueStableKey.d.mts} +5 -3
  46. package/dist/getValueStableKey.mjs +17 -0
  47. package/dist/{hash.d.cts → hash.d.mts} +3 -2
  48. package/dist/hash.mjs +28 -0
  49. package/dist/interpolate.d.mts +17 -0
  50. package/dist/interpolate.mjs +28 -0
  51. package/dist/{iteratorUtils.d.cts → iteratorUtils.d.mts} +5 -4
  52. package/dist/iteratorUtils.mjs +39 -0
  53. package/dist/keepPrevIfUnchanged.d.mts +12 -0
  54. package/dist/keepPrevIfUnchanged.mjs +9 -0
  55. package/dist/keyedMap.d.mts +76 -0
  56. package/dist/keyedMap.mjs +139 -0
  57. package/dist/keyedSet.d.mts +77 -0
  58. package/dist/keyedSet.mjs +129 -0
  59. package/dist/{levenshtein.d.cts → levenshtein.d.mts} +3 -2
  60. package/dist/levenshtein.mjs +121 -0
  61. package/dist/main.d.mts +4 -0
  62. package/dist/main.mjs +7 -0
  63. package/dist/matchPath.d.mts +50 -0
  64. package/dist/matchPath.mjs +81 -0
  65. package/dist/mathUtils-BDP1lM_z.mjs +81 -0
  66. package/dist/{mathUtils.d.cts → mathUtils.d.mts} +3 -2
  67. package/dist/mathUtils.mjs +3 -0
  68. package/dist/{mutationUtils.d.cts → mutationUtils.d.mts} +6 -5
  69. package/dist/mutationUtils.mjs +44 -0
  70. package/dist/{objUtils.d.ts → objUtils.d.mts} +8 -6
  71. package/dist/objUtils.mjs +115 -0
  72. package/dist/parallelAsyncCalls.d.mts +83 -0
  73. package/dist/parallelAsyncCalls.mjs +121 -0
  74. package/dist/partialEqual.d.mts +139 -0
  75. package/dist/partialEqual.mjs +1055 -0
  76. package/dist/promiseUtils.d.mts +9 -0
  77. package/dist/promiseUtils.mjs +17 -0
  78. package/dist/regexUtils.d.mts +18 -0
  79. package/dist/regexUtils.mjs +34 -0
  80. package/dist/{retryOnError.d.cts → retryOnError.d.mts} +38 -37
  81. package/dist/retryOnError.mjs +91 -0
  82. package/dist/{runShellCmd.d.ts → runShellCmd.d.mts} +24 -15
  83. package/dist/runShellCmd.mjs +151 -0
  84. package/dist/{safeJson.d.cts → safeJson.d.mts} +3 -2
  85. package/dist/safeJson.mjs +30 -0
  86. package/dist/{saferTyping.d.cts → saferTyping.d.mts} +4 -3
  87. package/dist/saferTyping.mjs +45 -0
  88. package/dist/serializeXML.d.mts +23 -0
  89. package/dist/serializeXML.mjs +74 -0
  90. package/dist/{shallowEqual.d.cts → shallowEqual.d.mts} +3 -2
  91. package/dist/shallowEqual.mjs +54 -0
  92. package/dist/sleep.d.mts +4 -0
  93. package/dist/sleep.mjs +7 -0
  94. package/dist/stringUtils-DjhWOiYn.mjs +113 -0
  95. package/dist/{stringUtils.d.cts → stringUtils.d.mts} +3 -2
  96. package/dist/stringUtils.mjs +3 -0
  97. package/dist/{testUtils.d.ts → testUtils.d.mts} +83 -52
  98. package/dist/testUtils.mjs +310 -0
  99. package/dist/{throttle.d.ts → throttle.d.mts} +18 -17
  100. package/dist/throttle.mjs +102 -0
  101. package/dist/time-sr2lhQRw.mjs +67 -0
  102. package/dist/{time.d.ts → time.d.mts} +8 -7
  103. package/dist/time.mjs +3 -0
  104. package/dist/{timers.d.cts → timers.d.mts} +22 -13
  105. package/dist/timers.mjs +220 -0
  106. package/dist/{tsResult.d.cts → tsResult.d.mts} +52 -48
  107. package/dist/tsResult.mjs +142 -0
  108. package/dist/typeGuards-B1mzA-Rz.mjs +128 -0
  109. package/dist/{typeGuards.d.cts → typeGuards.d.mts} +3 -2
  110. package/dist/typeGuards.mjs +3 -0
  111. package/dist/{typeUtils.d.ts → typeUtils.d.mts} +13 -34
  112. package/dist/typeUtils.mjs +1 -0
  113. package/dist/{typedStrings.d.cts → typedStrings.d.mts} +5 -4
  114. package/dist/typedStrings.mjs +131 -0
  115. package/dist/typingFnUtils-Bb8drgKF.mjs +101 -0
  116. package/dist/{typingFnUtils.d.cts → typingFnUtils.d.mts} +13 -22
  117. package/dist/typingFnUtils.mjs +3 -0
  118. package/dist/{typingTestUtils.d.cts → typingTestUtils.d.mts} +11 -15
  119. package/dist/typingTestUtils.mjs +80 -0
  120. package/dist/typingUtils.d.mts +20 -0
  121. package/dist/typingUtils.mjs +1 -0
  122. package/dist/yamlStringify.d.mts +17 -0
  123. package/dist/yamlStringify.mjs +189 -0
  124. package/package.json +65 -242
  125. package/dist/arrayUtils.cjs +0 -229
  126. package/dist/arrayUtils.d.ts +0 -171
  127. package/dist/arrayUtils.js +0 -42
  128. package/dist/assertions.cjs +0 -107
  129. package/dist/assertions.d.cts +0 -192
  130. package/dist/assertions.js +0 -25
  131. package/dist/asyncQueue.cjs +0 -672
  132. package/dist/asyncQueue.d.cts +0 -488
  133. package/dist/asyncQueue.d.ts +0 -488
  134. package/dist/asyncQueue.js +0 -631
  135. package/dist/awaitDebounce.cjs +0 -106
  136. package/dist/awaitDebounce.d.ts +0 -41
  137. package/dist/awaitDebounce.js +0 -28
  138. package/dist/cache.cjs +0 -367
  139. package/dist/cache.d.cts +0 -228
  140. package/dist/cache.js +0 -19
  141. package/dist/castValues.cjs +0 -50
  142. package/dist/castValues.d.ts +0 -4
  143. package/dist/castValues.js +0 -8
  144. package/dist/chunk-5DZT3Z5Z.js +0 -8
  145. package/dist/chunk-6FBIEPWU.js +0 -96
  146. package/dist/chunk-6FIBVC2P.js +0 -56
  147. package/dist/chunk-7CQPOM5I.js +0 -100
  148. package/dist/chunk-B6DNOZCP.js +0 -369
  149. package/dist/chunk-BM4PYVOX.js +0 -109
  150. package/dist/chunk-C2SVCIWE.js +0 -57
  151. package/dist/chunk-CCUPDGSZ.js +0 -132
  152. package/dist/chunk-DBOWTYR4.js +0 -49
  153. package/dist/chunk-DFXNVEH6.js +0 -14
  154. package/dist/chunk-DX2524CZ.js +0 -314
  155. package/dist/chunk-GMJTLFM6.js +0 -60
  156. package/dist/chunk-IATIXMCE.js +0 -20
  157. package/dist/chunk-II4R3VVX.js +0 -25
  158. package/dist/chunk-JF2MDHOJ.js +0 -40
  159. package/dist/chunk-JQFUKJU5.js +0 -71
  160. package/dist/chunk-MI4UE2PQ.js +0 -561
  161. package/dist/chunk-PUKVXYYL.js +0 -52
  162. package/dist/chunk-QQS7I7ZL.js +0 -16
  163. package/dist/chunk-VAAMRG4K.js +0 -20
  164. package/dist/chunk-WFQJUJTC.js +0 -182
  165. package/dist/chunk-ZXIKIA5B.js +0 -178
  166. package/dist/concurrentCalls.cjs +0 -406
  167. package/dist/concurrentCalls.d.cts +0 -116
  168. package/dist/concurrentCalls.js +0 -346
  169. package/dist/consoleFmt.cjs +0 -85
  170. package/dist/consoleFmt.d.cts +0 -54
  171. package/dist/consoleFmt.d.ts +0 -54
  172. package/dist/consoleFmt.js +0 -60
  173. package/dist/conversions.cjs +0 -44
  174. package/dist/conversions.d.cts +0 -3
  175. package/dist/conversions.d.ts +0 -3
  176. package/dist/conversions.js +0 -6
  177. package/dist/createThrottleController.cjs +0 -193
  178. package/dist/createThrottleController.d.cts +0 -13
  179. package/dist/createThrottleController.d.ts +0 -13
  180. package/dist/createThrottleController.js +0 -61
  181. package/dist/debounce.cjs +0 -157
  182. package/dist/debounce.d.cts +0 -46
  183. package/dist/debounce.d.ts +0 -46
  184. package/dist/debounce.js +0 -8
  185. package/dist/dedent.cjs +0 -104
  186. package/dist/dedent.d.cts +0 -73
  187. package/dist/dedent.d.ts +0 -73
  188. package/dist/dedent.js +0 -79
  189. package/dist/deepEqual.cjs +0 -96
  190. package/dist/deepEqual.d.ts +0 -21
  191. package/dist/deepEqual.js +0 -8
  192. package/dist/deepReplaceValues.cjs +0 -87
  193. package/dist/deepReplaceValues.d.ts +0 -27
  194. package/dist/deepReplaceValues.js +0 -7
  195. package/dist/enhancedMap.cjs +0 -131
  196. package/dist/enhancedMap.d.cts +0 -20
  197. package/dist/enhancedMap.d.ts +0 -20
  198. package/dist/enhancedMap.js +0 -10
  199. package/dist/exhaustiveMatch.cjs +0 -66
  200. package/dist/exhaustiveMatch.d.cts +0 -9
  201. package/dist/exhaustiveMatch.d.ts +0 -9
  202. package/dist/exhaustiveMatch.js +0 -40
  203. package/dist/filterObjectOrArrayKeys.cjs +0 -619
  204. package/dist/filterObjectOrArrayKeys.d.ts +0 -88
  205. package/dist/filterObjectOrArrayKeys.js +0 -9
  206. package/dist/getAutoIncrementId.cjs +0 -44
  207. package/dist/getAutoIncrementId.d.ts +0 -46
  208. package/dist/getAutoIncrementId.js +0 -18
  209. package/dist/getCompositeKey.cjs +0 -86
  210. package/dist/getCompositeKey.d.ts +0 -11
  211. package/dist/getCompositeKey.js +0 -8
  212. package/dist/getValueStableKey.cjs +0 -89
  213. package/dist/getValueStableKey.d.ts +0 -15
  214. package/dist/getValueStableKey.js +0 -11
  215. package/dist/hash.cjs +0 -57
  216. package/dist/hash.d.ts +0 -7
  217. package/dist/hash.js +0 -32
  218. package/dist/interpolate.cjs +0 -88
  219. package/dist/interpolate.d.cts +0 -11
  220. package/dist/interpolate.d.ts +0 -11
  221. package/dist/interpolate.js +0 -46
  222. package/dist/iteratorUtils.cjs +0 -73
  223. package/dist/iteratorUtils.d.ts +0 -10
  224. package/dist/iteratorUtils.js +0 -44
  225. package/dist/keepPrevIfUnchanged.cjs +0 -102
  226. package/dist/keepPrevIfUnchanged.d.cts +0 -7
  227. package/dist/keepPrevIfUnchanged.d.ts +0 -7
  228. package/dist/keepPrevIfUnchanged.js +0 -7
  229. package/dist/keyedMap.cjs +0 -224
  230. package/dist/keyedMap.d.cts +0 -75
  231. package/dist/keyedMap.d.ts +0 -75
  232. package/dist/keyedMap.js +0 -145
  233. package/dist/keyedSet.cjs +0 -205
  234. package/dist/keyedSet.d.cts +0 -76
  235. package/dist/keyedSet.d.ts +0 -76
  236. package/dist/keyedSet.js +0 -126
  237. package/dist/levenshtein.cjs +0 -180
  238. package/dist/levenshtein.d.ts +0 -5
  239. package/dist/levenshtein.js +0 -153
  240. package/dist/main.cjs +0 -32
  241. package/dist/main.d.cts +0 -3
  242. package/dist/main.d.ts +0 -3
  243. package/dist/main.js +0 -7
  244. package/dist/matchPath.cjs +0 -155
  245. package/dist/matchPath.d.cts +0 -53
  246. package/dist/matchPath.d.ts +0 -53
  247. package/dist/matchPath.js +0 -108
  248. package/dist/mathUtils.cjs +0 -81
  249. package/dist/mathUtils.d.ts +0 -54
  250. package/dist/mathUtils.js +0 -22
  251. package/dist/mutationUtils.cjs +0 -153
  252. package/dist/mutationUtils.d.ts +0 -15
  253. package/dist/mutationUtils.js +0 -55
  254. package/dist/objUtils.cjs +0 -242
  255. package/dist/objUtils.d.cts +0 -28
  256. package/dist/objUtils.js +0 -38
  257. package/dist/parallelAsyncCalls.cjs +0 -162
  258. package/dist/parallelAsyncCalls.d.cts +0 -82
  259. package/dist/parallelAsyncCalls.d.ts +0 -82
  260. package/dist/parallelAsyncCalls.js +0 -126
  261. package/dist/partialEqual.cjs +0 -1196
  262. package/dist/partialEqual.d.cts +0 -141
  263. package/dist/partialEqual.d.ts +0 -141
  264. package/dist/partialEqual.js +0 -1168
  265. package/dist/promiseUtils.cjs +0 -38
  266. package/dist/promiseUtils.d.cts +0 -8
  267. package/dist/promiseUtils.d.ts +0 -8
  268. package/dist/promiseUtils.js +0 -6
  269. package/dist/regexUtils.cjs +0 -60
  270. package/dist/regexUtils.d.cts +0 -17
  271. package/dist/regexUtils.d.ts +0 -17
  272. package/dist/regexUtils.js +0 -33
  273. package/dist/retryOnError.cjs +0 -130
  274. package/dist/retryOnError.d.ts +0 -83
  275. package/dist/retryOnError.js +0 -101
  276. package/dist/runShellCmd.cjs +0 -127
  277. package/dist/runShellCmd.d.cts +0 -90
  278. package/dist/runShellCmd.js +0 -98
  279. package/dist/safeJson.cjs +0 -45
  280. package/dist/safeJson.d.ts +0 -16
  281. package/dist/safeJson.js +0 -8
  282. package/dist/saferTyping.cjs +0 -52
  283. package/dist/saferTyping.d.ts +0 -47
  284. package/dist/saferTyping.js +0 -23
  285. package/dist/serializeXML.cjs +0 -154
  286. package/dist/serializeXML.d.cts +0 -22
  287. package/dist/serializeXML.d.ts +0 -22
  288. package/dist/serializeXML.js +0 -116
  289. package/dist/shallowEqual.cjs +0 -88
  290. package/dist/shallowEqual.d.ts +0 -4
  291. package/dist/shallowEqual.js +0 -63
  292. package/dist/sleep.cjs +0 -32
  293. package/dist/sleep.d.cts +0 -3
  294. package/dist/sleep.d.ts +0 -3
  295. package/dist/sleep.js +0 -6
  296. package/dist/stringUtils.cjs +0 -155
  297. package/dist/stringUtils.d.ts +0 -55
  298. package/dist/stringUtils.js +0 -50
  299. package/dist/testUtils.cjs +0 -1490
  300. package/dist/testUtils.d.cts +0 -133
  301. package/dist/testUtils.js +0 -359
  302. package/dist/throttle.cjs +0 -282
  303. package/dist/throttle.d.cts +0 -98
  304. package/dist/throttle.js +0 -38
  305. package/dist/time.cjs +0 -152
  306. package/dist/time.d.cts +0 -25
  307. package/dist/time.js +0 -38
  308. package/dist/timers.cjs +0 -194
  309. package/dist/timers.d.ts +0 -121
  310. package/dist/timers.js +0 -156
  311. package/dist/tsResult.cjs +0 -226
  312. package/dist/tsResult.d.ts +0 -114
  313. package/dist/tsResult.js +0 -180
  314. package/dist/typeGuards.cjs +0 -70
  315. package/dist/typeGuards.d.ts +0 -111
  316. package/dist/typeGuards.js +0 -18
  317. package/dist/typeUtils.cjs +0 -18
  318. package/dist/typeUtils.d.cts +0 -61
  319. package/dist/typeUtils.js +0 -0
  320. package/dist/typedStrings.cjs +0 -90
  321. package/dist/typedStrings.d.ts +0 -163
  322. package/dist/typedStrings.js +0 -57
  323. package/dist/typingFnUtils.cjs +0 -96
  324. package/dist/typingFnUtils.d.ts +0 -100
  325. package/dist/typingFnUtils.js +0 -30
  326. package/dist/typingTestUtils.cjs +0 -52
  327. package/dist/typingTestUtils.d.ts +0 -79
  328. package/dist/typingTestUtils.js +0 -27
  329. package/dist/typingUtils.cjs +0 -18
  330. package/dist/typingUtils.d.cts +0 -35
  331. package/dist/typingUtils.d.ts +0 -35
  332. package/dist/typingUtils.js +0 -0
  333. package/dist/yamlStringify.cjs +0 -423
  334. package/dist/yamlStringify.d.cts +0 -10
  335. package/dist/yamlStringify.d.ts +0 -10
  336. package/dist/yamlStringify.js +0 -9
@@ -0,0 +1,424 @@
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
+ */
10
+ function diffParser(input) {
11
+ if (!input) return [];
12
+ if (typeof input !== "string" || input.match(/^\s+$/)) return [];
13
+ const lines = input.split("\n");
14
+ if (lines.length === 0) return [];
15
+ const files = [];
16
+ let currentFile = null;
17
+ let currentChunk = null;
18
+ let deletedLineCounter = 0;
19
+ let addedLineCounter = 0;
20
+ let currentFileChanges = null;
21
+ let fromLineCount = 0;
22
+ let pendingFroms;
23
+ const normal = (line) => {
24
+ currentChunk?.changes.push({
25
+ type: "normal",
26
+ normal: true,
27
+ ln1: deletedLineCounter++,
28
+ ln2: addedLineCounter++,
29
+ content: line
30
+ });
31
+ if (currentFileChanges) {
32
+ currentFileChanges.oldLines--;
33
+ currentFileChanges.newLines--;
34
+ }
35
+ };
36
+ const start = (line) => {
37
+ const [fromFileName, toFileName] = parseFiles(line) ?? [];
38
+ currentFile = {
39
+ type: "modified",
40
+ chunks: [],
41
+ deletions: 0,
42
+ additions: 0,
43
+ from: fromFileName,
44
+ to: toFileName,
45
+ oldMode: void 0,
46
+ newMode: void 0,
47
+ index: void 0,
48
+ diff: void 0,
49
+ rawDiff: ""
50
+ };
51
+ fromLineCount = 0;
52
+ pendingFroms = void 0;
53
+ files.push(currentFile);
54
+ };
55
+ const restart = () => {
56
+ if (!currentFile || currentFile.chunks.length) start();
57
+ };
58
+ const newFile = (_, match) => {
59
+ restart();
60
+ if (currentFile) {
61
+ currentFile.type = "new";
62
+ currentFile.newMode = match[1];
63
+ currentFile.from = "/dev/null";
64
+ }
65
+ };
66
+ const deletedFile = (_, match) => {
67
+ restart();
68
+ if (currentFile) {
69
+ currentFile.type = "deleted";
70
+ currentFile.oldMode = match[1];
71
+ currentFile.to = "/dev/null";
72
+ }
73
+ };
74
+ const oldMode = (_, match) => {
75
+ restart();
76
+ if (currentFile) currentFile.oldMode = match[1];
77
+ };
78
+ const newMode = (_, match) => {
79
+ restart();
80
+ if (currentFile) currentFile.newMode = match[1];
81
+ };
82
+ const index = (line, match) => {
83
+ restart();
84
+ if (currentFile) {
85
+ currentFile.index = line.split(" ").slice(1);
86
+ if (match[1]) currentFile.oldMode = currentFile.newMode = match[1].trim();
87
+ }
88
+ };
89
+ const similarityIndex = (_, match) => {
90
+ restart();
91
+ if (currentFile) {
92
+ const renamedFile = ensureRenamedFile(currentFile);
93
+ renamedFile.similarityIndex = Number(match[1]);
94
+ }
95
+ };
96
+ const indexFile = (line) => {
97
+ start(line);
98
+ };
99
+ const renameFrom = (line) => {
100
+ restart();
101
+ if (currentFile) {
102
+ const renamedFile = ensureRenamedFile(currentFile);
103
+ renamedFile.from = parseOldOrNewFile(line, "rename from ");
104
+ }
105
+ };
106
+ const renameTo = (line) => {
107
+ restart();
108
+ if (currentFile) {
109
+ const renamedFile = ensureRenamedFile(currentFile);
110
+ renamedFile.to = parseOldOrNewFile(line, "rename to ");
111
+ }
112
+ };
113
+ const binaryFiles = () => {
114
+ restart();
115
+ if (currentFile) currentFile.type = "binary";
116
+ };
117
+ const fromFile = (line) => {
118
+ restart();
119
+ if (currentFile) {
120
+ const fileName = parseOldOrNewFile(line);
121
+ if (fromLineCount === 0) {
122
+ currentFile.from = fileName;
123
+ fromLineCount = 1;
124
+ return;
125
+ }
126
+ const froms = pendingFroms ?? (currentFile.from ? [currentFile.from] : []);
127
+ if (!froms.includes(fileName)) froms.push(fileName);
128
+ pendingFroms = froms;
129
+ fromLineCount++;
130
+ }
131
+ };
132
+ const toFile = (line) => {
133
+ restart();
134
+ if (currentFile) currentFile.to = parseOldOrNewFile(line);
135
+ };
136
+ const toNumOfLines = (number) => Number(number || 1);
137
+ const parseRange = (range, prefix) => {
138
+ if (!range.startsWith(prefix)) return null;
139
+ const [rangeStart, rangeLines] = range.slice(1).split(",");
140
+ const startNumber = Number(rangeStart);
141
+ if (!Number.isFinite(startNumber)) return null;
142
+ return {
143
+ start: startNumber,
144
+ lines: toNumOfLines(rangeLines)
145
+ };
146
+ };
147
+ const parseCombinedChunkHeader = (line) => {
148
+ const atCount = line.match(/^(@{3,})\s/)?.[1]?.length;
149
+ if (!atCount) return;
150
+ if (!line.match(/* @__PURE__ */ new RegExp(`\\s@{${atCount}}$`))) return;
151
+ const parts = line.slice(atCount, line.length - atCount).trim().split(/\s+/);
152
+ if (parts.length < 2) return;
153
+ const newPart = parts.at(-1);
154
+ if (!newPart?.startsWith("+")) return;
155
+ const parentParts = parts.slice(0, -1);
156
+ const parentRanges = [];
157
+ for (const part of parentParts) {
158
+ const range = parseRange(part, "-");
159
+ if (!range) return;
160
+ parentRanges.push(range);
161
+ }
162
+ const newRange = parseRange(newPart, "+");
163
+ if (!newRange) return;
164
+ return {
165
+ parentRanges,
166
+ newRange,
167
+ parentCount: parentRanges.length
168
+ };
169
+ };
170
+ const combinedChunk = (line) => {
171
+ if (!currentFile) start(line);
172
+ const parsedHeader = parseCombinedChunkHeader(line);
173
+ if (!parsedHeader) return;
174
+ const [firstParent] = parsedHeader.parentRanges;
175
+ const oldStartNum = firstParent?.start ?? 0;
176
+ const oldLinesNum = firstParent?.lines ?? 0;
177
+ deletedLineCounter = oldStartNum;
178
+ addedLineCounter = parsedHeader.newRange.start;
179
+ currentChunk = {
180
+ content: line,
181
+ changes: [],
182
+ oldStart: oldStartNum,
183
+ oldLines: oldLinesNum,
184
+ newStart: parsedHeader.newRange.start,
185
+ newLines: parsedHeader.newRange.lines,
186
+ combined: true,
187
+ parentCount: parsedHeader.parentCount,
188
+ oldRanges: parsedHeader.parentRanges
189
+ };
190
+ currentFileChanges = {
191
+ oldLines: oldLinesNum,
192
+ newLines: parsedHeader.newRange.lines,
193
+ combined: true,
194
+ parentCount: parsedHeader.parentCount,
195
+ parentLines: parsedHeader.parentRanges.map((range) => range.lines)
196
+ };
197
+ if (currentFile) {
198
+ const combinedFile = ensureCombinedFile(currentFile);
199
+ combinedFile.froms = pendingFroms;
200
+ }
201
+ currentFile?.chunks.push(currentChunk);
202
+ };
203
+ const chunk = (line, match) => {
204
+ if (!currentFile) start(line);
205
+ const [oldStart, oldNumLines, newStart, newNumLines] = match.slice(1);
206
+ const oldStartNum = Number(oldStart ?? 0);
207
+ const newStartNum = Number(newStart ?? 0);
208
+ deletedLineCounter = oldStartNum;
209
+ addedLineCounter = newStartNum;
210
+ currentChunk = {
211
+ content: line,
212
+ changes: [],
213
+ oldStart: oldStartNum,
214
+ oldLines: toNumOfLines(oldNumLines),
215
+ newStart: newStartNum,
216
+ newLines: toNumOfLines(newNumLines)
217
+ };
218
+ currentFileChanges = {
219
+ oldLines: toNumOfLines(oldNumLines),
220
+ newLines: toNumOfLines(newNumLines)
221
+ };
222
+ currentFile?.chunks.push(currentChunk);
223
+ };
224
+ const del = (line) => {
225
+ if (!currentChunk || !currentFile || !currentFileChanges) return;
226
+ currentChunk.changes.push({
227
+ type: "del",
228
+ del: true,
229
+ ln: deletedLineCounter++,
230
+ content: line
231
+ });
232
+ currentFile.deletions++;
233
+ currentFileChanges.oldLines--;
234
+ };
235
+ const add = (line) => {
236
+ if (!currentChunk || !currentFile || !currentFileChanges) return;
237
+ currentChunk.changes.push({
238
+ type: "add",
239
+ add: true,
240
+ ln: addedLineCounter++,
241
+ content: line
242
+ });
243
+ currentFile.additions++;
244
+ currentFileChanges.newLines--;
245
+ };
246
+ const eof = (line) => {
247
+ if (!currentChunk) return;
248
+ const [mostRecentChange] = currentChunk.changes.slice(-1);
249
+ if (!mostRecentChange) return;
250
+ currentChunk.changes.push({
251
+ type: mostRecentChange.type,
252
+ [mostRecentChange.type]: true,
253
+ ln1: mostRecentChange.ln1,
254
+ ln2: mostRecentChange.ln2,
255
+ ln: mostRecentChange.ln,
256
+ content: line
257
+ });
258
+ };
259
+ const parseCombinedContentLine = (line) => {
260
+ if (!currentChunk || !currentFile || !currentFileChanges) return;
261
+ if (line.match(/^\$/)) {
262
+ eof(line);
263
+ return;
264
+ }
265
+ const parentCount = currentChunk.parentCount ?? currentFileChanges.parentCount ?? currentFileChanges.parentLines?.length ?? 0;
266
+ const parentLines = currentFileChanges.parentLines;
267
+ if (!parentLines || parentCount <= 0) return;
268
+ const prefix = line.slice(0, parentCount);
269
+ const lineInResult = !prefix.includes("-");
270
+ const isLineInParent = (marker) => {
271
+ if (marker === "-") return true;
272
+ if (marker === "+") return false;
273
+ return lineInResult;
274
+ };
275
+ const lineInFirstParent = isLineInParent(prefix[0] ?? " ");
276
+ if (lineInResult && !lineInFirstParent) {
277
+ currentChunk.changes.push({
278
+ type: "add",
279
+ add: true,
280
+ ln: addedLineCounter++,
281
+ content: line
282
+ });
283
+ currentFile.additions++;
284
+ currentFileChanges.newLines--;
285
+ } else if (!lineInResult && lineInFirstParent) {
286
+ currentChunk.changes.push({
287
+ type: "del",
288
+ del: true,
289
+ ln: deletedLineCounter++,
290
+ content: line
291
+ });
292
+ currentFile.deletions++;
293
+ currentFileChanges.oldLines--;
294
+ } else if (lineInResult && lineInFirstParent) {
295
+ currentChunk.changes.push({
296
+ type: "normal",
297
+ normal: true,
298
+ ln1: deletedLineCounter++,
299
+ ln2: addedLineCounter++,
300
+ content: line
301
+ });
302
+ currentFileChanges.oldLines--;
303
+ currentFileChanges.newLines--;
304
+ } else currentChunk.changes.push({
305
+ type: "normal",
306
+ normal: true,
307
+ content: line
308
+ });
309
+ for (let i = 0; i < parentLines.length; i++) {
310
+ if (!isLineInParent(prefix[i] ?? " ")) continue;
311
+ const parentLine = parentLines[i];
312
+ if (parentLine !== void 0) parentLines[i] = parentLine - 1;
313
+ }
314
+ };
315
+ const schemaHeaders = [
316
+ [/^Index:\s/, indexFile],
317
+ [/^diff\s/, start],
318
+ [/^new file mode (\d+)$/, newFile],
319
+ [/^deleted file mode (\d+)$/, deletedFile],
320
+ [/^old mode (\d+)$/, oldMode],
321
+ [/^new mode (\d+)$/, newMode],
322
+ [/^similarity index (\d+)%/, similarityIndex],
323
+ [/^rename from /, renameFrom],
324
+ [/^rename to /, renameTo],
325
+ [/^Binary files .* and .* differ$/, binaryFiles],
326
+ [/^index\s[\da-zA-Z]+(?:,[\da-zA-Z]+)*\.\.[\da-zA-Z]+(?:\s(\d+))?$/, index],
327
+ [/^---\s/, fromFile],
328
+ [/^\+\+\+\s/, toFile],
329
+ [/^@{3,}\s/, combinedChunk],
330
+ [/^@@\s+-(\d+),?(\d+)?\s+\+(\d+),?(\d+)?\s@@/, chunk],
331
+ [/^\$/, eof]
332
+ ];
333
+ const schemaContent = [
334
+ [/^\$/, eof],
335
+ [/^-/, del],
336
+ [/^\+/, add],
337
+ [/^\s+/, normal]
338
+ ];
339
+ const parseContentLine = (line) => {
340
+ if (currentFileChanges?.combined) {
341
+ parseCombinedContentLine(line);
342
+ const parentLines = currentFileChanges.parentLines;
343
+ if (parentLines && parentLines.every((count) => count === 0) && currentFileChanges.newLines === 0) currentFileChanges = null;
344
+ return;
345
+ }
346
+ for (const [pattern, handler] of schemaContent) {
347
+ const match = line.match(pattern);
348
+ if (match) {
349
+ handler(line, match);
350
+ break;
351
+ }
352
+ }
353
+ if (currentFileChanges && currentFileChanges.oldLines === 0 && currentFileChanges.newLines === 0) currentFileChanges = null;
354
+ };
355
+ const parseHeaderLine = (line) => {
356
+ for (const [pattern, handler] of schemaHeaders) {
357
+ const match = line.match(pattern);
358
+ if (match) {
359
+ handler(line, match);
360
+ break;
361
+ }
362
+ }
363
+ };
364
+ const parseLine = (line) => {
365
+ if (currentFileChanges) parseContentLine(line);
366
+ else parseHeaderLine(line);
367
+ if (currentFile) currentFile.rawDiff = currentFile.rawDiff.length === 0 ? line : `${currentFile.rawDiff}\n${line}`;
368
+ };
369
+ for (const line of lines) parseLine(line);
370
+ for (const file of files) {
371
+ if (file.chunks.length === 0) continue;
372
+ const diffLines = [];
373
+ for (const fileChunk of file.chunks) {
374
+ diffLines.push(fileChunk.content);
375
+ for (const change of fileChunk.changes) diffLines.push(change.content);
376
+ }
377
+ file.diff = diffLines.join("\n");
378
+ }
379
+ return files;
380
+ }
381
+ const ensureRenamedFile = (file) => {
382
+ const renamedFile = file;
383
+ renamedFile.type = "renamed";
384
+ renamedFile.similarityIndex ??= void 0;
385
+ return renamedFile;
386
+ };
387
+ const ensureCombinedFile = (file) => {
388
+ const combinedFile = file;
389
+ combinedFile.type = "combined";
390
+ combinedFile.froms ??= void 0;
391
+ return combinedFile;
392
+ };
393
+ const fileNameDiffRegex = /(a|i|w|c|o|1|2)\/.*(?=["']? ["']?(b|i|w|c|o|1|2)\/)|(b|i|w|c|o|1|2)\/.*$/g;
394
+ const gitFileHeaderRegex = /^(a|b|i|w|c|o|1|2)\//;
395
+ const parseFiles = (line) => {
396
+ return (line?.match(fileNameDiffRegex))?.map((fileName) => fileName.replace(gitFileHeaderRegex, "").replace(/("|')$/, ""));
397
+ };
398
+ const quotedFileNameRegex = /^\\?['"]|\\?['"]$/g;
399
+ const parseOldOrNewFile = (line, prefix) => {
400
+ let fileName;
401
+ if (prefix) fileName = line.slice(prefix.length);
402
+ else fileName = leftTrimChars(line, "-+").trim();
403
+ fileName = removeTimeStamp(fileName);
404
+ return fileName.replace(quotedFileNameRegex, "").replace(gitFileHeaderRegex, "");
405
+ };
406
+ const leftTrimChars = (input, trimmingChars) => {
407
+ if (!trimmingChars) return input.trimStart();
408
+ const trimmingString = formTrimmingString(trimmingChars);
409
+ return input.replace(/* @__PURE__ */ new RegExp(`^${trimmingString}+`), "");
410
+ };
411
+ const timeStampRegex = /\t.*|\d{4}-\d\d-\d\d\s\d\d:\d\d:\d\d(.\d+)?\s(\+|-)\d\d\d\d/;
412
+ const removeTimeStamp = (input) => {
413
+ const timeStamp = timeStampRegex.exec(input);
414
+ if (timeStamp) return input.substring(0, timeStamp.index).trim();
415
+ return input;
416
+ };
417
+ const formTrimmingString = (trimmingChars) => {
418
+ if (trimmingChars === null || trimmingChars === void 0) return "\\s";
419
+ else if (trimmingChars instanceof RegExp) return trimmingChars.source;
420
+ return `[${trimmingChars.replace(/([.*+?^=!:${}()|[\]/\\])/g, "\\$1")}]`;
421
+ };
422
+
423
+ //#endregion
424
+ export { diffParser };
@@ -0,0 +1,21 @@
1
+ //#region src/enhancedMap.d.ts
2
+ declare const enhancedMapReject: unique symbol;
3
+ declare class EnhancedMap<K, V> extends Map<K, V> {
4
+ find(predicate: (value: V, key: K) => boolean): {
5
+ key: K;
6
+ value: V;
7
+ } | undefined;
8
+ setMultiple(values: Record<K & string, V>): this;
9
+ setMultiple(...values: [key: K, value: V][]): this;
10
+ getOrThrow(key: K): V;
11
+ getOrInsert(key: K, fallback: () => V): V;
12
+ toFilteredValues(predicate: (value: V, key: K) => boolean): V[];
13
+ toMap<T>(mapFunction: (value: V, key: K, reject: typeof enhancedMapReject) => T | typeof enhancedMapReject): T[];
14
+ toObjMap<ObjKey extends PropertyKey, ObjValue>(mapFunction: (value: V, key: K) => [key: ObjKey, value: ObjValue] | false): Record<ObjKey, ObjValue>;
15
+ toValues(): V[];
16
+ toKeys(): K[];
17
+ static from<T extends Record<string, unknown>, K extends keyof T>(array: T[] | Iterable<T> | null | undefined, key: K): EnhancedMap<T[K], T>;
18
+ static from<T, K, V>(array: T[] | Iterable<T> | null | undefined, mapFunction: (item: T) => [key: K, value: V] | false): EnhancedMap<K, V>;
19
+ }
20
+ //#endregion
21
+ export { EnhancedMap, enhancedMapReject };
@@ -0,0 +1,69 @@
1
+ import { a as isFunction } from "./assertions-qMxfVhSu.mjs";
2
+
3
+ //#region src/enhancedMap.ts
4
+ const enhancedMapReject = Symbol();
5
+ var EnhancedMap = class EnhancedMap extends Map {
6
+ find(predicate) {
7
+ for (const [key, value] of this) if (predicate(value, key)) return {
8
+ key,
9
+ value
10
+ };
11
+ }
12
+ setMultiple(...values) {
13
+ if (Array.isArray(values[0])) for (const [key, value] of values) this.set(key, value);
14
+ else for (const [key, value] of Object.entries(values[0])) this.set(key, value);
15
+ return this;
16
+ }
17
+ getOrThrow(key) {
18
+ const value = this.get(key);
19
+ if (value === void 0) throw new Error(`Key ${key} not found in EnhancedMap`);
20
+ return value;
21
+ }
22
+ getOrInsert(key, fallback) {
23
+ if (!this.has(key)) this.set(key, fallback());
24
+ return this.getOrThrow(key);
25
+ }
26
+ toFilteredValues(predicate) {
27
+ const values = [];
28
+ for (const [key, value] of this) if (predicate(value, key)) values.push(value);
29
+ return values;
30
+ }
31
+ toMap(mapFunction) {
32
+ const values = [];
33
+ for (const [key, value] of this) {
34
+ const result = mapFunction(value, key, enhancedMapReject);
35
+ if (result !== enhancedMapReject) values.push(result);
36
+ }
37
+ return values;
38
+ }
39
+ toObjMap(mapFunction) {
40
+ const values = {};
41
+ for (const [key, value] of this) {
42
+ const result = mapFunction(value, key);
43
+ if (result) values[result[0]] = result[1];
44
+ }
45
+ return values;
46
+ }
47
+ toValues() {
48
+ return [...this.values()];
49
+ }
50
+ toKeys() {
51
+ return [...this.keys()];
52
+ }
53
+ static from(array, mapFunction) {
54
+ const map = new EnhancedMap();
55
+ if (!array) return map;
56
+ const isFn = isFunction(mapFunction);
57
+ for (const item of array) if (isFn) {
58
+ const result = mapFunction(item);
59
+ if (result) map.set(result[0], result[1]);
60
+ } else {
61
+ const key = item[mapFunction];
62
+ if (key !== void 0) map.set(key, item);
63
+ }
64
+ return map;
65
+ }
66
+ };
67
+
68
+ //#endregion
69
+ export { EnhancedMap, enhancedMapReject };
@@ -0,0 +1,10 @@
1
+ //#region src/exhaustiveMatch.d.ts
2
+ declare function exhaustiveMatch<T extends string>(value: T): {
3
+ with: <R>(pattern: { [K in T]: "_nxt" | "_never" | (() => R) }) => R;
4
+ withObject: <R>(pattern: Record<T, R>) => R;
5
+ };
6
+ declare function exhaustiveMatchObjUnion<T extends Record<string, unknown>, D extends keyof T, K extends T[D] & string>(obj: T, key: D): {
7
+ with: <R>(pattern: { [P in K]: "_never" | ((props: Extract<T, Record<D, P>>) => R) }) => R;
8
+ };
9
+ //#endregion
10
+ export { exhaustiveMatch, exhaustiveMatchObjUnion };
@@ -0,0 +1,48 @@
1
+ //#region src/exhaustiveMatch.ts
2
+ function exhaustiveMatch(value) {
3
+ /**
4
+ * The pattern can be:
5
+ *
6
+ * - A function that returns the result
7
+ * - '_nxt' to try the next pattern
8
+ * - '_never' to indicate that this pattern should never be matched
9
+ *
10
+ * @param pattern
11
+ */
12
+ function matchWith(pattern) {
13
+ const result = pattern[value];
14
+ if (typeof result === "function") return result();
15
+ if (result === "_nxt") {
16
+ const keys = Object.keys(pattern);
17
+ const nextIndex = keys.indexOf(value) + 1;
18
+ for (let i = nextIndex; i < keys.length; i++) {
19
+ const nextMatch = pattern[keys[i]];
20
+ if (typeof nextMatch === "function") return nextMatch();
21
+ }
22
+ }
23
+ throw new Error(`Exhaustive match failed: no match for ${value}`);
24
+ }
25
+ /**
26
+ * Match with early evaluation of the values
27
+ *
28
+ * @param pattern
29
+ */
30
+ function withObject(pattern) {
31
+ return pattern[value];
32
+ }
33
+ return {
34
+ with: matchWith,
35
+ withObject
36
+ };
37
+ }
38
+ function exhaustiveMatchObjUnion(obj, key) {
39
+ function withLazy(pattern) {
40
+ const result = pattern[obj[key]];
41
+ if (typeof result === "function") return result(obj);
42
+ throw new Error(`Exhaustive match failed: no match for ${obj[key]}`);
43
+ }
44
+ return { with: withLazy };
45
+ }
46
+
47
+ //#endregion
48
+ export { exhaustiveMatch, exhaustiveMatchObjUnion };
@@ -1,3 +1,4 @@
1
+ //#region src/filterObjectOrArrayKeys.d.ts
1
2
  /**
2
3
  * Filters the keys of an object based on the provided patterns.
3
4
  *
@@ -77,12 +78,18 @@
77
78
  * supported.
78
79
  * @returns The filtered object or array.
79
80
  */
80
- declare function filterObjectOrArrayKeys(objOrArray: Record<string, any> | Record<string, any>[], { filterKeys, rejectKeys, rejectEmptyObjectsInArray, sortKeys, sortPatterns, }: {
81
- filterKeys?: string[] | string;
82
- rejectKeys?: string[] | string;
83
- rejectEmptyObjectsInArray?: boolean;
84
- sortKeys?: 'asc' | 'desc' | 'simpleValuesFirst' | false;
85
- sortPatterns?: string[];
81
+ declare function filterObjectOrArrayKeys(objOrArray: Record<string, any> | Record<string, any>[], {
82
+ filterKeys,
83
+ rejectKeys,
84
+ rejectEmptyObjectsInArray,
85
+ sortKeys,
86
+ sortPatterns
87
+ }: {
88
+ filterKeys?: string[] | string;
89
+ rejectKeys?: string[] | string;
90
+ rejectEmptyObjectsInArray?: boolean;
91
+ sortKeys?: 'asc' | 'desc' | 'simpleValuesFirst' | false;
92
+ sortPatterns?: string[];
86
93
  }): Record<string, any> | Record<string, any>[];
87
-
88
- export { filterObjectOrArrayKeys };
94
+ //#endregion
95
+ export { filterObjectOrArrayKeys };