@ls-stack/utils 3.63.0 → 3.66.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 (328) 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 +63 -0
  34. package/dist/diffParser.mjs +410 -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 -234
  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/levenshtein.cjs +0 -180
  230. package/dist/levenshtein.d.ts +0 -5
  231. package/dist/levenshtein.js +0 -153
  232. package/dist/main.cjs +0 -32
  233. package/dist/main.d.cts +0 -3
  234. package/dist/main.d.ts +0 -3
  235. package/dist/main.js +0 -7
  236. package/dist/matchPath.cjs +0 -155
  237. package/dist/matchPath.d.cts +0 -53
  238. package/dist/matchPath.d.ts +0 -53
  239. package/dist/matchPath.js +0 -108
  240. package/dist/mathUtils.cjs +0 -81
  241. package/dist/mathUtils.d.ts +0 -54
  242. package/dist/mathUtils.js +0 -22
  243. package/dist/mutationUtils.cjs +0 -153
  244. package/dist/mutationUtils.d.ts +0 -15
  245. package/dist/mutationUtils.js +0 -55
  246. package/dist/objUtils.cjs +0 -242
  247. package/dist/objUtils.d.cts +0 -28
  248. package/dist/objUtils.js +0 -38
  249. package/dist/parallelAsyncCalls.cjs +0 -162
  250. package/dist/parallelAsyncCalls.d.cts +0 -82
  251. package/dist/parallelAsyncCalls.d.ts +0 -82
  252. package/dist/parallelAsyncCalls.js +0 -126
  253. package/dist/partialEqual.cjs +0 -1196
  254. package/dist/partialEqual.d.cts +0 -141
  255. package/dist/partialEqual.d.ts +0 -141
  256. package/dist/partialEqual.js +0 -1168
  257. package/dist/promiseUtils.cjs +0 -38
  258. package/dist/promiseUtils.d.cts +0 -8
  259. package/dist/promiseUtils.d.ts +0 -8
  260. package/dist/promiseUtils.js +0 -6
  261. package/dist/regexUtils.cjs +0 -60
  262. package/dist/regexUtils.d.cts +0 -17
  263. package/dist/regexUtils.d.ts +0 -17
  264. package/dist/regexUtils.js +0 -33
  265. package/dist/retryOnError.cjs +0 -130
  266. package/dist/retryOnError.d.ts +0 -83
  267. package/dist/retryOnError.js +0 -101
  268. package/dist/runShellCmd.cjs +0 -127
  269. package/dist/runShellCmd.d.cts +0 -90
  270. package/dist/runShellCmd.js +0 -98
  271. package/dist/safeJson.cjs +0 -45
  272. package/dist/safeJson.d.ts +0 -16
  273. package/dist/safeJson.js +0 -8
  274. package/dist/saferTyping.cjs +0 -52
  275. package/dist/saferTyping.d.ts +0 -47
  276. package/dist/saferTyping.js +0 -23
  277. package/dist/serializeXML.cjs +0 -154
  278. package/dist/serializeXML.d.cts +0 -22
  279. package/dist/serializeXML.d.ts +0 -22
  280. package/dist/serializeXML.js +0 -116
  281. package/dist/shallowEqual.cjs +0 -88
  282. package/dist/shallowEqual.d.ts +0 -4
  283. package/dist/shallowEqual.js +0 -63
  284. package/dist/sleep.cjs +0 -32
  285. package/dist/sleep.d.cts +0 -3
  286. package/dist/sleep.d.ts +0 -3
  287. package/dist/sleep.js +0 -6
  288. package/dist/stringUtils.cjs +0 -155
  289. package/dist/stringUtils.d.ts +0 -55
  290. package/dist/stringUtils.js +0 -50
  291. package/dist/testUtils.cjs +0 -1490
  292. package/dist/testUtils.d.cts +0 -133
  293. package/dist/testUtils.js +0 -359
  294. package/dist/throttle.cjs +0 -282
  295. package/dist/throttle.d.cts +0 -98
  296. package/dist/throttle.js +0 -38
  297. package/dist/time.cjs +0 -152
  298. package/dist/time.d.cts +0 -25
  299. package/dist/time.js +0 -38
  300. package/dist/timers.cjs +0 -194
  301. package/dist/timers.d.ts +0 -121
  302. package/dist/timers.js +0 -156
  303. package/dist/tsResult.cjs +0 -226
  304. package/dist/tsResult.d.ts +0 -114
  305. package/dist/tsResult.js +0 -180
  306. package/dist/typeGuards.cjs +0 -70
  307. package/dist/typeGuards.d.ts +0 -111
  308. package/dist/typeGuards.js +0 -18
  309. package/dist/typeUtils.cjs +0 -18
  310. package/dist/typeUtils.d.cts +0 -61
  311. package/dist/typeUtils.js +0 -0
  312. package/dist/typedStrings.cjs +0 -90
  313. package/dist/typedStrings.d.ts +0 -163
  314. package/dist/typedStrings.js +0 -57
  315. package/dist/typingFnUtils.cjs +0 -96
  316. package/dist/typingFnUtils.d.ts +0 -100
  317. package/dist/typingFnUtils.js +0 -30
  318. package/dist/typingTestUtils.cjs +0 -52
  319. package/dist/typingTestUtils.d.ts +0 -79
  320. package/dist/typingTestUtils.js +0 -27
  321. package/dist/typingUtils.cjs +0 -18
  322. package/dist/typingUtils.d.cts +0 -35
  323. package/dist/typingUtils.d.ts +0 -35
  324. package/dist/typingUtils.js +0 -0
  325. package/dist/yamlStringify.cjs +0 -423
  326. package/dist/yamlStringify.d.cts +0 -10
  327. package/dist/yamlStringify.d.ts +0 -10
  328. package/dist/yamlStringify.js +0 -9
