@pawover/kit 0.0.0-alpha.3 → 0.0.0-alpha.31

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 (73) hide show
  1. package/dist/enums.d.ts +25 -0
  2. package/dist/enums.d.ts.map +1 -0
  3. package/dist/enums.js +25 -0
  4. package/dist/enums.js.map +1 -0
  5. package/dist/hooks-alova.d.ts +23 -0
  6. package/dist/hooks-alova.d.ts.map +1 -0
  7. package/dist/hooks-alova.js +39 -0
  8. package/dist/hooks-alova.js.map +1 -0
  9. package/dist/hooks-react.d.ts +89 -0
  10. package/dist/hooks-react.d.ts.map +1 -0
  11. package/dist/hooks-react.js +334 -0
  12. package/dist/hooks-react.js.map +1 -0
  13. package/dist/index.d.ts +2388 -0
  14. package/dist/index.d.ts.map +1 -0
  15. package/dist/index.js +1361 -2
  16. package/dist/index.js.map +1 -0
  17. package/dist/patches-fetchEventSource.d.ts +806 -0
  18. package/dist/patches-fetchEventSource.d.ts.map +1 -0
  19. package/dist/patches-fetchEventSource.js +313 -0
  20. package/dist/patches-fetchEventSource.js.map +1 -0
  21. package/dist/vite.d.ts +13 -0
  22. package/dist/vite.d.ts.map +1 -0
  23. package/dist/vite.js +22 -0
  24. package/dist/vite.js.map +1 -0
  25. package/dist/zod.d.ts +105 -0
  26. package/dist/zod.d.ts.map +1 -0
  27. package/dist/zod.js +138 -0
  28. package/dist/zod.js.map +1 -0
  29. package/metadata.json +157 -0
  30. package/package.json +57 -35
  31. package/dist/enums/index.js +0 -20
  32. package/dist/hooks/react/index.js +0 -5
  33. package/dist/hooks/react/useCreation.js +0 -11
  34. package/dist/hooks/react/useLatest.js +0 -6
  35. package/dist/hooks/react/useMount.js +0 -29
  36. package/dist/hooks/react/useResponsive.js +0 -59
  37. package/dist/hooks/react/useUnmount.js +0 -17
  38. package/dist/types/enums/index.d.ts +0 -20
  39. package/dist/types/hooks/react/index.d.ts +0 -5
  40. package/dist/types/hooks/react/useCreation.d.ts +0 -2
  41. package/dist/types/hooks/react/useLatest.d.ts +0 -1
  42. package/dist/types/hooks/react/useMount.d.ts +0 -11
  43. package/dist/types/hooks/react/useResponsive.d.ts +0 -16
  44. package/dist/types/hooks/react/useUnmount.d.ts +0 -6
  45. package/dist/types/index.d.ts +0 -2
  46. package/dist/types/utils/array.d.ts +0 -76
  47. package/dist/types/utils/index.d.ts +0 -6
  48. package/dist/types/utils/object.d.ts +0 -53
  49. package/dist/types/utils/string.d.ts +0 -13
  50. package/dist/types/utils/to.d.ts +0 -5
  51. package/dist/types/utils/tree/index.d.ts +0 -6
  52. package/dist/types/utils/tree/rowsToTree.d.ts +0 -10
  53. package/dist/types/utils/tree/treeFilter.d.ts +0 -6
  54. package/dist/types/utils/tree/treeFind.d.ts +0 -8
  55. package/dist/types/utils/tree/treeForEach.d.ts +0 -5
  56. package/dist/types/utils/tree/treeMap.d.ts +0 -6
  57. package/dist/types/utils/tree/treeToRows.d.ts +0 -9
  58. package/dist/types/utils/tree/types.d.ts +0 -24
  59. package/dist/types/utils/typeof.d.ts +0 -29
  60. package/dist/utils/array.js +0 -196
  61. package/dist/utils/index.js +0 -6
  62. package/dist/utils/object.js +0 -138
  63. package/dist/utils/string.js +0 -70
  64. package/dist/utils/to.js +0 -16
  65. package/dist/utils/tree/index.js +0 -6
  66. package/dist/utils/tree/rowsToTree.js +0 -35
  67. package/dist/utils/tree/treeFilter.js +0 -92
  68. package/dist/utils/tree/treeFind.js +0 -82
  69. package/dist/utils/tree/treeForEach.js +0 -60
  70. package/dist/utils/tree/treeMap.js +0 -79
  71. package/dist/utils/tree/treeToRows.js +0 -13
  72. package/dist/utils/tree/types.js +0 -10
  73. package/dist/utils/typeof.js +0 -114
