@pawover/kit 0.0.0-alpha.2 → 0.0.0-alpha.21

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 (69) 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 +90 -0
  10. package/dist/hooks-react.d.ts.map +1 -0
  11. package/dist/hooks-react.js +296 -0
  12. package/dist/hooks-react.js.map +1 -0
  13. package/dist/index.d.ts +383 -0
  14. package/dist/index.d.ts.map +1 -0
  15. package/dist/index.js +1124 -2
  16. package/dist/index.js.map +1 -0
  17. package/dist/vite.d.ts +13 -0
  18. package/dist/vite.d.ts.map +1 -0
  19. package/dist/vite.js +22 -0
  20. package/dist/vite.js.map +1 -0
  21. package/dist/zod.d.ts +105 -0
  22. package/dist/zod.d.ts.map +1 -0
  23. package/dist/zod.js +138 -0
  24. package/dist/zod.js.map +1 -0
  25. package/metadata.json +139 -0
  26. package/package.json +46 -42
  27. package/dist/enums/index.js +0 -20
  28. package/dist/hooks/react/index.js +0 -5
  29. package/dist/hooks/react/useCreation.js +0 -11
  30. package/dist/hooks/react/useLatest.js +0 -6
  31. package/dist/hooks/react/useMount.js +0 -29
  32. package/dist/hooks/react/useResponsive.js +0 -59
  33. package/dist/hooks/react/useUnmount.js +0 -17
  34. package/dist/types/enums/index.d.ts +0 -20
  35. package/dist/types/hooks/react/index.d.ts +0 -5
  36. package/dist/types/hooks/react/useCreation.d.ts +0 -2
  37. package/dist/types/hooks/react/useLatest.d.ts +0 -1
  38. package/dist/types/hooks/react/useMount.d.ts +0 -11
  39. package/dist/types/hooks/react/useResponsive.d.ts +0 -16
  40. package/dist/types/hooks/react/useUnmount.d.ts +0 -6
  41. package/dist/types/index.d.ts +0 -2
  42. package/dist/types/utils/array.d.ts +0 -76
  43. package/dist/types/utils/index.d.ts +0 -6
  44. package/dist/types/utils/object.d.ts +0 -53
  45. package/dist/types/utils/string.d.ts +0 -13
  46. package/dist/types/utils/to.d.ts +0 -5
  47. package/dist/types/utils/tree/index.d.ts +0 -6
  48. package/dist/types/utils/tree/rowsToTree.d.ts +0 -10
  49. package/dist/types/utils/tree/treeFilter.d.ts +0 -6
  50. package/dist/types/utils/tree/treeFind.d.ts +0 -8
  51. package/dist/types/utils/tree/treeForEach.d.ts +0 -5
  52. package/dist/types/utils/tree/treeMap.d.ts +0 -6
  53. package/dist/types/utils/tree/treeToRows.d.ts +0 -9
  54. package/dist/types/utils/tree/types.d.ts +0 -24
  55. package/dist/types/utils/typeof.d.ts +0 -29
  56. package/dist/utils/array.js +0 -196
  57. package/dist/utils/index.js +0 -6
  58. package/dist/utils/object.js +0 -138
  59. package/dist/utils/string.js +0 -70
  60. package/dist/utils/to.js +0 -16
  61. package/dist/utils/tree/index.js +0 -6
  62. package/dist/utils/tree/rowsToTree.js +0 -35
  63. package/dist/utils/tree/treeFilter.js +0 -92
  64. package/dist/utils/tree/treeFind.js +0 -82
  65. package/dist/utils/tree/treeForEach.js +0 -60
  66. package/dist/utils/tree/treeMap.js +0 -79
  67. package/dist/utils/tree/treeToRows.js +0 -13
  68. package/dist/utils/tree/types.js +0 -10
  69. package/dist/utils/typeof.js +0 -114