@@ -0,0 +1,410 @@
1
+ //#region src/diffParser.ts
2
+ function diffParser(input) {
3
+ if (!input) return [];
4
+ if (typeof input !== "string" || input.match(/^\s+$/)) return [];
5
+ const lines = input.split("\n");
6
+ if (lines.length === 0) return [];
7
+ const files = [];
8
+ let currentFile = null;
9
+ let currentChunk = null;
10
+ let deletedLineCounter = 0;
11
+ let addedLineCounter = 0;
12
+ let currentFileChanges = null;
13
+ let fromLineCount = 0;
14
+ let pendingFroms;
15
+ const normal = (line) => {
16
+ currentChunk?.changes.push({
17
+ type: "normal",
18
+ normal: true,
19
+ ln1: deletedLineCounter++,
20
+ ln2: addedLineCounter++,
21
+ content: line
22
+ });
23
+ if (currentFileChanges) {
24
+ currentFileChanges.oldLines--;
25
+ currentFileChanges.newLines--;
26
+ }
27
+ };
28
+ const start = (line) => {
29
+ const [fromFileName, toFileName] = parseFiles(line) ?? [];
30
+ currentFile = {
31
+ type: "modified",
32
+ chunks: [],
33
+ deletions: 0,
34
+ additions: 0,
35
+ from: fromFileName,
36
+ to: toFileName,
37
+ oldMode: void 0,
38
+ newMode: void 0,
39
+ index: void 0,
40
+ diff: void 0
41
+ };
42
+ fromLineCount = 0;
43
+ pendingFroms = void 0;
44
+ files.push(currentFile);
45
+ };
46
+ const restart = () => {
47
+ if (!currentFile || currentFile.chunks.length) start();
48
+ };
49
+ const newFile = (_, match) => {
50
+ restart();
51
+ if (currentFile) {
52
+ currentFile.type = "new";
53
+ currentFile.newMode = match[1];
54
+ currentFile.from = "/dev/null";
55
+ }
56
+ };
57
+ const deletedFile = (_, match) => {
58
+ restart();
59
+ if (currentFile) {
60
+ currentFile.type = "deleted";
61
+ currentFile.oldMode = match[1];
62
+ currentFile.to = "/dev/null";
63
+ }
64
+ };
65
+ const oldMode = (_, match) => {
66
+ restart();
67
+ if (currentFile) currentFile.oldMode = match[1];
68
+ };
69
+ const newMode = (_, match) => {
70
+ restart();
71
+ if (currentFile) currentFile.newMode = match[1];
72
+ };
73
+ const index = (line, match) => {
74
+ restart();
75
+ if (currentFile) {
76
+ currentFile.index = line.split(" ").slice(1);
77
+ if (match[1]) currentFile.oldMode = currentFile.newMode = match[1].trim();
78
+ }
79
+ };
80
+ const similarityIndex = (_, match) => {
81
+ restart();
82
+ if (currentFile) {
83
+ const renamedFile = ensureRenamedFile(currentFile);
84
+ renamedFile.similarityIndex = Number(match[1]);
85
+ }
86
+ };
87
+ const renameFrom = (line) => {
88
+ restart();
89
+ if (currentFile) {
90
+ const renamedFile = ensureRenamedFile(currentFile);
91
+ renamedFile.from = parseOldOrNewFile(line, "rename from ");
92
+ }
93
+ };
94
+ const renameTo = (line) => {
95
+ restart();
96
+ if (currentFile) {
97
+ const renamedFile = ensureRenamedFile(currentFile);
98
+ renamedFile.to = parseOldOrNewFile(line, "rename to ");
99
+ }
100
+ };
101
+ const binaryFiles = () => {
102
+ restart();
103
+ if (currentFile) currentFile.type = "binary";
104
+ };
105
+ const fromFile = (line) => {
106
+ restart();
107
+ if (currentFile) {
108
+ const fileName = parseOldOrNewFile(line);
109
+ if (fromLineCount === 0) {
110
+ currentFile.from = fileName;
111
+ fromLineCount = 1;
112
+ return;
113
+ }
114
+ const froms = pendingFroms ?? (currentFile.from ? [currentFile.from] : []);
115
+ if (!froms.includes(fileName)) froms.push(fileName);
116
+ pendingFroms = froms;
117
+ fromLineCount++;
118
+ }
119
+ };
120
+ const toFile = (line) => {
121
+ restart();
122
+ if (currentFile) currentFile.to = parseOldOrNewFile(line);
123
+ };
124
+ const toNumOfLines = (number) => Number(number || 1);
125
+ const parseRange = (range, prefix) => {
126
+ if (!range.startsWith(prefix)) return null;
127
+ const [rangeStart, rangeLines] = range.slice(1).split(",");
128
+ const startNumber = Number(rangeStart);
129
+ if (!Number.isFinite(startNumber)) return null;
130
+ return {
131
+ start: startNumber,
132
+ lines: toNumOfLines(rangeLines)
133
+ };
134
+ };
135
+ const parseCombinedChunkHeader = (line) => {
136
+ const atCount = line.match(/^(@{3,})\s/)?.[1]?.length;
137
+ if (!atCount) return;
138
+ if (!line.match(/* @__PURE__ */ new RegExp(`\\s@{${atCount}}$`))) return;
139
+ const parts = line.slice(atCount, line.length - atCount).trim().split(/\s+/);
140
+ if (parts.length < 2) return;
141
+ const newPart = parts.at(-1);
142
+ if (!newPart?.startsWith("+")) return;
143
+ const parentParts = parts.slice(0, -1);
144
+ const parentRanges = [];
145
+ for (const part of parentParts) {
146
+ const range = parseRange(part, "-");
147
+ if (!range) return;
148
+ parentRanges.push(range);
149
+ }
150
+ const newRange = parseRange(newPart, "+");
151
+ if (!newRange) return;
152
+ return {
153
+ parentRanges,
154
+ newRange,
155
+ parentCount: parentRanges.length
156
+ };
157
+ };
158
+ const combinedChunk = (line) => {
159
+ if (!currentFile) start(line);
160
+ const parsedHeader = parseCombinedChunkHeader(line);
161
+ if (!parsedHeader) return;
162
+ const [firstParent] = parsedHeader.parentRanges;
163
+ const oldStartNum = firstParent?.start ?? 0;
164
+ const oldLinesNum = firstParent?.lines ?? 0;
165
+ deletedLineCounter = oldStartNum;
166
+ addedLineCounter = parsedHeader.newRange.start;
167
+ currentChunk = {
168
+ content: line,
169
+ changes: [],
170
+ oldStart: oldStartNum,
171
+ oldLines: oldLinesNum,
172
+ newStart: parsedHeader.newRange.start,
173
+ newLines: parsedHeader.newRange.lines,
174
+ combined: true,
175
+ parentCount: parsedHeader.parentCount,
176
+ oldRanges: parsedHeader.parentRanges
177
+ };
178
+ currentFileChanges = {
179
+ oldLines: oldLinesNum,
180
+ newLines: parsedHeader.newRange.lines,
181
+ combined: true,
182
+ parentCount: parsedHeader.parentCount,
183
+ parentLines: parsedHeader.parentRanges.map((range) => range.lines)
184
+ };
185
+ if (currentFile) {
186
+ const combinedFile = ensureCombinedFile(currentFile);
187
+ combinedFile.froms = pendingFroms;
188
+ }
189
+ currentFile?.chunks.push(currentChunk);
190
+ };
191
+ const chunk = (line, match) => {
192
+ if (!currentFile) start(line);
193
+ const [oldStart, oldNumLines, newStart, newNumLines] = match.slice(1);
194
+ const oldStartNum = Number(oldStart ?? 0);
195
+ const newStartNum = Number(newStart ?? 0);
196
+ deletedLineCounter = oldStartNum;
197
+ addedLineCounter = newStartNum;
198
+ currentChunk = {
199
+ content: line,
200
+ changes: [],
201
+ oldStart: oldStartNum,
202
+ oldLines: toNumOfLines(oldNumLines),
203
+ newStart: newStartNum,
204
+ newLines: toNumOfLines(newNumLines)
205
+ };
206
+ currentFileChanges = {
207
+ oldLines: toNumOfLines(oldNumLines),
208
+ newLines: toNumOfLines(newNumLines)
209
+ };
210
+ currentFile?.chunks.push(currentChunk);
211
+ };
212
+ const del = (line) => {
213
+ if (!currentChunk || !currentFile || !currentFileChanges) return;
214
+ currentChunk.changes.push({
215
+ type: "del",
216
+ del: true,
217
+ ln: deletedLineCounter++,
218
+ content: line
219
+ });
220
+ currentFile.deletions++;
221
+ currentFileChanges.oldLines--;
222
+ };
223
+ const add = (line) => {
224
+ if (!currentChunk || !currentFile || !currentFileChanges) return;
225
+ currentChunk.changes.push({
226
+ type: "add",
227
+ add: true,
228
+ ln: addedLineCounter++,
229
+ content: line
230
+ });
231
+ currentFile.additions++;
232
+ currentFileChanges.newLines--;
233
+ };
234
+ const eof = (line) => {
235
+ if (!currentChunk) return;
236
+ const [mostRecentChange] = currentChunk.changes.slice(-1);
237
+ if (!mostRecentChange) return;
238
+ currentChunk.changes.push({
239
+ type: mostRecentChange.type,
240
+ [mostRecentChange.type]: true,
241
+ ln1: mostRecentChange.ln1,
242
+ ln2: mostRecentChange.ln2,
243
+ ln: mostRecentChange.ln,
244
+ content: line
245
+ });
246
+ };
247
+ const parseCombinedContentLine = (line) => {
248
+ if (!currentChunk || !currentFile || !currentFileChanges) return;
249
+ if (line.match(/^\$/)) {
250
+ eof(line);
251
+ return;
252
+ }
253
+ const parentCount = currentChunk.parentCount ?? currentFileChanges.parentCount ?? currentFileChanges.parentLines?.length ?? 0;
254
+ const parentLines = currentFileChanges.parentLines;
255
+ if (!parentLines || parentCount <= 0) return;
256
+ const prefix = line.slice(0, parentCount);
257
+ const lineInResult = !prefix.includes("-");
258
+ const isLineInParent = (marker) => {
259
+ if (marker === "-") return true;
260
+ if (marker === "+") return false;
261
+ return lineInResult;
262
+ };
263
+ const lineInFirstParent = isLineInParent(prefix[0] ?? " ");
264
+ if (lineInResult && !lineInFirstParent) {
265
+ currentChunk.changes.push({
266
+ type: "add",
267
+ add: true,
268
+ ln: addedLineCounter++,
269
+ content: line
270
+ });
271
+ currentFile.additions++;
272
+ currentFileChanges.newLines--;
273
+ } else if (!lineInResult && lineInFirstParent) {
274
+ currentChunk.changes.push({
275
+ type: "del",
276
+ del: true,
277
+ ln: deletedLineCounter++,
278
+ content: line
279
+ });
280
+ currentFile.deletions++;
281
+ currentFileChanges.oldLines--;
282
+ } else if (lineInResult && lineInFirstParent) {
283
+ currentChunk.changes.push({
284
+ type: "normal",
285
+ normal: true,
286
+ ln1: deletedLineCounter++,
287
+ ln2: addedLineCounter++,
288
+ content: line
289
+ });
290
+ currentFileChanges.oldLines--;
291
+ currentFileChanges.newLines--;
292
+ } else currentChunk.changes.push({
293
+ type: "normal",
294
+ normal: true,
295
+ content: line
296
+ });
297
+ for (let i = 0; i < parentLines.length; i++) {
298
+ if (!isLineInParent(prefix[i] ?? " ")) continue;
299
+ const parentLine = parentLines[i];
300
+ if (parentLine !== void 0) parentLines[i] = parentLine - 1;
301
+ }
302
+ };
303
+ const schemaHeaders = [
304
+ [/^diff\s/, start],
305
+ [/^new file mode (\d+)$/, newFile],
306
+ [/^deleted file mode (\d+)$/, deletedFile],
307
+ [/^old mode (\d+)$/, oldMode],
308
+ [/^new mode (\d+)$/, newMode],
309
+ [/^similarity index (\d+)%/, similarityIndex],
310
+ [/^rename from /, renameFrom],
311
+ [/^rename to /, renameTo],
312
+ [/^Binary files .* and .* differ$/, binaryFiles],
313
+ [/^index\s[\da-zA-Z]+(?:,[\da-zA-Z]+)*\.\.[\da-zA-Z]+(?:\s(\d+))?$/, index],
314
+ [/^---\s/, fromFile],
315
+ [/^\+\+\+\s/, toFile],
316
+ [/^@{3,}\s/, combinedChunk],
317
+ [/^@@\s+-(\d+),?(\d+)?\s+\+(\d+),?(\d+)?\s@@/, chunk],
318
+ [/^\$/, eof]
319
+ ];
320
+ const schemaContent = [
321
+ [/^\$/, eof],
322
+ [/^-/, del],
323
+ [/^\+/, add],
324
+ [/^\s+/, normal]
325
+ ];
326
+ const parseContentLine = (line) => {
327
+ if (currentFileChanges?.combined) {
328
+ parseCombinedContentLine(line);
329
+ const parentLines = currentFileChanges.parentLines;
330
+ if (parentLines && parentLines.every((count) => count === 0) && currentFileChanges.newLines === 0) currentFileChanges = null;
331
+ return;
332
+ }
333
+ for (const [pattern, handler] of schemaContent) {
334
+ const match = line.match(pattern);
335
+ if (match) {
336
+ handler(line, match);
337
+ break;
338
+ }
339
+ }
340
+ if (currentFileChanges && currentFileChanges.oldLines === 0 && currentFileChanges.newLines === 0) currentFileChanges = null;
341
+ };
342
+ const parseHeaderLine = (line) => {
343
+ for (const [pattern, handler] of schemaHeaders) {
344
+ const match = line.match(pattern);
345
+ if (match) {
346
+ handler(line, match);
347
+ break;
348
+ }
349
+ }
350
+ };
351
+ const parseLine = (line) => {
352
+ if (currentFileChanges) parseContentLine(line);
353
+ else parseHeaderLine(line);
354
+ };
355
+ for (const line of lines) parseLine(line);
356
+ for (const file of files) {
357
+ if (file.chunks.length === 0) continue;
358
+ const diffLines = [];
359
+ for (const fileChunk of file.chunks) {
360
+ diffLines.push(fileChunk.content);
361
+ for (const change of fileChunk.changes) diffLines.push(change.content);
362
+ }
363
+ file.diff = diffLines.join("\n");
364
+ }
365
+ return files;
366
+ }
367
+ const ensureRenamedFile = (file) => {
368
+ const renamedFile = file;
369
+ renamedFile.type = "renamed";
370
+ renamedFile.similarityIndex ??= void 0;
371
+ return renamedFile;
372
+ };
373
+ const ensureCombinedFile = (file) => {
374
+ const combinedFile = file;
375
+ combinedFile.type = "combined";
376
+ combinedFile.froms ??= void 0;
377
+ return combinedFile;
378
+ };
379
+ const fileNameDiffRegex = /(a|i|w|c|o|1|2)\/.*(?=["']? ["']?(b|i|w|c|o|1|2)\/)|(b|i|w|c|o|1|2)\/.*$/g;
380
+ const gitFileHeaderRegex = /^(a|b|i|w|c|o|1|2)\//;
381
+ const parseFiles = (line) => {
382
+ return (line?.match(fileNameDiffRegex))?.map((fileName) => fileName.replace(gitFileHeaderRegex, "").replace(/("|')$/, ""));
383
+ };
384
+ const quotedFileNameRegex = /^\\?['"]|\\?['"]$/g;
385
+ const parseOldOrNewFile = (line, prefix) => {
386
+ let fileName;
387
+ if (prefix) fileName = line.slice(prefix.length);
388
+ else fileName = leftTrimChars(line, "-+").trim();
389
+ fileName = removeTimeStamp(fileName);
390
+ return fileName.replace(quotedFileNameRegex, "").replace(gitFileHeaderRegex, "");
391
+ };
392
+ const leftTrimChars = (input, trimmingChars) => {
393
+ if (!trimmingChars) return input.trimStart();
394
+ const trimmingString = formTrimmingString(trimmingChars);
395
+ return input.replace(/* @__PURE__ */ new RegExp(`^${trimmingString}+`), "");
396
+ };
397
+ const timeStampRegex = /\t.*|\d{4}-\d\d-\d\d\s\d\d:\d\d:\d\d(.\d+)?\s(\+|-)\d\d\d\d/;
398
+ const removeTimeStamp = (input) => {
399
+ const timeStamp = timeStampRegex.exec(input);
400
+ if (timeStamp) return input.substring(0, timeStamp.index).trim();
401
+ return input;
402
+ };
403
+ const formTrimmingString = (trimmingChars) => {
404
+ if (trimmingChars === null || trimmingChars === void 0) return "\\s";
405
+ else if (trimmingChars instanceof RegExp) return trimmingChars.source;
406
+ return `[${trimmingChars.replace(/([.*+?^=!:${}()|[\]/\\])/g, "\\$1")}]`;
407
+ };
408
+
409
+ //#endregion
410
+ 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 };