package/dist/index.js CHANGED
@@ -1,2 +1,1361 @@
1
- export * from "./enums";
2
- export * from "./utils";
1
+ //#region src/utils/typeof/types.ts
2
+ const PROTOTYPE_TAGS = {
3
+ abortSignal: "[object AbortSignal]",
4
+ array: "[object Array]",
5
+ asyncFunction: "[object AsyncFunction]",
6
+ asyncGeneratorFunction: "[object AsyncGeneratorFunction]",
7
+ bigInt: "[object BigInt]",
8
+ blob: "[object Blob]",
9
+ boolean: "[object Boolean]",
10
+ date: "[object Date]",
11
+ error: "[object Error]",
12
+ file: "[object File]",
13
+ function: "[object Function]",
14
+ generatorFunction: "[object GeneratorFunction]",
15
+ map: "[object Map]",
16
+ null: "[object Null]",
17
+ number: "[object Number]",
18
+ object: "[object Object]",
19
+ promise: "[object Promise]",
20
+ readableStream: "[object ReadableStream]",
21
+ regExp: "[object RegExp]",
22
+ set: "[object Set]",
23
+ string: "[object String]",
24
+ symbol: "[object Symbol]",
25
+ undefined: "[object Undefined]",
26
+ URLSearchParams: "[object URLSearchParams]",
27
+ weakMap: "[object WeakMap]",
28
+ weakSet: "[object WeakSet]",
29
+ webSocket: "[object WebSocket]",
30
+ window: "[object Window]"
31
+ };
32
+ const TYPED_ARRAY_TAGS = new Set([
33
+ "[object Int8Array]",
34
+ "[object Uint8Array]",
35
+ "[object Uint8ClampedArray]",
36
+ "[object Int16Array]",
37
+ "[object Uint16Array]",
38
+ "[object Int32Array]",
39
+ "[object Uint32Array]",
40
+ "[object Float32Array]",
41
+ "[object Float64Array]",
42
+ "[object BigInt64Array]",
43
+ "[object BigUint64Array]"
44
+ ]);
45
+ function resolvePrototypeString(value) {
46
+ return Object.prototype.toString.call(value);
47
+ }
48
+
49
+ //#endregion
50
+ //#region src/utils/typeof/isAbortSignal.ts
51
+ function isAbortSignal(value) {
52
+ return resolvePrototypeString(value) === PROTOTYPE_TAGS.abortSignal;
53
+ }
54
+
55
+ //#endregion
56
+ //#region src/utils/typeof/isArray.ts
57
+ function isArray(value) {
58
+ return Array.isArray(value);
59
+ }
60
+ function isTypedArray(value) {
61
+ return typeof value === "object" && value !== null && TYPED_ARRAY_TAGS.has(resolvePrototypeString(value));
62
+ }
63
+
64
+ //#endregion
65
+ //#region src/utils/typeof/isBigInt.ts
66
+ function isBigInt(value) {
67
+ return typeof value === "bigint";
68
+ }
69
+
70
+ //#endregion
71
+ //#region src/utils/typeof/isBlob.ts
72
+ function isBlob(value) {
73
+ return resolvePrototypeString(value) === PROTOTYPE_TAGS.blob;
74
+ }
75
+
76
+ //#endregion
77
+ //#region src/utils/typeof/isBoolean.ts
78
+ function isBoolean(value) {
79
+ return typeof value === "boolean";
80
+ }
81
+
82
+ //#endregion
83
+ //#region src/utils/typeof/isClass.ts
84
+ function isConstructable(fn) {
85
+ try {
86
+ Reflect.construct(fn, []);
87
+ return true;
88
+ } catch {
89
+ return false;
90
+ }
91
+ }
92
+ function isClass(value) {
93
+ return isFunction(value) && !isAsyncFunction(value) && Function.prototype.toString.call(value).startsWith("class ") && isConstructable(value) && value.prototype !== void 0;
94
+ }
95
+
96
+ //#endregion
97
+ //#region src/utils/typeof/isObject.ts
98
+ /**
99
+ * 判断是否为对象类型
100
+ * - 可选是否检查原型为 `Object.prototype`,防止原型链污染
101
+ *
102
+ * @param value - 待检查值
103
+ * @param prototypeCheck - 是否进行原型检查,默认 `true`
104
+ */
105
+ function isObject(value, prototypeCheck = true) {
106
+ const check = resolvePrototypeString(value) === PROTOTYPE_TAGS.object;
107
+ return prototypeCheck ? check && Object.getPrototypeOf(value) === Object.prototype : check;
108
+ }
109
+
110
+ //#endregion
111
+ //#region src/utils/typeof/isDate.ts
112
+ function isDate(value) {
113
+ if (!isObject(value)) return false;
114
+ try {
115
+ return resolvePrototypeString(value) === PROTOTYPE_TAGS.date && typeof value["getTime"] === "function";
116
+ } catch (error) {
117
+ return false;
118
+ }
119
+ }
120
+
121
+ //#endregion
122
+ //#region src/utils/typeof/isEqual.ts
123
+ /**
124
+ * 检查给定的值是否相等
125
+ * @reference https://github.com/radashi-org/radashi/blob/main/src/typed/isEqual.ts
126
+ *
127
+ * @param {T} x
128
+ * @param {T} y
129
+ */
130
+ function isEqual(x, y) {
131
+ if (Object.is(x, y)) return true;
132
+ if (isDate(x) && isDate(y)) return x.getTime() === y.getTime();
133
+ if (isRegExp(x) && isRegExp(y)) return x.toString() === y.toString();
134
+ if (typeof x !== "object" || x === null || typeof y !== "object" || y === null) return false;
135
+ const keysX = Reflect.ownKeys(x);
136
+ const keysY = Reflect.ownKeys(y);
137
+ if (keysX.length !== keysY.length) return false;
138
+ for (const key of keysX) {
139
+ if (!Reflect.has(y, key)) return false;
140
+ if (!isEqual(x[key], y[key])) return false;
141
+ }
142
+ return true;
143
+ }
144
+
145
+ //#endregion
146
+ //#region src/utils/typeof/isError.ts
147
+ function isError(value) {
148
+ return value instanceof Error || resolvePrototypeString(value) === PROTOTYPE_TAGS.error;
149
+ }
150
+
151
+ //#endregion
152
+ //#region src/utils/typeof/isFalsy.ts
153
+ function isFalsy(value) {
154
+ if (isNaN(value) || isNull(value) || isUndefined(value)) return true;
155
+ return value === false || value === 0 || value === 0n || value === "";
156
+ }
157
+ function isFalsyLike(value) {
158
+ if (isFalsy(value)) return true;
159
+ return typeof value === "string" && (value === "null" || value === "undefined" || value === "NaN" || value === "false" || value === "0" || value === "0n");
160
+ }
161
+
162
+ //#endregion
163
+ //#region src/utils/typeof/isFile.ts
164
+ function isFile(value) {
165
+ return resolvePrototypeString(value) === PROTOTYPE_TAGS.file;
166
+ }
167
+
168
+ //#endregion
169
+ //#region src/utils/typeof/isFunction.ts
170
+ function isFunction(value) {
171
+ return typeof value === "function";
172
+ }
173
+ function isAsyncFunction(value) {
174
+ return isFunction(value) && resolvePrototypeString(value) === PROTOTYPE_TAGS.asyncFunction;
175
+ }
176
+ function isGeneratorFunction(value) {
177
+ return isFunction(value) && resolvePrototypeString(value) === PROTOTYPE_TAGS.generatorFunction;
178
+ }
179
+ function isAsyncGeneratorFunction(value) {
180
+ return isFunction(value) && resolvePrototypeString(value) === PROTOTYPE_TAGS.asyncGeneratorFunction;
181
+ }
182
+
183
+ //#endregion
184
+ //#region src/utils/typeof/isIterable.ts
185
+ function isIterable(value) {
186
+ return isObject(value) && Symbol.iterator in value;
187
+ }
188
+
189
+ //#endregion
190
+ //#region src/utils/typeof/isMap.ts
191
+ function isMap(value) {
192
+ return resolvePrototypeString(value) === PROTOTYPE_TAGS.map;
193
+ }
194
+ function isWeakMap(value) {
195
+ return resolvePrototypeString(value) === PROTOTYPE_TAGS.weakMap;
196
+ }
197
+
198
+ //#endregion
199
+ //#region src/utils/typeof/isNaN.ts
200
+ function isNaN(value) {
201
+ return Number.isNaN(value);
202
+ }
203
+
204
+ //#endregion
205
+ //#region src/utils/typeof/isNull.ts
206
+ function isNull(value) {
207
+ return value === null;
208
+ }
209
+
210
+ //#endregion
211
+ //#region src/utils/typeof/isNumber.ts
212
+ function isNumber(value) {
213
+ return typeof value === "number";
214
+ }
215
+ /**
216
+ * 检查 value 是否为整数
217
+ *
218
+ * @param value - 待检查值
219
+ * @param safeCheck - 是否附加安全数检查
220
+ */
221
+ function isInteger(value, safeCheck = true) {
222
+ const check = Number.isInteger(value);
223
+ return safeCheck ? check && Number.isSafeInteger(value) : check;
224
+ }
225
+ /**
226
+ * 检查 value 是否为正整数
227
+ * - 未考虑 value 为 0 的情况
228
+ *
229
+ * @param value - 待检查值
230
+ * @param safeCheck - 是否附加安全数检查
231
+ */
232
+ function isPositiveInteger(value, safeCheck = true) {
233
+ return isInteger(value, safeCheck) && value > 0;
234
+ }
235
+ /**
236
+ * 检查 value 是否为负整数
237
+ * - 未考虑 value 为 0 的情况
238
+ *
239
+ * @param value - 待检查值
240
+ * @param safeCheck - 是否附加安全数检查
241
+ */
242
+ function isNegativeInteger(value, safeCheck = true) {
243
+ return isInteger(value, safeCheck) && value < 0;
244
+ }
245
+ function isInfinity(value) {
246
+ return isNumber(value) && (Number.POSITIVE_INFINITY === value || Number.NEGATIVE_INFINITY === value);
247
+ }
248
+ function isInfinityLike(value) {
249
+ return isInfinity(value) && typeof value === "string" && (value === "Infinity" || value === "-Infinity" || value === "+Infinity");
250
+ }
251
+
252
+ //#endregion
253
+ //#region src/utils/typeof/isPromise.ts
254
+ function isPromise(value) {
255
+ return resolvePrototypeString(value) === PROTOTYPE_TAGS.promise;
256
+ }
257
+ function isPromiseLike(value) {
258
+ return isPromise(value) || isObject(value) && isFunction(value["then"]);
259
+ }
260
+
261
+ //#endregion
262
+ //#region src/utils/typeof/isReadableStream.ts
263
+ /**
264
+ * Checks if a value is a WHATWG ReadableStream instance.
265
+ *
266
+ * - Uses `Object.prototype.toString` where supported (modern browsers, Node.js ≥18).
267
+ * - Falls back to duck-typing in older environments.
268
+ * - Resistant to basic forgery, but not 100% secure in all polyfill scenarios.
269
+ *
270
+ * ⚠️ Note: In older Node.js (<18) or with non-compliant polyfills, this may return false positives or negatives.
271
+ */
272
+ function isReadableStream(value) {
273
+ if (resolvePrototypeString(value) === PROTOTYPE_TAGS.readableStream) return true;
274
+ return isObject(value) && isFunction(value["getReader"]) && isFunction(value["pipeThrough"]);
275
+ }
276
+
277
+ //#endregion
278
+ //#region src/utils/typeof/isRegExp.ts
279
+ function isRegExp(value) {
280
+ if (!isObject(value)) return false;
281
+ try {
282
+ const regex = value;
283
+ return resolvePrototypeString(value) === PROTOTYPE_TAGS.regExp && isString(regex.source) && isString(regex.flags) && isBoolean(regex.global) && isFunction(regex.test);
284
+ } catch (error) {
285
+ return false;
286
+ }
287
+ }
288
+
289
+ //#endregion
290
+ //#region src/utils/typeof/isSet.ts
291
+ function isSet(value) {
292
+ return resolvePrototypeString(value) === PROTOTYPE_TAGS.set;
293
+ }
294
+ function isWeakSet(value) {
295
+ return resolvePrototypeString(value) === PROTOTYPE_TAGS.weakSet;
296
+ }
297
+
298
+ //#endregion
299
+ //#region src/utils/typeof/isString.ts
300
+ function isString(value) {
301
+ return typeof value === "string";
302
+ }
303
+
304
+ //#endregion
305
+ //#region src/utils/typeof/isSymbol.ts
306
+ function isSymbol(value) {
307
+ return typeof value === "symbol";
308
+ }
309
+
310
+ //#endregion
311
+ //#region src/utils/typeof/isUndefined.ts
312
+ function isUndefined(value) {
313
+ return typeof value === "undefined";
314
+ }
315
+
316
+ //#endregion
317
+ //#region src/utils/typeof/isURLSearchParams.ts
318
+ function isURLSearchParams(value) {
319
+ return resolvePrototypeString(value) === PROTOTYPE_TAGS.URLSearchParams;
320
+ }
321
+
322
+ //#endregion
323
+ //#region src/utils/typeof/isWebSocket.ts
324
+ function isWebSocket(value) {
325
+ return resolvePrototypeString(value) === PROTOTYPE_TAGS.webSocket;
326
+ }
327
+
328
+ //#endregion
329
+ //#region src/utils/typeof/isWindow.ts
330
+ function isWindow(value) {
331
+ return resolvePrototypeString(value) === PROTOTYPE_TAGS.window;
332
+ }
333
+
334
+ //#endregion
335
+ //#region src/utils/array/arrayCast.ts
336
+ /**
337
+ * 构造数组
338
+ * @param candidate 待构造项
339
+ * @param checkEmpty 是否检查 `undefined` 和 `null`
340
+ */
341
+ function arrayCast(candidate, checkEmpty = true) {
342
+ if (checkEmpty && (isUndefined(candidate) || isNull(candidate))) return [];
343
+ return isArray(candidate) ? [...candidate] : [candidate];
344
+ }
345
+
346
+ //#endregion
347
+ //#region src/utils/array/arrayCompete.ts
348
+ /**
349
+ * 数组竞争
350
+ * - 返回在匹配函数的比较条件中获胜的最终项目,适用于更复杂的最小值/最大值计算
351
+ *
352
+ * @param initialList 数组
353
+ * @param match 匹配函数
354
+ */
355
+ function arrayCompete(initialList, match) {
356
+ if (!isArray(initialList) || initialList.length === 0 || !isFunction(match)) return null;
357
+ return initialList.reduce(match);
358
+ }
359
+
360
+ //#endregion
361
+ //#region src/utils/array/arrayCounting.ts
362
+ /**
363
+ * 统计数组的项目出现次数
364
+ * - 通过给定的标识符匹配函数,返回一个对象,其中键是回调函数返回的 key 值,每个值是一个整数,表示该 key 出现的次数
365
+ *
366
+ * @param initialList 初始数组
367
+ * @param match 匹配函数
368
+ */
369
+ function arrayCounting(initialList, match) {
370
+ if (!isArray(initialList) || !isFunction(match)) return {};
371
+ return initialList.reduce((prev, curr) => {
372
+ const id = match(curr).toString();
373
+ prev[id] = (prev[id] ?? 0) + 1;
374
+ return prev;
375
+ }, {});
376
+ }
377
+
378
+ //#endregion
379
+ //#region src/utils/array/arrayDifference.ts
380
+ /**
381
+ * 求数组差集
382
+ *
383
+ * @param initialList 初始数组
384
+ * @param diffList 对比数组
385
+ * @param match 匹配函数
386
+ */
387
+ function arrayDifference(initialList, diffList, match) {
388
+ if (!isArray(initialList) && !isArray(diffList)) return [];
389
+ if (!isArray(initialList) || !initialList.length) return [...diffList];
390
+ if (!isArray(diffList) || !diffList.length) return [...initialList];
391
+ if (!isFunction(match)) {
392
+ const arraySet = new Set(diffList);
393
+ return Array.from(new Set(initialList.filter((item) => !arraySet.has(item))));
394
+ }
395
+ const map = /* @__PURE__ */ new Map();
396
+ diffList.forEach((item) => {
397
+ map.set(match(item), true);
398
+ });
399
+ return initialList.filter((a) => !map.get(match(a)));
400
+ }
401
+
402
+ //#endregion
403
+ //#region src/utils/array/arrayFirst.ts
404
+ /**
405
+ * 获取数组第一项
406
+ *
407
+ * @param initialList 初始数组
408
+ * @param saveValue 安全值
409
+ */
410
+ function arrayFirst(initialList, saveValue) {
411
+ if (!isArray(initialList) || initialList.length === 0) return saveValue;
412
+ return initialList[0];
413
+ }
414
+
415
+ //#endregion
416
+ //#region src/utils/array/arrayFork.ts
417
+ /**
418
+ * 数组分组过滤
419
+ * - 给定一个数组和一个条件,返回一个由两个数组组成的元组,其中第一个数组包含所有满足条件的项,第二个数组包含所有不满足条件的项
420
+ *
421
+ * @param initialList 初始数组
422
+ * @param match 条件匹配函数
423
+ */
424
+ function arrayFork(initialList, match) {
425
+ const forked = [[], []];
426
+ if (isArray(initialList)) for (const item of initialList) forked[match(item) ? 0 : 1].push(item);
427
+ return forked;
428
+ }
429
+
430
+ //#endregion
431
+ //#region src/utils/array/arrayIntersection.ts
432
+ /**
433
+ * 求数组交集
434
+ *
435
+ * @param initialList 初始数组
436
+ * @param diffList 对比数组
437
+ * @param match 匹配函数
438
+ */
439
+ function arrayIntersection(initialList, diffList, match) {
440
+ if (!isArray(initialList) && !isArray(diffList)) return [];
441
+ if (!isArray(initialList) || !initialList.length) return [...diffList];
442
+ if (!isArray(diffList) || !diffList.length) return [...initialList];
443
+ if (!isFunction(match)) {
444
+ const arraySet = new Set(diffList);
445
+ return Array.from(new Set(initialList.filter((item) => arraySet.has(item))));
446
+ }
447
+ const map = /* @__PURE__ */ new Map();
448
+ diffList.forEach((item) => {
449
+ map.set(match(item), true);
450
+ });
451
+ return initialList.filter((a) => map.get(match(a)));
452
+ }
453
+
454
+ //#endregion
455
+ //#region src/utils/array/arrayLast.ts
456
+ /**
457
+ * 获取数组最后一项
458
+ *
459
+ * @param initialList 初始数组
460
+ * @param saveValue 安全值
461
+ */
462
+ function arrayLast(initialList, saveValue) {
463
+ if (!isArray(initialList) || initialList.length === 0) return saveValue;
464
+ return initialList[initialList.length - 1];
465
+ }
466
+
467
+ //#endregion
468
+ //#region src/utils/array/arrayMerge.ts
469
+ /**
470
+ * 数组合并
471
+ * - 通过给定的标识符匹配函数,用第二个数组中的匹配项替换第一个数组中匹配项的所有内容
472
+ *
473
+ * @param initialList 初始数组
474
+ * @param mergeList 待合并数组
475
+ * @param match 匹配函数
476
+ */
477
+ function arrayMerge(initialList, mergeList, match) {
478
+ if (!isArray(initialList)) return [];
479
+ if (!isArray(mergeList)) return [...initialList];
480
+ if (!isFunction(match)) return Array.from(new Set([...initialList, ...mergeList]));
481
+ const keys = /* @__PURE__ */ new Map();
482
+ for (const item of mergeList) keys.set(match(item), item);
483
+ return initialList.map((prevItem) => {
484
+ const key = match(prevItem);
485
+ return keys.has(key) ? keys.get(key) : prevItem;
486
+ });
487
+ }
488
+
489
+ //#endregion
490
+ //#region src/utils/array/arrayPick.ts
491
+ /**
492
+ * 数组选择
493
+ * - 一次性应用 `filter` 和 `map` 操作
494
+ *
495
+ * @param initialList 初始数组
496
+ * @param filter filter 函数
497
+ * @param mapper map 函数
498
+ */
499
+ function arrayPick(initialList, filter, mapper) {
500
+ if (!isArray(initialList)) return [];
501
+ if (!isFunction(filter)) return [...initialList];
502
+ const hasMapper = isFunction(mapper);
503
+ return initialList.reduce((prev, curr, index) => {
504
+ if (!filter(curr, index)) return prev;
505
+ if (hasMapper) prev.push(mapper(curr, index));
506
+ else prev.push(curr);
507
+ return prev;
508
+ }, []);
509
+ }
510
+
511
+ //#endregion
512
+ //#region src/utils/array/arrayReplace.ts
513
+ /**
514
+ * 数组项替换
515
+ * - 在给定的数组中,替换符合匹配函数结果的项目。只替换第一个匹配项。始终返回原始数组的副本。
516
+ *
517
+ * @param initialList 初始数组
518
+ * @param newItem 替换项
519
+ * @param match 匹配函数
520
+ */
521
+ function arrayReplace(initialList, newItem, match) {
522
+ if (!initialList) return [];
523
+ if (newItem === void 0 || !isFunction(match)) return [...initialList];
524
+ for (let i = 0; i < initialList.length; i++) {
525
+ const item = initialList[i];
526
+ if (item !== void 0 && match(item, i)) return [
527
+ ...initialList.slice(0, i),
528
+ newItem,
529
+ ...initialList.slice(i + 1, initialList.length)
530
+ ];
531
+ }
532
+ return [...initialList];
533
+ }
534
+
535
+ //#endregion
536
+ //#region src/utils/array/arraySplit.ts
537
+ /**
538
+ * 数组切分
539
+ * - 将数组以指定的长度切分后,组合在高维数组中
540
+ *
541
+ * @param initialList 初始数组
542
+ * @param size 分割尺寸,默认 `10`
543
+ */
544
+ function arraySplit(initialList, size = 10) {
545
+ if (!isArray(initialList)) return [];
546
+ const count = Math.ceil(initialList.length / size);
547
+ return Array.from({ length: count }).fill(null).map((_c, i) => {
548
+ return initialList.slice(i * size, i * size + size);
549
+ });
550
+ }
551
+
552
+ //#endregion
553
+ //#region src/utils/function/to.ts
554
+ /**
555
+ * @param promise
556
+ * @param errorExt - 可以传递给err对象的其他信息
557
+ */
558
+ function to(promise, errorExt) {
559
+ return promise.then((data) => [null, data]).catch((err) => {
560
+ if (errorExt) return [{
561
+ ...err,
562
+ ...errorExt
563
+ }, void 0];
564
+ return [err ? err : /* @__PURE__ */ new Error("defaultError"), void 0];
565
+ });
566
+ }
567
+
568
+ //#endregion
569
+ //#region src/utils/string/stringToNumber.ts
570
+ const R1$1 = /[^0-9.-]/g;
571
+ /**
572
+ * 从字符串中提取数字字符串
573
+ *
574
+ * @param input 待处理字符串
575
+ */
576
+ function stringToNumber(input) {
577
+ if (!isString(input) || !input.length) return "";
578
+ const cleaned = input.replace(R1$1, "");
579
+ let isDecimal = false;
580
+ let signCount = 0;
581
+ let firstIndex = -1;
582
+ const stringList = cleaned.split("").map((s, i) => {
583
+ if (s === ".") {
584
+ if (isDecimal) return "";
585
+ isDecimal = true;
586
+ return ".";
587
+ }
588
+ if (s === "-") {
589
+ firstIndex === -1 && signCount++;
590
+ return "";
591
+ }
592
+ firstIndex === -1 && (firstIndex = i);
593
+ return s;
594
+ });
595
+ const sign = signCount % 2 === 1 ? "-" : "";
596
+ if (firstIndex === -1) return sign + "0";
597
+ let result = stringList.join("");
598
+ if (result.startsWith(".")) result = "0" + result;
599
+ if (result.endsWith(".")) result = result.slice(0, -1);
600
+ return sign + result;
601
+ }
602
+
603
+ //#endregion
604
+ //#region src/utils/math/toMathBignumber.ts
605
+ /**
606
+ * 将任意类型的值转换为 `math.bignumber`
607
+ *
608
+ * @param mathJsInstance mathJs 实例
609
+ * @param value 任意类型的值
610
+ * @param saveValue 安全值
611
+ */
612
+ function toMathBignumber(mathJsInstance, value, saveValue) {
613
+ const errorValue = saveValue ?? mathJsInstance.bignumber(0);
614
+ if (isFalsyLike(value) || isInfinityLike(value)) return errorValue;
615
+ try {
616
+ return mathJsInstance.bignumber(stringToNumber(`${value}`));
617
+ } catch (error) {
618
+ return errorValue;
619
+ }
620
+ }
621
+
622
+ //#endregion
623
+ //#region src/utils/math/toMathDecimal.ts
624
+ function toMathDecimal(mathJsInstance, value, precision, isFormat = true) {
625
+ const bigNumber = toMathBignumber(mathJsInstance, value);
626
+ return isFormat ? mathJsInstance.format(bigNumber, {
627
+ notation: "fixed",
628
+ precision
629
+ }) : bigNumber;
630
+ }
631
+
632
+ //#endregion
633
+ //#region src/utils/math/toMathEvaluate.ts
634
+ /**
635
+ * 数学表达式求值
636
+ *
637
+ * @param mathJsInstance mathJs 实例
638
+ * @param expr 表达式
639
+ * @param scope 键值映射
640
+ */
641
+ function toMathEvaluate(mathJsInstance, expr, scope) {
642
+ const evaluateValue = `${mathJsInstance.evaluate(expr, scope || {})}`;
643
+ return mathJsInstance.format(toMathBignumber(mathJsInstance, evaluateValue), { notation: "fixed" });
644
+ }
645
+
646
+ //#endregion
647
+ //#region src/utils/object/cloneDeep.ts
648
+ const DefaultCloningStrategy = {
649
+ cloneMap(input, track, clone) {
650
+ const output = track(/* @__PURE__ */ new Map());
651
+ for (const [key, value] of input) output.set(key, clone(value));
652
+ return output;
653
+ },
654
+ cloneSet(input, track, clone) {
655
+ const output = track(/* @__PURE__ */ new Set());
656
+ for (const value of input) output.add(clone(value));
657
+ return output;
658
+ },
659
+ cloneArray(input, track, clone) {
660
+ const output = track(new Array(input.length));
661
+ input.forEach((value, index) => {
662
+ output[index] = clone(value);
663
+ });
664
+ return output;
665
+ },
666
+ cloneObject(input, track, clone) {
667
+ const output = track(Object.create(Object.getPrototypeOf(input)));
668
+ for (const key of Reflect.ownKeys(input)) {
669
+ const descriptor = Object.getOwnPropertyDescriptor(input, key);
670
+ if ("value" in descriptor) descriptor.value = clone(descriptor.value);
671
+ Object.defineProperty(output, key, descriptor);
672
+ }
673
+ return output;
674
+ },
675
+ cloneOther(input, track) {
676
+ return track(input);
677
+ }
678
+ };
679
+ /**
680
+ * cloneDeep
681
+ * @reference https://github.com/radashi-org/radashi/blob/main/src/object/cloneDeep.ts
682
+ */
683
+ function cloneDeep(root, customStrategy) {
684
+ const strategy = {
685
+ ...DefaultCloningStrategy,
686
+ ...customStrategy
687
+ };
688
+ const tracked = /* @__PURE__ */ new Map();
689
+ const track = (parent, newParent) => {
690
+ tracked.set(parent, newParent);
691
+ return newParent;
692
+ };
693
+ const clone = (value) => {
694
+ return value && typeof value === "object" ? tracked.get(value) ?? cloneDeep$1(value, strategy) : value;
695
+ };
696
+ const cloneDeep$1 = (parent, strategy$1) => {
697
+ const newParent = (isObject(parent) ? strategy$1.cloneObject : isArray(parent) ? strategy$1.cloneArray : isMap(parent) ? strategy$1.cloneMap : isSet(parent) ? strategy$1.cloneSet : strategy$1.cloneOther)(parent, track.bind(null, parent), clone);
698
+ if (!newParent) return cloneDeep$1(parent, DefaultCloningStrategy);
699
+ tracked.set(parent, newParent);
700
+ return newParent;
701
+ };
702
+ return cloneDeep$1(root, strategy);
703
+ }
704
+
705
+ //#endregion
706
+ //#region src/utils/object/objectKeys.ts
707
+ /**
708
+ * 返回对象的可枚举属性和方法的名称
709
+ * - `Object.keys` 始终返回 `string[]` 类型,此函数可以返回具体类型
710
+ *
711
+ * @param obj 对象
712
+ */
713
+ function objectKeys(obj) {
714
+ return Object.keys(obj);
715
+ }
716
+
717
+ //#endregion
718
+ //#region src/utils/object/enumTypeCheck.ts
719
+ function enumTypeCheck(enumeration) {
720
+ if (!isObject(enumeration)) throw Error(`function enumKeys expected parameter is a enum, but got ${typeof enumeration}`);
721
+ if (!objectKeys(enumeration).length) throw Error("Enum requires at least one member");
722
+ return enumeration;
723
+ }
724
+
725
+ //#endregion
726
+ //#region src/utils/object/objectEntries.ts
727
+ /**
728
+ * 返回对象的可枚举属性的键/值数组
729
+ *
730
+ * @param obj 对象
731
+ */
732
+ function objectEntries(obj) {
733
+ return Object.entries(obj);
734
+ }
735
+
736
+ //#endregion
737
+ //#region src/utils/object/objectValues.ts
738
+ /**
739
+ * 返回对象的可枚举属性的值数组
740
+ *
741
+ * @param obj 对象
742
+ */
743
+ function objectValues(obj) {
744
+ return Object.values(obj);
745
+ }
746
+
747
+ //#endregion
748
+ //#region src/utils/object/enumEntries.ts
749
+ /**
750
+ * 返回枚举的属性的键/值数组
751
+ *
752
+ * @param enumeration 枚举
753
+ */
754
+ function enumEntries(enumeration) {
755
+ const e = enumTypeCheck(enumeration);
756
+ const keys = objectKeys(e);
757
+ const values = objectValues(e);
758
+ const entries = objectEntries(e);
759
+ if (keys.every((k) => values.some((v) => `${v}` === k))) return entries.splice(keys.length / 2, keys.length / 2);
760
+ return entries;
761
+ }
762
+
763
+ //#endregion
764
+ //#region src/utils/object/enumKeys.ts
765
+ /**
766
+ * 获取枚举所有属性的键
767
+ *
768
+ * @param enumeration 枚举
769
+ */
770
+ function enumKeys(enumeration) {
771
+ const e = enumTypeCheck(enumeration);
772
+ const keys = objectKeys(e);
773
+ const values = objectValues(e);
774
+ if (keys.every((k) => values.some((v) => `${v}` === k))) return keys.splice(keys.length / 2, keys.length / 2);
775
+ return keys;
776
+ }
777
+
778
+ //#endregion
779
+ //#region src/utils/object/enumValues.ts
780
+ /**
781
+ * 获取枚举所有属性的值
782
+ *
783
+ * @param enumeration 枚举
784
+ */
785
+ function enumValues(enumeration) {
786
+ const e = enumTypeCheck(enumeration);
787
+ const keys = objectKeys(e);
788
+ const values = objectValues(e);
789
+ if (keys.every((k) => values.some((v) => `${v}` === k))) return values.splice(keys.length / 2, keys.length / 2);
790
+ return values;
791
+ }
792
+
793
+ //#endregion
794
+ //#region src/utils/object/mapEntries.ts
795
+ function mapEntries(obj, toEntry) {
796
+ const defaultResult = {};
797
+ if (!obj) return defaultResult;
798
+ return objectEntries(obj).reduce((acc, [key, value]) => {
799
+ const [newKey, newValue] = toEntry(key, value);
800
+ acc[newKey] = newValue;
801
+ return acc;
802
+ }, defaultResult);
803
+ }
804
+
805
+ //#endregion
806
+ //#region src/utils/object/objectAssign.ts
807
+ /**
808
+ * 递归地将第二个对象合并到第一个对象的副本中
809
+ * - 只有普通对象才会递归合并
810
+ *
811
+ * @param initial 初始对象
812
+ * @param override 待合并对象
813
+ */
814
+ function objectAssign(initial, override) {
815
+ if (!isObject(initial) || !isObject(override)) return initial ?? override ?? {};
816
+ const proto = Object.getPrototypeOf(initial);
817
+ const assigned = proto ? { ...initial } : Object.assign(Object.create(proto), initial);
818
+ for (const key of Object.keys(override)) assigned[key] = isObject(initial[key]) && isObject(override[key]) ? objectAssign(initial[key], override[key]) : override[key];
819
+ return assigned;
820
+ }
821
+
822
+ //#endregion
823
+ //#region src/utils/object/objectCrush.ts
824
+ function objectCrush(value) {
825
+ if (!value) return {};
826
+ function crushReducer(crushed, value$1, path) {
827
+ if (isObject(value$1) || isArray(value$1)) for (const [prop, propValue] of Object.entries(value$1)) crushReducer(crushed, propValue, path ? `${path}.${prop}` : prop);
828
+ else crushed[path] = value$1;
829
+ return crushed;
830
+ }
831
+ return crushReducer({}, value, "");
832
+ }
833
+
834
+ //#endregion
835
+ //#region src/utils/object/objectPick.ts
836
+ function objectPick(obj, keys) {
837
+ const result = {};
838
+ if (!isObject(obj)) return result;
839
+ if (!isArray(keys)) return obj;
840
+ return keys.reduce((acc, curr) => {
841
+ if (curr in obj) acc[curr] = obj[curr];
842
+ return acc;
843
+ }, result);
844
+ }
845
+
846
+ //#endregion
847
+ //#region src/utils/object/objectSwitch.ts
848
+ /**
849
+ * 对象反转
850
+ * - 返回交换了对象的可枚举属性的值/键对象
851
+ *
852
+ * @param obj 对象
853
+ */
854
+ function objectSwitch(obj) {
855
+ const result = {};
856
+ if (!isObject(obj)) return result;
857
+ for (const [k, v] of objectEntries(obj)) result[v] = k;
858
+ return result;
859
+ }
860
+
861
+ //#endregion
862
+ //#region src/utils/string/stringInitialCase.ts
863
+ const R1 = /\S+/g;
864
+ const R2 = /[^a-zA-Z\u00C0-\u017F]/;
865
+ /**
866
+ * 字符串首字母大小写
867
+ * - 包含非西欧字母字符时,不处理
868
+ * - 纯字母且全大写时,不处理
869
+ * - 纯字母且非全大写时,首字母小写,其余保留
870
+ * - 纯字母且非全大写时,首字母大写,其余保留
871
+ *
872
+ * @param input 待处理字符串
873
+ * @param caseType 大小写类型
874
+ */
875
+ function stringInitialCase(input, caseType) {
876
+ if (!isString(input) || !input.length) return "";
877
+ return input.replace(R1, (word) => {
878
+ if (R2.test(word)) return word;
879
+ if (word === word.toLocaleUpperCase()) return word;
880
+ if (caseType === "lower" && word[0]) return word[0].toLocaleLowerCase() + word.slice(1);
881
+ if (caseType === "upper" && word[0]) return word[0].toLocaleUpperCase() + word.slice(1);
882
+ return word;
883
+ });
884
+ }
885
+
886
+ //#endregion
887
+ //#region src/utils/string/stringReplace.ts
888
+ /**
889
+ * 字符串替换
890
+ * - 替换第一个匹配项
891
+ *
892
+ * @param input 待处理字符串
893
+ * @param search 匹配项
894
+ * @param replacement 替换项
895
+ */
896
+ function stringReplace(input, search, replacement) {
897
+ if (!isString(input) || !input.length) return "";
898
+ return input.replace(search, replacement);
899
+ }
900
+
901
+ //#endregion
902
+ //#region src/utils/string/stringTemplate.ts
903
+ /**
904
+ * 字符串模板替换
905
+ *
906
+ * @param input 待处理字符串
907
+ * @param template 模板对象
908
+ * @param regex 模板匹配正则
909
+ */
910
+ function stringTemplate(input, template, regex = /\{\{(.+?)\}\}/g) {
911
+ if (!isString(input) || !input.length) return "";
912
+ let result = "";
913
+ let from = 0;
914
+ let match;
915
+ while (match = regex.exec(input)) {
916
+ result += input.slice(from, match.index) + template[match[1]];
917
+ from = regex.lastIndex;
918
+ }
919
+ return result + input.slice(from);
920
+ }
921
+
922
+ //#endregion
923
+ //#region src/utils/string/stringToJson.ts
924
+ /**
925
+ * 处理 JSON 字符串
926
+ *
927
+ * @param input 待处理字符串
928
+ * @param safeValue 安全值
929
+ */
930
+ function stringToJson(input, safeValue) {
931
+ if (!isString(input) || !input.length) return safeValue;
932
+ try {
933
+ return JSON.parse(input);
934
+ } catch (error) {
935
+ return safeValue;
936
+ }
937
+ }
938
+
939
+ //#endregion
940
+ //#region src/utils/string/stringToValues.ts
941
+ function stringToValues(input, valueType = "number", splitSymbol = ",") {
942
+ if (!isString(input) || !input.length) return [];
943
+ try {
944
+ const values = input.split(splitSymbol);
945
+ if (valueType === "number") return values.map((d) => Number(d));
946
+ return values;
947
+ } catch (error) {
948
+ return [];
949
+ }
950
+ }
951
+
952
+ //#endregion
953
+ //#region src/utils/tree/types.ts
954
+ function getFinalChildrenKey(tree, meta, options) {
955
+ if (isFunction(options.getChildrenKey)) {
956
+ const dynamicChildrenKey = options.getChildrenKey(tree, meta);
957
+ if (dynamicChildrenKey && dynamicChildrenKey !== null) return dynamicChildrenKey;
958
+ }
959
+ return options.childrenKey;
960
+ }
961
+
962
+ //#endregion
963
+ //#region src/utils/tree/treeFilter.ts
964
+ function preImpl$3(row, callback, options) {
965
+ if (!callback(row, options)) return;
966
+ const finalChildrenKey = getFinalChildrenKey(row, options, options);
967
+ const children = row[finalChildrenKey];
968
+ let newChildren;
969
+ if (isArray(children)) {
970
+ const nextLevelOptions = {
971
+ ...options,
972
+ parents: [...options.parents, row],
973
+ depth: options.depth + 1
974
+ };
975
+ newChildren = children.map((c) => preImpl$3(c, callback, nextLevelOptions)).filter((c) => !!c);
976
+ }
977
+ return {
978
+ ...row,
979
+ [finalChildrenKey]: newChildren
980
+ };
981
+ }
982
+ function postImpl$3(row, callback, options) {
983
+ const finalChildrenKey = getFinalChildrenKey(row, options, options);
984
+ const children = row[finalChildrenKey];
985
+ let newChildren;
986
+ if (isArray(children)) {
987
+ const nextLevelOptions = {
988
+ ...options,
989
+ parents: [...options.parents, row],
990
+ depth: options.depth + 1
991
+ };
992
+ newChildren = children.map((c) => preImpl$3(c, callback, nextLevelOptions)).filter((c) => !!c);
993
+ }
994
+ if (!callback(row, options)) return;
995
+ return {
996
+ ...row,
997
+ [finalChildrenKey]: newChildren
998
+ };
999
+ }
1000
+ function breadthImpl$3(row, callback, options) {
1001
+ const queue = [{
1002
+ queueRow: row,
1003
+ queueOptions: options
1004
+ }];
1005
+ const resultCache = /* @__PURE__ */ new WeakMap();
1006
+ const newNodeCache = /* @__PURE__ */ new WeakMap();
1007
+ const childrenKeyCache = /* @__PURE__ */ new WeakMap();
1008
+ let result;
1009
+ const runQueue = () => {
1010
+ if (queue.length === 0) return result;
1011
+ const { queueRow, queueOptions } = queue.shift();
1012
+ const finalChildrenKey = getFinalChildrenKey(queueRow, queueOptions, queueOptions);
1013
+ const children = queueRow[finalChildrenKey];
1014
+ if (isArray(children)) {
1015
+ const nextLevelOptions = {
1016
+ ...queueOptions,
1017
+ parents: [...queueOptions.parents, queueRow],
1018
+ depth: queueOptions.depth + 1
1019
+ };
1020
+ const subQueueItems = children.map((queueRow$1) => ({
1021
+ queueRow: queueRow$1,
1022
+ queueOptions: nextLevelOptions
1023
+ }));
1024
+ queue.push(...subQueueItems);
1025
+ }
1026
+ const parent = arrayLast(queueOptions.parents);
1027
+ const isTopNode = queueOptions.depth === 0;
1028
+ const parentResult = parent && resultCache.get(parent);
1029
+ if (!isTopNode && !parentResult) return runQueue();
1030
+ const callbackResult = callback(queueRow, queueOptions);
1031
+ if (isTopNode && !callbackResult) return;
1032
+ const newNode = {
1033
+ ...queueRow,
1034
+ [finalChildrenKey]: void 0
1035
+ };
1036
+ if (isTopNode) result = newNode;
1037
+ resultCache.set(queueRow, callbackResult);
1038
+ newNodeCache.set(queueRow, newNode);
1039
+ childrenKeyCache.set(queueRow, finalChildrenKey);
1040
+ if (callbackResult && parent) {
1041
+ const parentNewNode = newNodeCache.get(parent);
1042
+ const parentChildrenKey = childrenKeyCache.get(parent);
1043
+ if (parentNewNode && parentChildrenKey) {
1044
+ if (!parentNewNode[parentChildrenKey]) parentNewNode[parentChildrenKey] = [];
1045
+ parentNewNode[parentChildrenKey].push(newNode);
1046
+ }
1047
+ }
1048
+ return runQueue();
1049
+ };
1050
+ return runQueue();
1051
+ }
1052
+ const strategies$3 = {
1053
+ pre: preImpl$3,
1054
+ post: postImpl$3,
1055
+ breadth: breadthImpl$3
1056
+ };
1057
+ function treeFilter(tree, callback, options = {}) {
1058
+ const { childrenKey = "children", strategy = "pre", getChildrenKey } = options;
1059
+ const traversalMethod = strategies$3[strategy];
1060
+ const innerOptions = {
1061
+ childrenKey,
1062
+ depth: 0,
1063
+ parents: [],
1064
+ getChildrenKey
1065
+ };
1066
+ return isArray(tree) ? tree.map((row) => traversalMethod(row, callback, innerOptions)).filter((t) => !!t) : traversalMethod(tree, callback, innerOptions) || [];
1067
+ }
1068
+
1069
+ //#endregion
1070
+ //#region src/utils/tree/treeFind.ts
1071
+ const strategies$2 = {
1072
+ pre: preImpl$2,
1073
+ post: postImpl$2,
1074
+ breadth: breadthImpl$2
1075
+ };
1076
+ function preImpl$2(row, callback, options) {
1077
+ if (callback(row, options)) return row;
1078
+ const children = row[getFinalChildrenKey(row, options, options)];
1079
+ if (isArray(children)) for (const child of children) {
1080
+ const result = preImpl$2(child, callback, {
1081
+ ...options,
1082
+ parents: [...options.parents, row],
1083
+ depth: options.depth + 1
1084
+ });
1085
+ if (result) return result;
1086
+ }
1087
+ }
1088
+ function postImpl$2(row, callback, options) {
1089
+ const children = row[getFinalChildrenKey(row, options, options)];
1090
+ if (isArray(children)) for (const child of children) {
1091
+ const result = postImpl$2(child, callback, {
1092
+ ...options,
1093
+ parents: [...options.parents, row],
1094
+ depth: options.depth + 1
1095
+ });
1096
+ if (result) return result;
1097
+ }
1098
+ if (callback(row, options)) return row;
1099
+ }
1100
+ function breadthImpl$2(row, callback, options) {
1101
+ const queue = [{
1102
+ queueRow: row,
1103
+ queueOptions: options
1104
+ }];
1105
+ const runQueue = () => {
1106
+ if (queue.length === 0) return;
1107
+ const { queueRow, queueOptions } = queue.shift();
1108
+ const children = queueRow[getFinalChildrenKey(queueRow, queueOptions, queueOptions)];
1109
+ if (isArray(children)) {
1110
+ const nextLevelOptions = {
1111
+ ...queueOptions,
1112
+ parents: [...queueOptions.parents, queueRow],
1113
+ depth: queueOptions.depth + 1
1114
+ };
1115
+ const subQueueItems = children.map((queueRow$1) => ({
1116
+ queueRow: queueRow$1,
1117
+ queueOptions: nextLevelOptions
1118
+ }));
1119
+ queue.push(...subQueueItems);
1120
+ }
1121
+ if (callback(queueRow, queueOptions)) return queueRow;
1122
+ return runQueue();
1123
+ };
1124
+ return runQueue();
1125
+ }
1126
+ /**
1127
+ * 查找树节点,找到第一个返回非空值的节点
1128
+ */
1129
+ function treeFind(tree, callback, options = {}) {
1130
+ const { childrenKey = "children", strategy = "pre", getChildrenKey } = options;
1131
+ const traversalMethod = strategies$2[strategy];
1132
+ const innerOptions = {
1133
+ childrenKey,
1134
+ depth: 0,
1135
+ parents: [],
1136
+ getChildrenKey
1137
+ };
1138
+ if (isArray(tree)) {
1139
+ for (const row of tree) {
1140
+ const result = traversalMethod(row, callback, innerOptions);
1141
+ if (result) return result;
1142
+ }
1143
+ return;
1144
+ }
1145
+ return traversalMethod(tree, callback, innerOptions);
1146
+ }
1147
+
1148
+ //#endregion
1149
+ //#region src/utils/tree/treeForEach.ts
1150
+ const strategies$1 = {
1151
+ pre: preImpl$1,
1152
+ post: postImpl$1,
1153
+ breadth: breadthImpl$1
1154
+ };
1155
+ function preImpl$1(row, callback, options) {
1156
+ callback(row, options);
1157
+ const children = row[getFinalChildrenKey(row, options, options)];
1158
+ if (isArray(children)) {
1159
+ const nextLevelOptions = {
1160
+ ...options,
1161
+ parents: [...options.parents, row],
1162
+ depth: options.depth + 1
1163
+ };
1164
+ for (const child of children) preImpl$1(child, callback, nextLevelOptions);
1165
+ }
1166
+ }
1167
+ function postImpl$1(row, callback, options) {
1168
+ const children = row[getFinalChildrenKey(row, options, options)];
1169
+ if (isArray(children)) {
1170
+ const nextLevelOptions = {
1171
+ ...options,
1172
+ parents: [...options.parents, row],
1173
+ depth: options.depth + 1
1174
+ };
1175
+ for (const child of children) postImpl$1(child, callback, nextLevelOptions);
1176
+ }
1177
+ callback(row, options);
1178
+ }
1179
+ function breadthImpl$1(row, callback, options) {
1180
+ const queue = [{
1181
+ queueRow: row,
1182
+ queueOptions: options
1183
+ }];
1184
+ const runQueue = () => {
1185
+ if (queue.length === 0) return;
1186
+ const { queueRow, queueOptions } = queue.shift();
1187
+ const children = queueRow[getFinalChildrenKey(queueRow, queueOptions, queueOptions)];
1188
+ if (isArray(children)) {
1189
+ const nextLevelOptions = {
1190
+ ...queueOptions,
1191
+ parents: [...queueOptions.parents, queueRow],
1192
+ depth: queueOptions.depth + 1
1193
+ };
1194
+ const subQueueItems = children.map((queueRow$1) => ({
1195
+ queueRow: queueRow$1,
1196
+ queueOptions: nextLevelOptions
1197
+ }));
1198
+ queue.push(...subQueueItems);
1199
+ }
1200
+ callback(queueRow, queueOptions);
1201
+ runQueue();
1202
+ };
1203
+ runQueue();
1204
+ }
1205
+ function treeForEach(tree, callback, options = {}) {
1206
+ const { childrenKey = "children", strategy = "pre", getChildrenKey } = options;
1207
+ const traversalMethod = strategies$1[strategy];
1208
+ const innerOptions = {
1209
+ childrenKey,
1210
+ depth: 0,
1211
+ parents: [],
1212
+ getChildrenKey
1213
+ };
1214
+ if (isArray(tree)) for (const row of tree) traversalMethod(row, callback, innerOptions);
1215
+ else traversalMethod(tree, callback, innerOptions);
1216
+ }
1217
+
1218
+ //#endregion
1219
+ //#region src/utils/tree/treeMap.ts
1220
+ const strategies = {
1221
+ pre: preImpl,
1222
+ post: postImpl,
1223
+ breadth: breadthImpl
1224
+ };
1225
+ function preImpl(row, callback, options) {
1226
+ const finalChildrenKey = getFinalChildrenKey(row, options, options);
1227
+ const result = callback(row, options);
1228
+ const children = row[finalChildrenKey];
1229
+ let newChildren;
1230
+ if (isArray(children)) {
1231
+ const nextLevelOptions = {
1232
+ ...options,
1233
+ parents: [...options.parents, row],
1234
+ depth: options.depth + 1
1235
+ };
1236
+ newChildren = children.map((c) => preImpl(c, callback, nextLevelOptions));
1237
+ }
1238
+ return {
1239
+ ...result,
1240
+ [finalChildrenKey]: newChildren
1241
+ };
1242
+ }
1243
+ function postImpl(row, callback, options) {
1244
+ const finalChildrenKey = getFinalChildrenKey(row, options, options);
1245
+ const children = row[finalChildrenKey];
1246
+ let newChildren;
1247
+ if (isArray(children)) {
1248
+ const nextLevelOptions = {
1249
+ ...options,
1250
+ parents: [...options.parents, row],
1251
+ depth: options.depth + 1
1252
+ };
1253
+ newChildren = children.map((c) => postImpl(c, callback, nextLevelOptions));
1254
+ }
1255
+ return {
1256
+ ...callback(row, options),
1257
+ [finalChildrenKey]: newChildren
1258
+ };
1259
+ }
1260
+ function breadthImpl(row, callback, options) {
1261
+ const queue = [{
1262
+ queueRow: row,
1263
+ queueOptions: options
1264
+ }];
1265
+ const cache = /* @__PURE__ */ new WeakMap();
1266
+ const childrenKeyCache = /* @__PURE__ */ new WeakMap();
1267
+ let result;
1268
+ const runQueue = () => {
1269
+ if (queue.length === 0) return result;
1270
+ const { queueRow, queueOptions } = queue.shift();
1271
+ const finalChildrenKey = getFinalChildrenKey(queueRow, queueOptions, queueOptions);
1272
+ const children = queueRow[finalChildrenKey];
1273
+ if (isArray(children)) {
1274
+ const nextLevelOptions = {
1275
+ ...queueOptions,
1276
+ parents: [...queueOptions.parents, queueRow],
1277
+ depth: queueOptions.depth + 1
1278
+ };
1279
+ const subQueueItems = children.map((queueRow$1) => ({
1280
+ queueRow: queueRow$1,
1281
+ queueOptions: nextLevelOptions
1282
+ }));
1283
+ queue.push(...subQueueItems);
1284
+ }
1285
+ const res = callback(queueRow, queueOptions);
1286
+ cache.set(queueRow, res);
1287
+ childrenKeyCache.set(queueRow, finalChildrenKey);
1288
+ const parent = arrayLast(queueOptions.parents);
1289
+ if (parent) {
1290
+ const newParent = cache.get(parent);
1291
+ const parentChildrenKey = childrenKeyCache.get(parent);
1292
+ if (newParent && parentChildrenKey) if (newParent[parentChildrenKey]) newParent[parentChildrenKey].push(res);
1293
+ else newParent[parentChildrenKey] = [res];
1294
+ }
1295
+ if (queueOptions.depth === 0) result = res;
1296
+ return runQueue();
1297
+ };
1298
+ return runQueue();
1299
+ }
1300
+ function treeMap(tree, callback, options = {}) {
1301
+ const { childrenKey = "children", strategy = "pre", getChildrenKey } = options;
1302
+ const traversalMethod = strategies[strategy];
1303
+ const innerOptions = {
1304
+ childrenKey,
1305
+ depth: 0,
1306
+ parents: [],
1307
+ getChildrenKey
1308
+ };
1309
+ return isArray(tree) ? tree.map((row) => traversalMethod(row, callback, innerOptions)) : traversalMethod(tree, callback, innerOptions);
1310
+ }
1311
+
1312
+ //#endregion
1313
+ //#region src/utils/tree/rowsToTree.ts
1314
+ /**
1315
+ * 行结构 转 树结构
1316
+ */
1317
+ function rowsToTree(rows, options) {
1318
+ const { parentIdKey = "parentId", rowKey = "id", childrenKey = "children" } = options || {};
1319
+ const result = [];
1320
+ const map = /* @__PURE__ */ new Map();
1321
+ for (const row of rows) {
1322
+ const id = row[rowKey];
1323
+ if (!map.get(id)) map.set(id, row);
1324
+ }
1325
+ for (const row of rows) {
1326
+ const parentId = row[parentIdKey];
1327
+ const parent = map.get(parentId);
1328
+ if (!parent || !parentId) {
1329
+ result.push(row);
1330
+ continue;
1331
+ }
1332
+ const siblings = parent[childrenKey];
1333
+ if (isNull(siblings) || isUndefined(siblings)) parent[childrenKey] = [row];
1334
+ else if (Array.isArray(siblings)) siblings.push(row);
1335
+ else {
1336
+ const message = `The key "${childrenKey.toString()}" in parent item is not an array.`;
1337
+ throw new Error(message);
1338
+ }
1339
+ }
1340
+ return result;
1341
+ }
1342
+
1343
+ //#endregion
1344
+ //#region src/utils/tree/treeToRows.ts
1345
+ /**
1346
+ * 树结构 转 行结构
1347
+ */
1348
+ function treeToRows(tree, options = {}) {
1349
+ const { childrenKey = "children" } = options;
1350
+ const result = [];
1351
+ if (!tree) return result;
1352
+ treeForEach(tree, (t) => result.push({
1353
+ ...t,
1354
+ [childrenKey]: void 0
1355
+ }), options);
1356
+ return result;
1357
+ }
1358
+
1359
+ //#endregion
1360
+ export { arrayCast, arrayCompete, arrayCounting, arrayDifference, arrayFirst, arrayFork, arrayIntersection, arrayLast, arrayMerge, arrayPick, arrayReplace, arraySplit, cloneDeep, enumEntries, enumKeys, enumTypeCheck, enumValues, isAbortSignal, isArray, isAsyncFunction, isAsyncGeneratorFunction, isBigInt, isBlob, isBoolean, isClass, isDate, isEqual, isError, isFalsy, isFalsyLike, isFile, isFunction, isGeneratorFunction, isInfinity, isInfinityLike, isInteger, isIterable, isMap, isNaN, isNegativeInteger, isNull, isNumber, isObject, isPositiveInteger, isPromise, isPromiseLike, isReadableStream, isRegExp, isSet, isString, isSymbol, isTypedArray, isURLSearchParams, isUndefined, isWeakMap, isWeakSet, isWebSocket, isWindow, mapEntries, objectAssign, objectCrush, objectEntries, objectKeys, objectPick, objectSwitch, objectValues, rowsToTree, stringInitialCase, stringReplace, stringTemplate, stringToJson, stringToNumber, stringToValues, to, toMathBignumber, toMathDecimal, toMathEvaluate, treeFilter, treeFind, treeForEach, treeMap, treeToRows };
1361
+ //# sourceMappingURL=index.js.map