package/dist/index.js CHANGED
@@ -1,2 +1,1124 @@
1
- export * from "./enums";
2
- export * from "./utils";
1
+ //#region src/utils/typeof/types.ts
2
+ const prototypeStrings = {
3
+ string: "[object String]",
4
+ number: "[object Number]",
5
+ boolean: "[object Boolean]",
6
+ object: "[object Object]",
7
+ array: "[object Array]",
8
+ bigInt: "[object BigInt]",
9
+ symbol: "[object Symbol]",
10
+ function: "[object Function]",
11
+ generatorFunction: "[object GeneratorFunction]",
12
+ asyncFunction: "[object AsyncFunction]",
13
+ promise: "[object Promise]",
14
+ null: "[object Null]",
15
+ undefined: "[object Undefined]",
16
+ date: "[object Date]",
17
+ regExp: "[object RegExp]",
18
+ error: "[object Error]",
19
+ file: "[object File]",
20
+ map: "[object Map]",
21
+ weakMap: "[object WeakMap]",
22
+ set: "[object Set]",
23
+ weakSet: "[object WeakSet]",
24
+ window: "[object Window]",
25
+ webSocket: "[object WebSocket]",
26
+ URLSearchParams: "[object URLSearchParams]"
27
+ };
28
+ function resolvePrototypeString(value) {
29
+ return Object.prototype.toString.call(value);
30
+ }
31
+
32
+ //#endregion
33
+ //#region src/utils/typeof/isArray.ts
34
+ function isArray(value) {
35
+ return resolvePrototypeString(value) === prototypeStrings.array;
36
+ }
37
+
38
+ //#endregion
39
+ //#region src/utils/typeof/isAsyncFunction.ts
40
+ function isAsyncFunction(value) {
41
+ return resolvePrototypeString(value) === prototypeStrings.asyncFunction;
42
+ }
43
+
44
+ //#endregion
45
+ //#region src/utils/typeof/isBigInt.ts
46
+ function isBigInt(value) {
47
+ return resolvePrototypeString(value) === prototypeStrings.bigInt;
48
+ }
49
+
50
+ //#endregion
51
+ //#region src/utils/typeof/isBoolean.ts
52
+ function isBoolean(value) {
53
+ return resolvePrototypeString(value) === prototypeStrings.boolean;
54
+ }
55
+
56
+ //#endregion
57
+ //#region src/utils/typeof/isClass.ts
58
+ function isClass(value) {
59
+ return resolvePrototypeString(value).startsWith("class ");
60
+ }
61
+
62
+ //#endregion
63
+ //#region src/utils/typeof/isDate.ts
64
+ function isDate(value) {
65
+ return resolvePrototypeString(value) === prototypeStrings.date;
66
+ }
67
+
68
+ //#endregion
69
+ //#region src/utils/typeof/isEqual.ts
70
+ /**
71
+ * 判断给定的值是否相等
72
+ * @reference https://github.com/radashi-org/radashi/blob/main/src/typed/isEqual.ts
73
+ *
74
+ * @param {T} x
75
+ * @param {T} y
76
+ */
77
+ function isEqual(x, y) {
78
+ if (Object.is(x, y)) return true;
79
+ if (x instanceof Date && y instanceof Date) return x.getTime() === y.getTime();
80
+ if (x instanceof RegExp && y instanceof RegExp) return x.toString() === y.toString();
81
+ if (typeof x !== "object" || x === null || typeof y !== "object" || y === null) return false;
82
+ const keysX = Reflect.ownKeys(x);
83
+ const keysY = Reflect.ownKeys(y);
84
+ if (keysX.length !== keysY.length) return false;
85
+ for (const key of keysX) {
86
+ if (!Reflect.has(y, key)) return false;
87
+ if (!isEqual(x[key], y[key])) return false;
88
+ }
89
+ return true;
90
+ }
91
+
92
+ //#endregion
93
+ //#region src/utils/typeof/isError.ts
94
+ function isError(value) {
95
+ return resolvePrototypeString(value) === prototypeStrings.error;
96
+ }
97
+
98
+ //#endregion
99
+ //#region src/utils/typeof/isFile.ts
100
+ function isFile(value) {
101
+ return resolvePrototypeString(value) === prototypeStrings.file;
102
+ }
103
+
104
+ //#endregion
105
+ //#region src/utils/typeof/isFunction.ts
106
+ function isFunction(value) {
107
+ return [
108
+ prototypeStrings.function,
109
+ prototypeStrings.generatorFunction,
110
+ prototypeStrings.asyncFunction
111
+ ].includes(resolvePrototypeString(value));
112
+ }
113
+
114
+ //#endregion
115
+ //#region src/utils/typeof/isGeneratorFunction.ts
116
+ function isGeneratorFunction(value) {
117
+ return resolvePrototypeString(value) === prototypeStrings.generatorFunction;
118
+ }
119
+
120
+ //#endregion
121
+ //#region src/utils/typeof/isInteger.ts
122
+ function isInteger(value) {
123
+ return Number.isInteger(value);
124
+ }
125
+
126
+ //#endregion
127
+ //#region src/utils/typeof/isObject.ts
128
+ function isObject(value) {
129
+ return resolvePrototypeString(value) === prototypeStrings.object;
130
+ }
131
+
132
+ //#endregion
133
+ //#region src/utils/typeof/isIterable.ts
134
+ function isIterable(value) {
135
+ return isObject(value) && Symbol.iterator in value;
136
+ }
137
+
138
+ //#endregion
139
+ //#region src/utils/typeof/isMap.ts
140
+ function isMap(value) {
141
+ return resolvePrototypeString(value) === prototypeStrings.map;
142
+ }
143
+
144
+ //#endregion
145
+ //#region src/utils/typeof/isNull.ts
146
+ function isNull(value) {
147
+ return resolvePrototypeString(value) === prototypeStrings.null;
148
+ }
149
+
150
+ //#endregion
151
+ //#region src/utils/typeof/isNumber.ts
152
+ function isNumber(value) {
153
+ return resolvePrototypeString(value) === prototypeStrings.number;
154
+ }
155
+
156
+ //#endregion
157
+ //#region src/utils/typeof/isPromise.ts
158
+ function isPromise(value) {
159
+ return resolvePrototypeString(value) === prototypeStrings.promise;
160
+ }
161
+
162
+ //#endregion
163
+ //#region src/utils/typeof/isPromiseLike.ts
164
+ function isPromiseLike(value) {
165
+ return isPromise(value) || isObject(value) && isFunction(value["then"]);
166
+ }
167
+
168
+ //#endregion
169
+ //#region src/utils/typeof/isRegExp.ts
170
+ function isRegExp(value) {
171
+ return resolvePrototypeString(value) === prototypeStrings.regExp;
172
+ }
173
+
174
+ //#endregion
175
+ //#region src/utils/typeof/isSet.ts
176
+ function isSet(value) {
177
+ return resolvePrototypeString(value) === prototypeStrings.set;
178
+ }
179
+
180
+ //#endregion
181
+ //#region src/utils/typeof/isString.ts
182
+ function isString(value) {
183
+ return resolvePrototypeString(value) === prototypeStrings.string;
184
+ }
185
+
186
+ //#endregion
187
+ //#region src/utils/typeof/isSymbol.ts
188
+ function isSymbol(value) {
189
+ return resolvePrototypeString(value) === prototypeStrings.symbol;
190
+ }
191
+
192
+ //#endregion
193
+ //#region src/utils/typeof/isUndefined.ts
194
+ function isUndefined(value) {
195
+ return resolvePrototypeString(value) === prototypeStrings.undefined;
196
+ }
197
+
198
+ //#endregion
199
+ //#region src/utils/typeof/isURLSearchParams.ts
200
+ function isURLSearchParams(value) {
201
+ return resolvePrototypeString(value) === prototypeStrings.URLSearchParams;
202
+ }
203
+
204
+ //#endregion
205
+ //#region src/utils/typeof/isWeakMap.ts
206
+ function isWeakMap(value) {
207
+ return resolvePrototypeString(value) === prototypeStrings.weakMap;
208
+ }
209
+
210
+ //#endregion
211
+ //#region src/utils/typeof/isWeakSet.ts
212
+ function isWeakSet(value) {
213
+ return resolvePrototypeString(value) === prototypeStrings.weakSet;
214
+ }
215
+
216
+ //#endregion
217
+ //#region src/utils/typeof/isWebSocket.ts
218
+ function isWebSocket(value) {
219
+ return resolvePrototypeString(value) === prototypeStrings.webSocket;
220
+ }
221
+
222
+ //#endregion
223
+ //#region src/utils/typeof/isWindow.ts
224
+ function isWindow(value) {
225
+ return resolvePrototypeString(value) === prototypeStrings.window;
226
+ }
227
+
228
+ //#endregion
229
+ //#region src/utils/array/arrayCast.ts
230
+ /**
231
+ * 构造数组
232
+ * @param candidate 待构造项
233
+ * @param checkEmpty 是否检查 `undefined` 和 `null`
234
+ */
235
+ function arrayCast(candidate, checkEmpty = true) {
236
+ if (checkEmpty && (isUndefined(candidate) || isNull(candidate))) return [];
237
+ return isArray(candidate) ? [...candidate] : [candidate];
238
+ }
239
+
240
+ //#endregion
241
+ //#region src/utils/array/arrayCompete.ts
242
+ /**
243
+ * 数组竞争
244
+ * - 返回在匹配函数的比较条件中获胜的最终项目,适用于更复杂的最小值/最大值计算
245
+ *
246
+ * @param initialList 数组
247
+ * @param match 匹配函数
248
+ */
249
+ function arrayCompete(initialList, match) {
250
+ if (!isArray(initialList) || initialList.length === 0 || !isFunction(match)) return null;
251
+ return initialList.reduce(match);
252
+ }
253
+
254
+ //#endregion
255
+ //#region src/utils/array/arrayCounting.ts
256
+ /**
257
+ * 统计数组的项目出现次数
258
+ * - 通过给定的标识符匹配函数,返回一个对象,其中键是回调函数返回的 key 值,每个值是一个整数,表示该 key 出现的次数
259
+ *
260
+ * @param initialList 初始数组
261
+ * @param match 匹配函数
262
+ */
263
+ function arrayCounting(initialList, match) {
264
+ if (!isArray(initialList) || !isFunction(match)) return {};
265
+ return initialList.reduce((prev, curr) => {
266
+ const id = match(curr).toString();
267
+ prev[id] = (prev[id] ?? 0) + 1;
268
+ return prev;
269
+ }, {});
270
+ }
271
+
272
+ //#endregion
273
+ //#region src/utils/array/arrayDifference.ts
274
+ /**
275
+ * 求数组差集
276
+ *
277
+ * @param initialList 初始数组
278
+ * @param diffList 对比数组
279
+ * @param match 匹配函数
280
+ */
281
+ function arrayDifference(initialList, diffList, match) {
282
+ if (!isArray(initialList) && !isArray(diffList)) return [];
283
+ if (!isArray(initialList) || !initialList.length) return [...diffList];
284
+ if (!isArray(diffList) || !diffList.length) return [...initialList];
285
+ if (!isFunction(match)) {
286
+ const arraySet = new Set(diffList);
287
+ return Array.from(new Set(initialList.filter((item) => !arraySet.has(item))));
288
+ }
289
+ const map = /* @__PURE__ */ new Map();
290
+ diffList.forEach((item) => {
291
+ map.set(match(item), true);
292
+ });
293
+ return initialList.filter((a) => !map.get(match(a)));
294
+ }
295
+
296
+ //#endregion
297
+ //#region src/utils/array/arrayFirst.ts
298
+ /**
299
+ * 获取数组第一项
300
+ *
301
+ * @param initialList 初始数组
302
+ * @param saveValue 安全值
303
+ */
304
+ function arrayFirst(initialList, saveValue) {
305
+ if (!isArray(initialList) || initialList.length === 0) return saveValue;
306
+ return initialList[0];
307
+ }
308
+
309
+ //#endregion
310
+ //#region src/utils/array/arrayFork.ts
311
+ /**
312
+ * 数组分组过滤
313
+ * - 给定一个数组和一个条件,返回一个由两个数组组成的元组,其中第一个数组包含所有满足条件的项,第二个数组包含所有不满足条件的项
314
+ *
315
+ * @param initialList 初始数组
316
+ * @param match 条件匹配函数
317
+ */
318
+ function arrayFork(initialList, match) {
319
+ const forked = [[], []];
320
+ if (isArray(initialList)) for (const item of initialList) forked[match(item) ? 0 : 1].push(item);
321
+ return forked;
322
+ }
323
+
324
+ //#endregion
325
+ //#region src/utils/array/arrayIntersection.ts
326
+ /**
327
+ * 求数组交集
328
+ *
329
+ * @param initialList 初始数组
330
+ * @param diffList 对比数组
331
+ * @param match 匹配函数
332
+ */
333
+ function arrayIntersection(initialList, diffList, match) {
334
+ if (!isArray(initialList) && !isArray(diffList)) return [];
335
+ if (!isArray(initialList) || !initialList.length) return [...diffList];
336
+ if (!isArray(diffList) || !diffList.length) return [...initialList];
337
+ if (!isFunction(match)) {
338
+ const arraySet = new Set(diffList);
339
+ return Array.from(new Set(initialList.filter((item) => arraySet.has(item))));
340
+ }
341
+ const map = /* @__PURE__ */ new Map();
342
+ diffList.forEach((item) => {
343
+ map.set(match(item), true);
344
+ });
345
+ return initialList.filter((a) => map.get(match(a)));
346
+ }
347
+
348
+ //#endregion
349
+ //#region src/utils/array/arrayLast.ts
350
+ /**
351
+ * 获取数组最后一项
352
+ *
353
+ * @param initialList 初始数组
354
+ * @param saveValue 安全值
355
+ */
356
+ function arrayLast(initialList, saveValue) {
357
+ if (!isArray(initialList) || initialList.length === 0) return saveValue;
358
+ return initialList[initialList.length - 1];
359
+ }
360
+
361
+ //#endregion
362
+ //#region src/utils/array/arrayMerge.ts
363
+ /**
364
+ * 数组合并
365
+ * - 通过给定的标识符匹配函数,用第二个数组中的匹配项替换第一个数组中匹配项的所有内容
366
+ *
367
+ * @param initialList 初始数组
368
+ * @param mergeList 待合并数组
369
+ * @param match 匹配函数
370
+ */
371
+ function arrayMerge(initialList, mergeList, match) {
372
+ if (!isArray(initialList)) return [];
373
+ if (!isArray(mergeList)) return [...initialList];
374
+ if (!isFunction(match)) return Array.from(new Set([...initialList, ...mergeList]));
375
+ const keys = /* @__PURE__ */ new Map();
376
+ for (const item of mergeList) keys.set(match(item), item);
377
+ return initialList.map((prevItem) => {
378
+ const key = match(prevItem);
379
+ return keys.has(key) ? keys.get(key) : prevItem;
380
+ });
381
+ }
382
+
383
+ //#endregion
384
+ //#region src/utils/array/arrayPick.ts
385
+ /**
386
+ * 数组选择
387
+ * - 一次性应用 `filter` 和 `map` 操作
388
+ *
389
+ * @param initialList 初始数组
390
+ * @param filter filter 函数
391
+ * @param mapper map 函数
392
+ */
393
+ function arrayPick(initialList, filter, mapper) {
394
+ if (!isArray(initialList)) return [];
395
+ if (!isFunction(filter)) return [...initialList];
396
+ const hasMapper = isFunction(mapper);
397
+ return initialList.reduce((prev, curr, index) => {
398
+ if (!filter(curr, index)) return prev;
399
+ if (hasMapper) prev.push(mapper(curr, index));
400
+ else prev.push(curr);
401
+ return prev;
402
+ }, []);
403
+ }
404
+
405
+ //#endregion
406
+ //#region src/utils/array/arrayReplace.ts
407
+ /**
408
+ * 数组项替换
409
+ * - 在给定的数组中,替换符合匹配函数结果的项目。只替换第一个匹配项。始终返回原始数组的副本。
410
+ *
411
+ * @param initialList 初始数组
412
+ * @param newItem 替换项
413
+ * @param match 匹配函数
414
+ */
415
+ function arrayReplace(initialList, newItem, match) {
416
+ if (!initialList) return [];
417
+ if (newItem === void 0 || !isFunction(match)) return [...initialList];
418
+ for (let i = 0; i < initialList.length; i++) {
419
+ const item = initialList[i];
420
+ if (item !== void 0 && match(item, i)) return [
421
+ ...initialList.slice(0, i),
422
+ newItem,
423
+ ...initialList.slice(i + 1, initialList.length)
424
+ ];
425
+ }
426
+ return [...initialList];
427
+ }
428
+
429
+ //#endregion
430
+ //#region src/utils/array/arraySplit.ts
431
+ /**
432
+ * 数组切分
433
+ * - 将数组以指定的长度切分后,组合在高维数组中
434
+ *
435
+ * @param initialList 初始数组
436
+ * @param size 分割尺寸,默认 `10`
437
+ */
438
+ function arraySplit(initialList, size = 10) {
439
+ if (!isArray(initialList)) return [];
440
+ const count = Math.ceil(initialList.length / size);
441
+ return Array.from({ length: count }).fill(null).map((_c, i) => {
442
+ return initialList.slice(i * size, i * size + size);
443
+ });
444
+ }
445
+
446
+ //#endregion
447
+ //#region src/utils/function/to.ts
448
+ /**
449
+ * @param promise
450
+ * @param errorExt - 可以传递给err对象的其他信息
451
+ */
452
+ function to(promise, errorExt) {
453
+ return promise.then((data) => [null, data]).catch((err) => {
454
+ if (errorExt) return [{
455
+ ...err,
456
+ ...errorExt
457
+ }, void 0];
458
+ return [err ? err : /* @__PURE__ */ new Error("defaultError"), void 0];
459
+ });
460
+ }
461
+
462
+ //#endregion
463
+ //#region src/utils/object/cloneDeep.ts
464
+ const DefaultCloningStrategy = {
465
+ cloneMap(input, track, clone) {
466
+ const output = track(/* @__PURE__ */ new Map());
467
+ for (const [key, value] of input) output.set(key, clone(value));
468
+ return output;
469
+ },
470
+ cloneSet(input, track, clone) {
471
+ const output = track(/* @__PURE__ */ new Set());
472
+ for (const value of input) output.add(clone(value));
473
+ return output;
474
+ },
475
+ cloneArray(input, track, clone) {
476
+ const output = track(new Array(input.length));
477
+ input.forEach((value, index) => {
478
+ output[index] = clone(value);
479
+ });
480
+ return output;
481
+ },
482
+ cloneObject(input, track, clone) {
483
+ const output = track(Object.create(Object.getPrototypeOf(input)));
484
+ for (const key of Reflect.ownKeys(input)) {
485
+ const descriptor = Object.getOwnPropertyDescriptor(input, key);
486
+ if ("value" in descriptor) descriptor.value = clone(descriptor.value);
487
+ Object.defineProperty(output, key, descriptor);
488
+ }
489
+ return output;
490
+ },
491
+ cloneOther(input, track) {
492
+ return track(input);
493
+ }
494
+ };
495
+ /**
496
+ * cloneDeep
497
+ * @reference https://github.com/radashi-org/radashi/blob/main/src/object/cloneDeep.ts
498
+ */
499
+ function cloneDeep(root, customStrategy) {
500
+ const strategy = {
501
+ ...DefaultCloningStrategy,
502
+ ...customStrategy
503
+ };
504
+ const tracked = /* @__PURE__ */ new Map();
505
+ const track = (parent, newParent) => {
506
+ tracked.set(parent, newParent);
507
+ return newParent;
508
+ };
509
+ const clone = (value) => {
510
+ return value && typeof value === "object" ? tracked.get(value) ?? cloneDeep$1(value, strategy) : value;
511
+ };
512
+ const cloneDeep$1 = (parent, strategy$1) => {
513
+ 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);
514
+ if (!newParent) return cloneDeep$1(parent, DefaultCloningStrategy);
515
+ tracked.set(parent, newParent);
516
+ return newParent;
517
+ };
518
+ return cloneDeep$1(root, strategy);
519
+ }
520
+
521
+ //#endregion
522
+ //#region src/utils/object/objectKeys.ts
523
+ /**
524
+ * 返回对象的可枚举属性和方法的名称
525
+ * - `Object.keys` 始终返回 `string[]` 类型,此函数可以返回具体类型
526
+ *
527
+ * @param obj 对象
528
+ */
529
+ function objectKeys(obj) {
530
+ return Object.keys(obj);
531
+ }
532
+
533
+ //#endregion
534
+ //#region src/utils/object/enumTypeCheck.ts
535
+ function enumTypeCheck(enumeration) {
536
+ if (!isObject(enumeration)) throw Error(`function enumKeys expected parameter is a enum, but got ${typeof enumeration}`);
537
+ if (!objectKeys(enumeration).length) throw Error("Enum requires at least one member");
538
+ return enumeration;
539
+ }
540
+
541
+ //#endregion
542
+ //#region src/utils/object/objectEntries.ts
543
+ /**
544
+ * 返回对象的可枚举属性的键/值数组
545
+ *
546
+ * @param obj 对象
547
+ */
548
+ function objectEntries(obj) {
549
+ return Object.entries(obj);
550
+ }
551
+
552
+ //#endregion
553
+ //#region src/utils/object/objectValues.ts
554
+ /**
555
+ * 返回对象的可枚举属性的值数组
556
+ *
557
+ * @param obj 对象
558
+ */
559
+ function objectValues(obj) {
560
+ return Object.values(obj);
561
+ }
562
+
563
+ //#endregion
564
+ //#region src/utils/object/enumEntries.ts
565
+ /**
566
+ * 返回枚举的属性的键/值数组
567
+ *
568
+ * @param enumeration 枚举
569
+ */
570
+ function enumEntries(enumeration) {
571
+ const e = enumTypeCheck(enumeration);
572
+ const keys = objectKeys(e);
573
+ const values = objectValues(e);
574
+ const entries = objectEntries(e);
575
+ if (keys.every((k) => values.some((v) => `${v}` === k))) return entries.splice(keys.length / 2, keys.length / 2);
576
+ return entries;
577
+ }
578
+
579
+ //#endregion
580
+ //#region src/utils/object/enumKeys.ts
581
+ /**
582
+ * 获取枚举所有属性的键
583
+ *
584
+ * @param enumeration 枚举
585
+ */
586
+ function enumKeys(enumeration) {
587
+ const e = enumTypeCheck(enumeration);
588
+ const keys = objectKeys(e);
589
+ const values = objectValues(e);
590
+ if (keys.every((k) => values.some((v) => `${v}` === k))) return keys.splice(keys.length / 2, keys.length / 2);
591
+ return keys;
592
+ }
593
+
594
+ //#endregion
595
+ //#region src/utils/object/enumValues.ts
596
+ /**
597
+ * 获取枚举所有属性的值
598
+ *
599
+ * @param enumeration 枚举
600
+ */
601
+ function enumValues(enumeration) {
602
+ const e = enumTypeCheck(enumeration);
603
+ const keys = objectKeys(e);
604
+ const values = objectValues(e);
605
+ if (keys.every((k) => values.some((v) => `${v}` === k))) return values.splice(keys.length / 2, keys.length / 2);
606
+ return values;
607
+ }
608
+
609
+ //#endregion
610
+ //#region src/utils/object/mapEntries.ts
611
+ function mapEntries(obj, toEntry) {
612
+ const defaultResult = {};
613
+ if (!obj) return defaultResult;
614
+ return objectEntries(obj).reduce((acc, [key, value]) => {
615
+ const [newKey, newValue] = toEntry(key, value);
616
+ acc[newKey] = newValue;
617
+ return acc;
618
+ }, defaultResult);
619
+ }
620
+
621
+ //#endregion
622
+ //#region node_modules/.pnpm/radashi@12.7.1/node_modules/radashi/dist/radashi.js
623
+ function assign(initial, override) {
624
+ if (!initial || !override) return initial ?? override ?? {};
625
+ const proto = Object.getPrototypeOf(initial);
626
+ const merged = proto ? { ...initial } : Object.assign(Object.create(proto), initial);
627
+ for (const key of Object.keys(override)) merged[key] = isPlainObject(initial[key]) && isPlainObject(override[key]) ? assign(initial[key], override[key]) : override[key];
628
+ return merged;
629
+ }
630
+ function isPlainObject(value) {
631
+ if (typeof value !== "object" || value === null) return false;
632
+ const prototype = Object.getPrototypeOf(value);
633
+ return prototype === Object.prototype || prototype === null || Object.getPrototypeOf(prototype) === null;
634
+ }
635
+
636
+ //#endregion
637
+ //#region src/utils/object/objectAssign.ts
638
+ const objectAssign = assign;
639
+
640
+ //#endregion
641
+ //#region src/utils/object/objectPick.ts
642
+ function objectPick(obj, keys) {
643
+ const result = {};
644
+ if (!isObject(obj)) return result;
645
+ if (!isArray(keys)) return obj;
646
+ return keys.reduce((acc, curr) => {
647
+ if (curr in obj) acc[curr] = obj[curr];
648
+ return acc;
649
+ }, result);
650
+ }
651
+
652
+ //#endregion
653
+ //#region src/utils/object/objectSwitch.ts
654
+ /**
655
+ * 对象反转
656
+ * - 返回交换了对象的可枚举属性的值/键对象
657
+ *
658
+ * @param obj 对象
659
+ */
660
+ function objectSwitch(obj) {
661
+ const result = {};
662
+ if (!isObject(obj)) return result;
663
+ for (const [k, v] of objectEntries(obj)) result[v] = k;
664
+ return result;
665
+ }
666
+
667
+ //#endregion
668
+ //#region src/utils/string/stringInitialCase.ts
669
+ const m1 = /\S+/g;
670
+ const m2 = /[^a-zA-Z\u00C0-\u017F]/;
671
+ /**
672
+ * 首字母大小写
673
+ */
674
+ function stringInitialCase(value, type) {
675
+ if (!isString(value) || value.length === 0) return value;
676
+ return value.replace(m1, (word) => {
677
+ if (m2.test(word)) return word;
678
+ if (word === word.toLocaleUpperCase()) return word;
679
+ if (type === "lower" && word[0]) return word[0].toLocaleLowerCase() + word.slice(1);
680
+ if (type === "upper" && word[0]) return word[0].toLocaleUpperCase() + word.slice(1);
681
+ return word;
682
+ });
683
+ }
684
+
685
+ //#endregion
686
+ //#region src/utils/string/stringReplace.ts
687
+ function stringReplace(input, search, replacement) {
688
+ return input.replace(search, replacement);
689
+ }
690
+
691
+ //#endregion
692
+ //#region src/utils/string/stringToJson.ts
693
+ function stringToJson(data, safeValue) {
694
+ if (isString(data) && data) try {
695
+ return JSON.parse(data);
696
+ } catch (error) {
697
+ return safeValue;
698
+ }
699
+ else return safeValue;
700
+ }
701
+
702
+ //#endregion
703
+ //#region src/utils/string/stringToValues.ts
704
+ function stringToValues(data, valueType = "number", splitSymbol = ",") {
705
+ if (isString(data) && data) try {
706
+ const values = data.split(splitSymbol);
707
+ if (valueType === "number") return values.map((d) => Number(d));
708
+ return values;
709
+ } catch (error) {
710
+ return [];
711
+ }
712
+ else return [];
713
+ }
714
+
715
+ //#endregion
716
+ //#region src/utils/tree/types.ts
717
+ function getFinalChildrenKey(tree, meta, options) {
718
+ if (isFunction(options.getChildrenKey)) {
719
+ const dynamicChildrenKey = options.getChildrenKey(tree, meta);
720
+ if (dynamicChildrenKey && dynamicChildrenKey !== null) return dynamicChildrenKey;
721
+ }
722
+ return options.childrenKey;
723
+ }
724
+
725
+ //#endregion
726
+ //#region src/utils/tree/treeFilter.ts
727
+ function preImpl$3(row, callback, options) {
728
+ if (!callback(row, options)) return;
729
+ const finalChildrenKey = getFinalChildrenKey(row, options, options);
730
+ const children = row[finalChildrenKey];
731
+ let newChildren;
732
+ if (isArray(children)) {
733
+ const nextLevelOptions = {
734
+ ...options,
735
+ parents: [...options.parents, row],
736
+ depth: options.depth + 1
737
+ };
738
+ newChildren = children.map((c) => preImpl$3(c, callback, nextLevelOptions)).filter((c) => !!c);
739
+ }
740
+ return {
741
+ ...row,
742
+ [finalChildrenKey]: newChildren
743
+ };
744
+ }
745
+ function postImpl$3(row, callback, options) {
746
+ const finalChildrenKey = getFinalChildrenKey(row, options, options);
747
+ const children = row[finalChildrenKey];
748
+ let newChildren;
749
+ if (isArray(children)) {
750
+ const nextLevelOptions = {
751
+ ...options,
752
+ parents: [...options.parents, row],
753
+ depth: options.depth + 1
754
+ };
755
+ newChildren = children.map((c) => preImpl$3(c, callback, nextLevelOptions)).filter((c) => !!c);
756
+ }
757
+ if (!callback(row, options)) return;
758
+ return {
759
+ ...row,
760
+ [finalChildrenKey]: newChildren
761
+ };
762
+ }
763
+ function breadthImpl$3(row, callback, options) {
764
+ const queue = [{
765
+ queueRow: row,
766
+ queueOptions: options
767
+ }];
768
+ const resultCache = /* @__PURE__ */ new WeakMap();
769
+ const newNodeCache = /* @__PURE__ */ new WeakMap();
770
+ const childrenKeyCache = /* @__PURE__ */ new WeakMap();
771
+ let result;
772
+ const runQueue = () => {
773
+ if (queue.length === 0) return result;
774
+ const { queueRow, queueOptions } = queue.shift();
775
+ const finalChildrenKey = getFinalChildrenKey(queueRow, queueOptions, queueOptions);
776
+ const children = queueRow[finalChildrenKey];
777
+ if (isArray(children)) {
778
+ const nextLevelOptions = {
779
+ ...queueOptions,
780
+ parents: [...queueOptions.parents, queueRow],
781
+ depth: queueOptions.depth + 1
782
+ };
783
+ const subQueueItems = children.map((queueRow$1) => ({
784
+ queueRow: queueRow$1,
785
+ queueOptions: nextLevelOptions
786
+ }));
787
+ queue.push(...subQueueItems);
788
+ }
789
+ const parent = arrayLast(queueOptions.parents);
790
+ const isTopNode = queueOptions.depth === 0;
791
+ const parentResult = parent && resultCache.get(parent);
792
+ if (!isTopNode && !parentResult) return runQueue();
793
+ const callbackResult = callback(queueRow, queueOptions);
794
+ if (isTopNode && !callbackResult) return;
795
+ const newNode = {
796
+ ...queueRow,
797
+ [finalChildrenKey]: void 0
798
+ };
799
+ if (isTopNode) result = newNode;
800
+ resultCache.set(queueRow, callbackResult);
801
+ newNodeCache.set(queueRow, newNode);
802
+ childrenKeyCache.set(queueRow, finalChildrenKey);
803
+ if (callbackResult && parent) {
804
+ const parentNewNode = newNodeCache.get(parent);
805
+ const parentChildrenKey = childrenKeyCache.get(parent);
806
+ if (parentNewNode && parentChildrenKey) {
807
+ if (!parentNewNode[parentChildrenKey]) parentNewNode[parentChildrenKey] = [];
808
+ parentNewNode[parentChildrenKey].push(newNode);
809
+ }
810
+ }
811
+ return runQueue();
812
+ };
813
+ return runQueue();
814
+ }
815
+ const strategies$3 = {
816
+ pre: preImpl$3,
817
+ post: postImpl$3,
818
+ breadth: breadthImpl$3
819
+ };
820
+ function treeFilter(tree, callback, options = {}) {
821
+ const { childrenKey = "children", strategy = "pre", getChildrenKey } = options;
822
+ const traversalMethod = strategies$3[strategy];
823
+ const innerOptions = {
824
+ childrenKey,
825
+ depth: 0,
826
+ parents: [],
827
+ getChildrenKey
828
+ };
829
+ return isArray(tree) ? tree.map((row) => traversalMethod(row, callback, innerOptions)).filter((t) => !!t) : traversalMethod(tree, callback, innerOptions) || [];
830
+ }
831
+
832
+ //#endregion
833
+ //#region src/utils/tree/treeFind.ts
834
+ const strategies$2 = {
835
+ pre: preImpl$2,
836
+ post: postImpl$2,
837
+ breadth: breadthImpl$2
838
+ };
839
+ function preImpl$2(row, callback, options) {
840
+ if (callback(row, options)) return row;
841
+ const children = row[getFinalChildrenKey(row, options, options)];
842
+ if (isArray(children)) for (const child of children) {
843
+ const result = preImpl$2(child, callback, {
844
+ ...options,
845
+ parents: [...options.parents, row],
846
+ depth: options.depth + 1
847
+ });
848
+ if (result) return result;
849
+ }
850
+ }
851
+ function postImpl$2(row, callback, options) {
852
+ const children = row[getFinalChildrenKey(row, options, options)];
853
+ if (isArray(children)) for (const child of children) {
854
+ const result = postImpl$2(child, callback, {
855
+ ...options,
856
+ parents: [...options.parents, row],
857
+ depth: options.depth + 1
858
+ });
859
+ if (result) return result;
860
+ }
861
+ if (callback(row, options)) return row;
862
+ }
863
+ function breadthImpl$2(row, callback, options) {
864
+ const queue = [{
865
+ queueRow: row,
866
+ queueOptions: options
867
+ }];
868
+ const runQueue = () => {
869
+ if (queue.length === 0) return;
870
+ const { queueRow, queueOptions } = queue.shift();
871
+ const children = queueRow[getFinalChildrenKey(queueRow, queueOptions, queueOptions)];
872
+ if (isArray(children)) {
873
+ const nextLevelOptions = {
874
+ ...queueOptions,
875
+ parents: [...queueOptions.parents, queueRow],
876
+ depth: queueOptions.depth + 1
877
+ };
878
+ const subQueueItems = children.map((queueRow$1) => ({
879
+ queueRow: queueRow$1,
880
+ queueOptions: nextLevelOptions
881
+ }));
882
+ queue.push(...subQueueItems);
883
+ }
884
+ if (callback(queueRow, queueOptions)) return queueRow;
885
+ return runQueue();
886
+ };
887
+ return runQueue();
888
+ }
889
+ /**
890
+ * 查找树节点,找到第一个返回非空值的节点
891
+ */
892
+ function treeFind(tree, callback, options = {}) {
893
+ const { childrenKey = "children", strategy = "pre", getChildrenKey } = options;
894
+ const traversalMethod = strategies$2[strategy];
895
+ const innerOptions = {
896
+ childrenKey,
897
+ depth: 0,
898
+ parents: [],
899
+ getChildrenKey
900
+ };
901
+ if (isArray(tree)) {
902
+ for (const row of tree) {
903
+ const result = traversalMethod(row, callback, innerOptions);
904
+ if (result) return result;
905
+ }
906
+ return;
907
+ }
908
+ return traversalMethod(tree, callback, innerOptions);
909
+ }
910
+
911
+ //#endregion
912
+ //#region src/utils/tree/treeForEach.ts
913
+ const strategies$1 = {
914
+ pre: preImpl$1,
915
+ post: postImpl$1,
916
+ breadth: breadthImpl$1
917
+ };
918
+ function preImpl$1(row, callback, options) {
919
+ callback(row, options);
920
+ const children = row[getFinalChildrenKey(row, options, options)];
921
+ if (isArray(children)) {
922
+ const nextLevelOptions = {
923
+ ...options,
924
+ parents: [...options.parents, row],
925
+ depth: options.depth + 1
926
+ };
927
+ for (const child of children) preImpl$1(child, callback, nextLevelOptions);
928
+ }
929
+ }
930
+ function postImpl$1(row, callback, options) {
931
+ const children = row[getFinalChildrenKey(row, options, options)];
932
+ if (isArray(children)) {
933
+ const nextLevelOptions = {
934
+ ...options,
935
+ parents: [...options.parents, row],
936
+ depth: options.depth + 1
937
+ };
938
+ for (const child of children) postImpl$1(child, callback, nextLevelOptions);
939
+ }
940
+ callback(row, options);
941
+ }
942
+ function breadthImpl$1(row, callback, options) {
943
+ const queue = [{
944
+ queueRow: row,
945
+ queueOptions: options
946
+ }];
947
+ const runQueue = () => {
948
+ if (queue.length === 0) return;
949
+ const { queueRow, queueOptions } = queue.shift();
950
+ const children = queueRow[getFinalChildrenKey(queueRow, queueOptions, queueOptions)];
951
+ if (isArray(children)) {
952
+ const nextLevelOptions = {
953
+ ...queueOptions,
954
+ parents: [...queueOptions.parents, queueRow],
955
+ depth: queueOptions.depth + 1
956
+ };
957
+ const subQueueItems = children.map((queueRow$1) => ({
958
+ queueRow: queueRow$1,
959
+ queueOptions: nextLevelOptions
960
+ }));
961
+ queue.push(...subQueueItems);
962
+ }
963
+ callback(queueRow, queueOptions);
964
+ runQueue();
965
+ };
966
+ runQueue();
967
+ }
968
+ function treeForEach(tree, callback, options = {}) {
969
+ const { childrenKey = "children", strategy = "pre", getChildrenKey } = options;
970
+ const traversalMethod = strategies$1[strategy];
971
+ const innerOptions = {
972
+ childrenKey,
973
+ depth: 0,
974
+ parents: [],
975
+ getChildrenKey
976
+ };
977
+ if (isArray(tree)) for (const row of tree) traversalMethod(row, callback, innerOptions);
978
+ else traversalMethod(tree, callback, innerOptions);
979
+ }
980
+
981
+ //#endregion
982
+ //#region src/utils/tree/treeMap.ts
983
+ const strategies = {
984
+ pre: preImpl,
985
+ post: postImpl,
986
+ breadth: breadthImpl
987
+ };
988
+ function preImpl(row, callback, options) {
989
+ const finalChildrenKey = getFinalChildrenKey(row, options, options);
990
+ const result = callback(row, options);
991
+ const children = row[finalChildrenKey];
992
+ let newChildren;
993
+ if (isArray(children)) {
994
+ const nextLevelOptions = {
995
+ ...options,
996
+ parents: [...options.parents, row],
997
+ depth: options.depth + 1
998
+ };
999
+ newChildren = children.map((c) => preImpl(c, callback, nextLevelOptions));
1000
+ }
1001
+ return {
1002
+ ...result,
1003
+ [finalChildrenKey]: newChildren
1004
+ };
1005
+ }
1006
+ function postImpl(row, callback, options) {
1007
+ const finalChildrenKey = getFinalChildrenKey(row, options, options);
1008
+ const children = row[finalChildrenKey];
1009
+ let newChildren;
1010
+ if (isArray(children)) {
1011
+ const nextLevelOptions = {
1012
+ ...options,
1013
+ parents: [...options.parents, row],
1014
+ depth: options.depth + 1
1015
+ };
1016
+ newChildren = children.map((c) => postImpl(c, callback, nextLevelOptions));
1017
+ }
1018
+ return {
1019
+ ...callback(row, options),
1020
+ [finalChildrenKey]: newChildren
1021
+ };
1022
+ }
1023
+ function breadthImpl(row, callback, options) {
1024
+ const queue = [{
1025
+ queueRow: row,
1026
+ queueOptions: options
1027
+ }];
1028
+ const cache = /* @__PURE__ */ new WeakMap();
1029
+ const childrenKeyCache = /* @__PURE__ */ new WeakMap();
1030
+ let result;
1031
+ const runQueue = () => {
1032
+ if (queue.length === 0) return result;
1033
+ const { queueRow, queueOptions } = queue.shift();
1034
+ const finalChildrenKey = getFinalChildrenKey(queueRow, queueOptions, queueOptions);
1035
+ const children = queueRow[finalChildrenKey];
1036
+ if (isArray(children)) {
1037
+ const nextLevelOptions = {
1038
+ ...queueOptions,
1039
+ parents: [...queueOptions.parents, queueRow],
1040
+ depth: queueOptions.depth + 1
1041
+ };
1042
+ const subQueueItems = children.map((queueRow$1) => ({
1043
+ queueRow: queueRow$1,
1044
+ queueOptions: nextLevelOptions
1045
+ }));
1046
+ queue.push(...subQueueItems);
1047
+ }
1048
+ const res = callback(queueRow, queueOptions);
1049
+ cache.set(queueRow, res);
1050
+ childrenKeyCache.set(queueRow, finalChildrenKey);
1051
+ const parent = arrayLast(queueOptions.parents);
1052
+ if (parent) {
1053
+ const newParent = cache.get(parent);
1054
+ const parentChildrenKey = childrenKeyCache.get(parent);
1055
+ if (newParent && parentChildrenKey) if (newParent[parentChildrenKey]) newParent[parentChildrenKey].push(res);
1056
+ else newParent[parentChildrenKey] = [res];
1057
+ }
1058
+ if (queueOptions.depth === 0) result = res;
1059
+ return runQueue();
1060
+ };
1061
+ return runQueue();
1062
+ }
1063
+ function treeMap(tree, callback, options = {}) {
1064
+ const { childrenKey = "children", strategy = "pre", getChildrenKey } = options;
1065
+ const traversalMethod = strategies[strategy];
1066
+ const innerOptions = {
1067
+ childrenKey,
1068
+ depth: 0,
1069
+ parents: [],
1070
+ getChildrenKey
1071
+ };
1072
+ return isArray(tree) ? tree.map((row) => traversalMethod(row, callback, innerOptions)) : traversalMethod(tree, callback, innerOptions);
1073
+ }
1074
+
1075
+ //#endregion
1076
+ //#region src/utils/tree/rowsToTree.ts
1077
+ /**
1078
+ * 行结构 转 树结构
1079
+ */
1080
+ function rowsToTree(rows, options) {
1081
+ const { parentIdKey = "parentId", rowKey = "id", childrenKey = "children" } = options || {};
1082
+ const result = [];
1083
+ const map = /* @__PURE__ */ new Map();
1084
+ for (const row of rows) {
1085
+ const id = row[rowKey];
1086
+ if (!map.get(id)) map.set(id, row);
1087
+ }
1088
+ for (const row of rows) {
1089
+ const parentId = row[parentIdKey];
1090
+ const parent = map.get(parentId);
1091
+ if (!parent || !parentId) {
1092
+ result.push(row);
1093
+ continue;
1094
+ }
1095
+ const siblings = parent[childrenKey];
1096
+ if (isNull(siblings) || isUndefined(siblings)) parent[childrenKey] = [row];
1097
+ else if (Array.isArray(siblings)) siblings.push(row);
1098
+ else {
1099
+ const message = `The key "${childrenKey.toString()}" in parent item is not an array.`;
1100
+ throw new Error(message);
1101
+ }
1102
+ }
1103
+ return result;
1104
+ }
1105
+
1106
+ //#endregion
1107
+ //#region src/utils/tree/treeToRows.ts
1108
+ /**
1109
+ * 树结构 转 行结构
1110
+ */
1111
+ function treeToRows(tree, options = {}) {
1112
+ const { childrenKey = "children" } = options;
1113
+ const result = [];
1114
+ if (!tree) return result;
1115
+ treeForEach(tree, (t) => result.push({
1116
+ ...t,
1117
+ [childrenKey]: void 0
1118
+ }), options);
1119
+ return result;
1120
+ }
1121
+
1122
+ //#endregion
1123
+ export { arrayCast, arrayCompete, arrayCounting, arrayDifference, arrayFirst, arrayFork, arrayIntersection, arrayLast, arrayMerge, arrayPick, arrayReplace, arraySplit, cloneDeep, enumEntries, enumKeys, enumTypeCheck, enumValues, isArray, isAsyncFunction, isBigInt, isBoolean, isClass, isDate, isEqual, isError, isFile, isFunction, isGeneratorFunction, isInteger, isIterable, isMap, isNull, isNumber, isObject, isPromise, isPromiseLike, isRegExp, isSet, isString, isSymbol, isURLSearchParams, isUndefined, isWeakMap, isWeakSet, isWebSocket, isWindow, mapEntries, objectAssign, objectEntries, objectKeys, objectPick, objectSwitch, objectValues, rowsToTree, stringInitialCase, stringReplace, stringToJson, stringToValues, to, treeFilter, treeFind, treeForEach, treeMap, treeToRows };
1124
+ //# sourceMappingURL=index.js.map