@pawover/kit 0.0.0-beta.41 → 0.0.0-beta.43
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.
- package/dist/enums.d.ts +1 -1
- package/dist/enums.js +144 -2
- package/dist/enums.js.map +1 -0
- package/dist/{except-MacUK44u.d.ts → except-6l9Qdmn1.d.ts} +53 -38
- package/dist/except-6l9Qdmn1.d.ts.map +1 -0
- package/dist/hooks-alova.d.ts.map +1 -1
- package/dist/hooks-alova.js +1 -4
- package/dist/hooks-alova.js.map +1 -1
- package/dist/hooks-react.d.ts +43 -12
- package/dist/hooks-react.d.ts.map +1 -1
- package/dist/hooks-react.js +52 -49
- package/dist/hooks-react.js.map +1 -1
- package/dist/{index-DBPmnr4a.d.ts → index-D0_YLsqN.d.ts} +2 -5
- package/dist/index-D0_YLsqN.d.ts.map +1 -0
- package/dist/index-JKtXbRi8.d.ts +149 -0
- package/dist/index-JKtXbRi8.d.ts.map +1 -0
- package/dist/index.d.ts +400 -111
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -3
- package/dist/patches-fetchEventSource.d.ts +2 -2
- package/dist/patches-fetchEventSource.d.ts.map +1 -1
- package/dist/patches-fetchEventSource.js +2 -4
- package/dist/patches-fetchEventSource.js.map +1 -1
- package/dist/{utils-_dtCs-qa.js → utils-DvWLCdYR.js} +282 -356
- package/dist/utils-DvWLCdYR.js.map +1 -0
- package/dist/{value-of-DUmTbnuw.d.ts → value-of-Dz22arsm.d.ts} +2 -2
- package/dist/value-of-Dz22arsm.d.ts.map +1 -0
- package/dist/vite.d.ts +0 -1
- package/dist/vite.d.ts.map +1 -1
- package/dist/vite.js +2 -2
- package/dist/vite.js.map +1 -1
- package/dist/zod.d.ts.map +1 -1
- package/dist/zod.js +31 -69
- package/dist/zod.js.map +1 -1
- package/metadata.json +0 -3
- package/package.json +18 -12
- package/dist/enums-BL6w5-mS.js +0 -148
- package/dist/enums-BL6w5-mS.js.map +0 -1
- package/dist/except-MacUK44u.d.ts.map +0 -1
- package/dist/index-Bn_PNnsM.d.ts +0 -212
- package/dist/index-Bn_PNnsM.d.ts.map +0 -1
- package/dist/index-DBPmnr4a.d.ts.map +0 -1
- package/dist/utils-_dtCs-qa.js.map +0 -1
- package/dist/value-of-DUmTbnuw.d.ts.map +0 -1
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { clone, cloneDeep, cloneDeepWith } from "lodash-es";
|
|
2
|
-
|
|
3
1
|
//#region src/utils/typeof/types.ts
|
|
4
2
|
const PROTOTYPE_TAGS = Object.freeze({
|
|
5
3
|
abortSignal: "[object AbortSignal]",
|
|
@@ -46,10 +44,19 @@ const TYPED_ARRAY_TAGS = new Set([
|
|
|
46
44
|
"[object BigInt64Array]",
|
|
47
45
|
"[object BigUint64Array]"
|
|
48
46
|
]);
|
|
47
|
+
/**
|
|
48
|
+
* 获取值的 [[Prototype]] 标签(通过 Object.prototype.toString)
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* resolvePrototypeString([]) // "[object Array]"
|
|
52
|
+
* resolvePrototypeString(null) // "[object Null]"
|
|
53
|
+
*
|
|
54
|
+
* @param value - 任意 JavaScript 值
|
|
55
|
+
* @returns 标准化的类型标签字符串
|
|
56
|
+
*/
|
|
49
57
|
function resolvePrototypeString(value) {
|
|
50
58
|
return Object.prototype.toString.call(value);
|
|
51
59
|
}
|
|
52
|
-
|
|
53
60
|
//#endregion
|
|
54
61
|
//#region src/utils/typeof/isAbortSignal.ts
|
|
55
62
|
/**
|
|
@@ -60,7 +67,6 @@ function resolvePrototypeString(value) {
|
|
|
60
67
|
function isAbortSignal(value) {
|
|
61
68
|
return resolvePrototypeString(value) === PROTOTYPE_TAGS.abortSignal;
|
|
62
69
|
}
|
|
63
|
-
|
|
64
70
|
//#endregion
|
|
65
71
|
//#region src/utils/typeof/isArray.ts
|
|
66
72
|
/**
|
|
@@ -89,7 +95,6 @@ function isArray(value) {
|
|
|
89
95
|
function isTypedArray(value) {
|
|
90
96
|
return typeof value === "object" && value !== null && TYPED_ARRAY_TAGS.has(resolvePrototypeString(value));
|
|
91
97
|
}
|
|
92
|
-
|
|
93
98
|
//#endregion
|
|
94
99
|
//#region src/utils/typeof/isBigInt.ts
|
|
95
100
|
/**
|
|
@@ -100,7 +105,6 @@ function isTypedArray(value) {
|
|
|
100
105
|
function isBigInt(value) {
|
|
101
106
|
return typeof value === "bigint";
|
|
102
107
|
}
|
|
103
|
-
|
|
104
108
|
//#endregion
|
|
105
109
|
//#region src/utils/typeof/isBlob.ts
|
|
106
110
|
/**
|
|
@@ -114,7 +118,6 @@ function isBlob(value) {
|
|
|
114
118
|
function isFile(value) {
|
|
115
119
|
return resolvePrototypeString(value) === PROTOTYPE_TAGS.file;
|
|
116
120
|
}
|
|
117
|
-
|
|
118
121
|
//#endregion
|
|
119
122
|
//#region src/utils/typeof/isBoolean.ts
|
|
120
123
|
/**
|
|
@@ -125,7 +128,6 @@ function isFile(value) {
|
|
|
125
128
|
function isBoolean(value) {
|
|
126
129
|
return typeof value === "boolean";
|
|
127
130
|
}
|
|
128
|
-
|
|
129
131
|
//#endregion
|
|
130
132
|
//#region src/utils/typeof/isFunction.ts
|
|
131
133
|
/**
|
|
@@ -160,7 +162,6 @@ function isGeneratorFunction(value) {
|
|
|
160
162
|
function isAsyncGeneratorFunction(value) {
|
|
161
163
|
return isFunction(value) && resolvePrototypeString(value) === PROTOTYPE_TAGS.asyncGeneratorFunction;
|
|
162
164
|
}
|
|
163
|
-
|
|
164
165
|
//#endregion
|
|
165
166
|
//#region src/utils/typeof/isClass.ts
|
|
166
167
|
function isConstructable(fn) {
|
|
@@ -186,7 +187,6 @@ function isConstructable(fn) {
|
|
|
186
187
|
function isClass(value) {
|
|
187
188
|
return isFunction(value) && !isAsyncFunction(value) && Function.prototype.toString.call(value).startsWith("class ") && isConstructable(value) && value.prototype !== void 0;
|
|
188
189
|
}
|
|
189
|
-
|
|
190
190
|
//#endregion
|
|
191
191
|
//#region src/utils/typeof/isDate.ts
|
|
192
192
|
/**
|
|
@@ -218,7 +218,6 @@ function isDate(value, invalidCheck = true) {
|
|
|
218
218
|
return false;
|
|
219
219
|
}
|
|
220
220
|
}
|
|
221
|
-
|
|
222
221
|
//#endregion
|
|
223
222
|
//#region src/utils/typeof/isEnumeration.ts
|
|
224
223
|
/**
|
|
@@ -267,7 +266,6 @@ function isEnumeration(enumeration) {
|
|
|
267
266
|
}
|
|
268
267
|
return [true, isBidirectional];
|
|
269
268
|
}
|
|
270
|
-
|
|
271
269
|
//#endregion
|
|
272
270
|
//#region src/utils/typeof/isEqual.ts
|
|
273
271
|
/**
|
|
@@ -303,7 +301,6 @@ function isEqual(x, y) {
|
|
|
303
301
|
}
|
|
304
302
|
return _isEqual(x, y);
|
|
305
303
|
}
|
|
306
|
-
|
|
307
304
|
//#endregion
|
|
308
305
|
//#region src/utils/typeof/isError.ts
|
|
309
306
|
/**
|
|
@@ -314,7 +311,6 @@ function isEqual(x, y) {
|
|
|
314
311
|
function isError(value) {
|
|
315
312
|
return value instanceof Error || resolvePrototypeString(value) === PROTOTYPE_TAGS.error;
|
|
316
313
|
}
|
|
317
|
-
|
|
318
314
|
//#endregion
|
|
319
315
|
//#region src/utils/typeof/isFalsy.ts
|
|
320
316
|
/**
|
|
@@ -330,7 +326,6 @@ function isFalsyLike(value) {
|
|
|
330
326
|
if (isFalsy(value)) return true;
|
|
331
327
|
return typeof value === "string" && (value === "null" || value === "undefined" || value === "NaN" || value === "false" || value === "0" || value === "-0" || value === "0n");
|
|
332
328
|
}
|
|
333
|
-
|
|
334
329
|
//#endregion
|
|
335
330
|
//#region src/utils/typeof/isIframe.ts
|
|
336
331
|
/**
|
|
@@ -351,7 +346,6 @@ function isInIframe() {
|
|
|
351
346
|
return false;
|
|
352
347
|
}
|
|
353
348
|
}
|
|
354
|
-
|
|
355
349
|
//#endregion
|
|
356
350
|
//#region src/utils/typeof/isIterable.ts
|
|
357
351
|
/**
|
|
@@ -362,7 +356,6 @@ function isInIframe() {
|
|
|
362
356
|
function isIterable(value) {
|
|
363
357
|
return !!value && typeof value[Symbol.iterator] === "function";
|
|
364
358
|
}
|
|
365
|
-
|
|
366
359
|
//#endregion
|
|
367
360
|
//#region src/utils/typeof/isMap.ts
|
|
368
361
|
/**
|
|
@@ -381,7 +374,6 @@ function isMap(value) {
|
|
|
381
374
|
function isWeakMap(value) {
|
|
382
375
|
return resolvePrototypeString(value) === PROTOTYPE_TAGS.weakMap;
|
|
383
376
|
}
|
|
384
|
-
|
|
385
377
|
//#endregion
|
|
386
378
|
//#region src/utils/typeof/isNull.ts
|
|
387
379
|
/**
|
|
@@ -392,7 +384,6 @@ function isWeakMap(value) {
|
|
|
392
384
|
function isNull(value) {
|
|
393
385
|
return value === null;
|
|
394
386
|
}
|
|
395
|
-
|
|
396
387
|
//#endregion
|
|
397
388
|
//#region src/utils/typeof/isNumber.ts
|
|
398
389
|
/**
|
|
@@ -475,7 +466,6 @@ function isInfinityLike(value) {
|
|
|
475
466
|
}
|
|
476
467
|
return false;
|
|
477
468
|
}
|
|
478
|
-
|
|
479
469
|
//#endregion
|
|
480
470
|
//#region src/utils/typeof/isObject.ts
|
|
481
471
|
/**
|
|
@@ -489,8 +479,8 @@ function isInfinityLike(value) {
|
|
|
489
479
|
* ```ts
|
|
490
480
|
* isObject({}); // true
|
|
491
481
|
* isObject([]); // false
|
|
492
|
-
* isObject(new Date()); // false
|
|
493
|
-
* isObject(new Date(), false); // true
|
|
482
|
+
* isObject(new Date()); // false
|
|
483
|
+
* isObject(new Date(), false); // true
|
|
494
484
|
* isObject(Object.create(null)) // false
|
|
495
485
|
* isObject(Object.create(null), false) // true
|
|
496
486
|
* ```
|
|
@@ -499,7 +489,6 @@ function isObject(value, prototypeCheck = true) {
|
|
|
499
489
|
const check = resolvePrototypeString(value) === PROTOTYPE_TAGS.object;
|
|
500
490
|
return prototypeCheck ? check && Object.getPrototypeOf(value) === Object.prototype : check;
|
|
501
491
|
}
|
|
502
|
-
|
|
503
492
|
//#endregion
|
|
504
493
|
//#region src/utils/typeof/isPromise.ts
|
|
505
494
|
/**
|
|
@@ -516,9 +505,8 @@ function isPromise(value) {
|
|
|
516
505
|
* @returns 是否为 PromiseLike
|
|
517
506
|
*/
|
|
518
507
|
function isPromiseLike(value) {
|
|
519
|
-
return isPromise(value) || isObject(value) && isFunction(value["then"]);
|
|
508
|
+
return isPromise(value) || isObject(value, false) && isFunction(value["then"]);
|
|
520
509
|
}
|
|
521
|
-
|
|
522
510
|
//#endregion
|
|
523
511
|
//#region src/utils/typeof/isReadableStream.ts
|
|
524
512
|
/**
|
|
@@ -535,26 +523,6 @@ function isReadableStream(value) {
|
|
|
535
523
|
if (resolvePrototypeString(value) === PROTOTYPE_TAGS.readableStream) return true;
|
|
536
524
|
return isObject(value) && isFunction(value["getReader"]) && isFunction(value["pipeThrough"]);
|
|
537
525
|
}
|
|
538
|
-
|
|
539
|
-
//#endregion
|
|
540
|
-
//#region src/utils/typeof/isString.ts
|
|
541
|
-
/**
|
|
542
|
-
* 检查 value 是否为 string 类型
|
|
543
|
-
*
|
|
544
|
-
* @param value 待检查值
|
|
545
|
-
* @param checkEmpty 是否检查空字符串
|
|
546
|
-
* @returns 是否为字符串
|
|
547
|
-
* @example
|
|
548
|
-
* ```ts
|
|
549
|
-
* isString("abc"); // true
|
|
550
|
-
* isString(""); // true
|
|
551
|
-
* isString("", true); // false
|
|
552
|
-
* ```
|
|
553
|
-
*/
|
|
554
|
-
function isString(value, checkEmpty = false) {
|
|
555
|
-
return typeof value === "string" && (!checkEmpty || !!value.length);
|
|
556
|
-
}
|
|
557
|
-
|
|
558
526
|
//#endregion
|
|
559
527
|
//#region src/utils/typeof/isRegExp.ts
|
|
560
528
|
/**
|
|
@@ -571,7 +539,6 @@ function isRegExp(value) {
|
|
|
571
539
|
return false;
|
|
572
540
|
}
|
|
573
541
|
}
|
|
574
|
-
|
|
575
542
|
//#endregion
|
|
576
543
|
//#region src/utils/typeof/isSet.ts
|
|
577
544
|
/**
|
|
@@ -590,7 +557,24 @@ function isSet(value) {
|
|
|
590
557
|
function isWeakSet(value) {
|
|
591
558
|
return resolvePrototypeString(value) === PROTOTYPE_TAGS.weakSet;
|
|
592
559
|
}
|
|
593
|
-
|
|
560
|
+
//#endregion
|
|
561
|
+
//#region src/utils/typeof/isString.ts
|
|
562
|
+
/**
|
|
563
|
+
* 检查 value 是否为 string 类型
|
|
564
|
+
*
|
|
565
|
+
* @param value 待检查值
|
|
566
|
+
* @param checkEmpty 是否检查空字符串
|
|
567
|
+
* @returns 是否为字符串
|
|
568
|
+
* @example
|
|
569
|
+
* ```ts
|
|
570
|
+
* isString("abc"); // true
|
|
571
|
+
* isString(""); // true
|
|
572
|
+
* isString("", true); // false
|
|
573
|
+
* ```
|
|
574
|
+
*/
|
|
575
|
+
function isString(value, checkEmpty = false) {
|
|
576
|
+
return typeof value === "string" && (!checkEmpty || !!value.length);
|
|
577
|
+
}
|
|
594
578
|
//#endregion
|
|
595
579
|
//#region src/utils/typeof/isSymbol.ts
|
|
596
580
|
/**
|
|
@@ -601,7 +585,6 @@ function isWeakSet(value) {
|
|
|
601
585
|
function isSymbol(value) {
|
|
602
586
|
return typeof value === "symbol";
|
|
603
587
|
}
|
|
604
|
-
|
|
605
588
|
//#endregion
|
|
606
589
|
//#region src/utils/typeof/isUndefined.ts
|
|
607
590
|
/**
|
|
@@ -612,7 +595,6 @@ function isSymbol(value) {
|
|
|
612
595
|
function isUndefined(value) {
|
|
613
596
|
return typeof value === "undefined";
|
|
614
597
|
}
|
|
615
|
-
|
|
616
598
|
//#endregion
|
|
617
599
|
//#region src/utils/typeof/isURLSearchParams.ts
|
|
618
600
|
/**
|
|
@@ -623,7 +605,6 @@ function isUndefined(value) {
|
|
|
623
605
|
function isURLSearchParams(value) {
|
|
624
606
|
return resolvePrototypeString(value) === PROTOTYPE_TAGS.URLSearchParams;
|
|
625
607
|
}
|
|
626
|
-
|
|
627
608
|
//#endregion
|
|
628
609
|
//#region src/utils/typeof/isWebSocket.ts
|
|
629
610
|
/**
|
|
@@ -634,7 +615,6 @@ function isURLSearchParams(value) {
|
|
|
634
615
|
function isWebSocket(value) {
|
|
635
616
|
return resolvePrototypeString(value) === PROTOTYPE_TAGS.webSocket;
|
|
636
617
|
}
|
|
637
|
-
|
|
638
618
|
//#endregion
|
|
639
619
|
//#region src/utils/typeof/isWindow.ts
|
|
640
620
|
/**
|
|
@@ -645,14 +625,12 @@ function isWebSocket(value) {
|
|
|
645
625
|
function isWindow(value) {
|
|
646
626
|
return resolvePrototypeString(value) === PROTOTYPE_TAGS.window;
|
|
647
627
|
}
|
|
648
|
-
|
|
649
628
|
//#endregion
|
|
650
629
|
//#region src/utils/array/arrayCast.ts
|
|
651
630
|
function arrayCast(candidate, checkEmpty = true) {
|
|
652
631
|
if (checkEmpty && (isUndefined(candidate) || isNull(candidate))) return [];
|
|
653
632
|
return isArray(candidate) ? [...candidate] : [candidate];
|
|
654
633
|
}
|
|
655
|
-
|
|
656
634
|
//#endregion
|
|
657
635
|
//#region src/utils/array/arrayCompete.ts
|
|
658
636
|
/**
|
|
@@ -673,7 +651,6 @@ function arrayCompete(initialList, match) {
|
|
|
673
651
|
if (!isArray(initialList) || initialList.length === 0 || !isFunction(match)) return null;
|
|
674
652
|
return initialList.reduce(match);
|
|
675
653
|
}
|
|
676
|
-
|
|
677
654
|
//#endregion
|
|
678
655
|
//#region src/utils/array/arrayCounting.ts
|
|
679
656
|
/**
|
|
@@ -700,7 +677,6 @@ function arrayCounting(initialList, match) {
|
|
|
700
677
|
return prev;
|
|
701
678
|
}, {});
|
|
702
679
|
}
|
|
703
|
-
|
|
704
680
|
//#endregion
|
|
705
681
|
//#region src/utils/array/arrayDifference.ts
|
|
706
682
|
/**
|
|
@@ -731,14 +707,12 @@ function arrayDifference(initialList, diffList, match) {
|
|
|
731
707
|
});
|
|
732
708
|
return initialList.filter((item, index) => !map.get(match(item, index)));
|
|
733
709
|
}
|
|
734
|
-
|
|
735
710
|
//#endregion
|
|
736
711
|
//#region src/utils/array/arrayFirst.ts
|
|
737
712
|
function arrayFirst(initialList, saveValue) {
|
|
738
713
|
if (!isArray(initialList) || initialList.length === 0) return saveValue;
|
|
739
714
|
return initialList[0];
|
|
740
715
|
}
|
|
741
|
-
|
|
742
716
|
//#endregion
|
|
743
717
|
//#region src/utils/array/arrayFork.ts
|
|
744
718
|
/**
|
|
@@ -760,7 +734,6 @@ function arrayFork(initialList, match) {
|
|
|
760
734
|
});
|
|
761
735
|
return forked;
|
|
762
736
|
}
|
|
763
|
-
|
|
764
737
|
//#endregion
|
|
765
738
|
//#region src/utils/array/arrayIntersection.ts
|
|
766
739
|
function arrayIntersection(initialList, diffList, match) {
|
|
@@ -773,14 +746,12 @@ function arrayIntersection(initialList, diffList, match) {
|
|
|
773
746
|
const diffKeys = new Set(diffList.map((item, index) => match(item, index)));
|
|
774
747
|
return initialList.filter((item, index) => diffKeys.has(match(item, index)));
|
|
775
748
|
}
|
|
776
|
-
|
|
777
749
|
//#endregion
|
|
778
750
|
//#region src/utils/array/arrayLast.ts
|
|
779
751
|
function arrayLast(initialList, saveValue) {
|
|
780
752
|
if (!isArray(initialList) || initialList.length === 0) return saveValue;
|
|
781
753
|
return initialList[initialList.length - 1];
|
|
782
754
|
}
|
|
783
|
-
|
|
784
755
|
//#endregion
|
|
785
756
|
//#region src/utils/array/arrayMerge.ts
|
|
786
757
|
function arrayMerge(initialList, mergeList, match) {
|
|
@@ -796,7 +767,6 @@ function arrayMerge(initialList, mergeList, match) {
|
|
|
796
767
|
return keys.has(key) ? keys.get(key) : prevItem;
|
|
797
768
|
});
|
|
798
769
|
}
|
|
799
|
-
|
|
800
770
|
//#endregion
|
|
801
771
|
//#region src/utils/array/arrayPick.ts
|
|
802
772
|
function arrayPick(initialList, filter, mapper) {
|
|
@@ -810,7 +780,6 @@ function arrayPick(initialList, filter, mapper) {
|
|
|
810
780
|
return prev;
|
|
811
781
|
}, []);
|
|
812
782
|
}
|
|
813
|
-
|
|
814
783
|
//#endregion
|
|
815
784
|
//#region src/utils/array/arrayReplace.ts
|
|
816
785
|
function arrayReplace(initialList, newItem, match) {
|
|
@@ -826,7 +795,6 @@ function arrayReplace(initialList, newItem, match) {
|
|
|
826
795
|
}
|
|
827
796
|
return [...initialList];
|
|
828
797
|
}
|
|
829
|
-
|
|
830
798
|
//#endregion
|
|
831
799
|
//#region src/utils/array/arrayReplaceMove.ts
|
|
832
800
|
/**
|
|
@@ -860,7 +828,6 @@ function arrayReplaceMove(initialList, newItem, match, position) {
|
|
|
860
828
|
else result.push(newItem);
|
|
861
829
|
return result;
|
|
862
830
|
}
|
|
863
|
-
|
|
864
831
|
//#endregion
|
|
865
832
|
//#region src/utils/array/arraySplit.ts
|
|
866
833
|
/**
|
|
@@ -883,7 +850,6 @@ function arraySplit(initialList, size = 10) {
|
|
|
883
850
|
return initialList.slice(i * size, i * size + size);
|
|
884
851
|
});
|
|
885
852
|
}
|
|
886
|
-
|
|
887
853
|
//#endregion
|
|
888
854
|
//#region src/utils/array/arrayZip.ts
|
|
889
855
|
/**
|
|
@@ -908,7 +874,6 @@ function arrayUnzip(arrays) {
|
|
|
908
874
|
function arrayZip(...arrays) {
|
|
909
875
|
return arrayUnzip(arrays);
|
|
910
876
|
}
|
|
911
|
-
|
|
912
877
|
//#endregion
|
|
913
878
|
//#region src/utils/array/arrayZipToObject.ts
|
|
914
879
|
function arrayZipToObject(keys, values) {
|
|
@@ -920,7 +885,6 @@ function arrayZipToObject(keys, values) {
|
|
|
920
885
|
return acc;
|
|
921
886
|
}, result);
|
|
922
887
|
}
|
|
923
|
-
|
|
924
888
|
//#endregion
|
|
925
889
|
//#region src/utils/device/isBrowser.ts
|
|
926
890
|
function isBrowser() {
|
|
@@ -929,7 +893,37 @@ function isBrowser() {
|
|
|
929
893
|
function isWebWorker() {
|
|
930
894
|
return typeof window === "undefined" && typeof self !== "undefined" && "importScripts" in self;
|
|
931
895
|
}
|
|
932
|
-
|
|
896
|
+
//#endregion
|
|
897
|
+
//#region src/utils/device/isTablet.ts
|
|
898
|
+
/**
|
|
899
|
+
* 检测当前设备是否为平板
|
|
900
|
+
*
|
|
901
|
+
* @param minWidth - 平板最小宽度(默认 768px)
|
|
902
|
+
* @param maxWidth - 平板最大宽度(默认 1200px)
|
|
903
|
+
* @param dpi - 标准 DPI 基准(默认 160)
|
|
904
|
+
* @returns 是否为平板设备
|
|
905
|
+
* @example
|
|
906
|
+
* ```ts
|
|
907
|
+
* // 假设 window.innerWidth = 1000
|
|
908
|
+
* isTablet(); // true
|
|
909
|
+
* ```
|
|
910
|
+
*/
|
|
911
|
+
function isTablet(minWidth = 768, maxWidth = 1200, dpi = 160) {
|
|
912
|
+
if (typeof window === "undefined" || !isPositiveInteger(minWidth) || !isPositiveInteger(maxWidth)) return false;
|
|
913
|
+
const width = window.innerWidth;
|
|
914
|
+
const isWithinWidthRange = width >= minWidth && width <= maxWidth;
|
|
915
|
+
try {
|
|
916
|
+
const widthPx = window.screen.width;
|
|
917
|
+
const heightPx = window.screen.height;
|
|
918
|
+
const DPI = dpi * (window.devicePixelRatio || 1);
|
|
919
|
+
const widthInch = widthPx / DPI;
|
|
920
|
+
const heightInch = heightPx / DPI;
|
|
921
|
+
const screenInches = Math.sqrt(widthInch ** 2 + heightInch ** 2);
|
|
922
|
+
return isWithinWidthRange || screenInches >= 7;
|
|
923
|
+
} catch {
|
|
924
|
+
return isWithinWidthRange;
|
|
925
|
+
}
|
|
926
|
+
}
|
|
933
927
|
//#endregion
|
|
934
928
|
//#region src/utils/device/isMobile.ts
|
|
935
929
|
/**
|
|
@@ -964,39 +958,6 @@ function isIOSMobile(maxWidth = 768, dpi = 160) {
|
|
|
964
958
|
if (typeof navigator === "undefined" || !navigator.userAgent || !isPositiveInteger(maxWidth)) return false;
|
|
965
959
|
return /iPhone|iPad|iPod/i.test(navigator.userAgent) && !isTablet(maxWidth, 1200, dpi);
|
|
966
960
|
}
|
|
967
|
-
|
|
968
|
-
//#endregion
|
|
969
|
-
//#region src/utils/device/isTablet.ts
|
|
970
|
-
/**
|
|
971
|
-
* 检测当前设备是否为平板
|
|
972
|
-
*
|
|
973
|
-
* @param minWidth - 平板最小宽度(默认 768px)
|
|
974
|
-
* @param maxWidth - 平板最大宽度(默认 1200px)
|
|
975
|
-
* @param dpi - 标准 DPI 基准(默认 160)
|
|
976
|
-
* @returns 是否为平板设备
|
|
977
|
-
* @example
|
|
978
|
-
* ```ts
|
|
979
|
-
* // 假设 window.innerWidth = 1000
|
|
980
|
-
* isTablet(); // true
|
|
981
|
-
* ```
|
|
982
|
-
*/
|
|
983
|
-
function isTablet(minWidth = 768, maxWidth = 1200, dpi = 160) {
|
|
984
|
-
if (typeof window === "undefined" || !isPositiveInteger(minWidth) || !isPositiveInteger(maxWidth)) return false;
|
|
985
|
-
const width = window.innerWidth;
|
|
986
|
-
const isWithinWidthRange = width >= minWidth && width <= maxWidth;
|
|
987
|
-
try {
|
|
988
|
-
const widthPx = window.screen.width;
|
|
989
|
-
const heightPx = window.screen.height;
|
|
990
|
-
const DPI = dpi * (window.devicePixelRatio || 1);
|
|
991
|
-
const widthInch = widthPx / DPI;
|
|
992
|
-
const heightInch = heightPx / DPI;
|
|
993
|
-
const screenInches = Math.sqrt(widthInch ** 2 + heightInch ** 2);
|
|
994
|
-
return isWithinWidthRange || screenInches >= 7;
|
|
995
|
-
} catch {
|
|
996
|
-
return isWithinWidthRange;
|
|
997
|
-
}
|
|
998
|
-
}
|
|
999
|
-
|
|
1000
961
|
//#endregion
|
|
1001
962
|
//#region src/utils/function/to.ts
|
|
1002
963
|
/**
|
|
@@ -1034,10 +995,116 @@ function to(promise, errorExt) {
|
|
|
1034
995
|
return [err ? err : /* @__PURE__ */ new Error("defaultError"), void 0];
|
|
1035
996
|
});
|
|
1036
997
|
}
|
|
1037
|
-
|
|
998
|
+
//#endregion
|
|
999
|
+
//#region src/utils/string/stringInitialCase.ts
|
|
1000
|
+
const R1$2 = /\S+/g;
|
|
1001
|
+
const R2 = /[^a-zA-Z\u00C0-\u017F]/;
|
|
1002
|
+
/**
|
|
1003
|
+
* 字符串首字母大小写
|
|
1004
|
+
* - 包含非西欧字母字符时,不处理
|
|
1005
|
+
* - 纯字母且全大写时,不处理
|
|
1006
|
+
* - 纯字母且非全大写时,首字母小写,其余保留
|
|
1007
|
+
* - 纯字母且非全大写时,首字母大写,其余保留
|
|
1008
|
+
*
|
|
1009
|
+
* @param input 待处理字符串
|
|
1010
|
+
* @param caseType 大小写类型
|
|
1011
|
+
* @returns 处理后的字符串
|
|
1012
|
+
* @example
|
|
1013
|
+
* ```ts
|
|
1014
|
+
* stringInitialCase("Hello", "lower"); // "hello"
|
|
1015
|
+
* stringInitialCase("hello", "upper"); // "Hello"
|
|
1016
|
+
* ```
|
|
1017
|
+
*/
|
|
1018
|
+
function stringInitialCase(input, caseType) {
|
|
1019
|
+
if (!isString(input, true)) return "";
|
|
1020
|
+
return input.replace(R1$2, (word) => {
|
|
1021
|
+
if (R2.test(word)) return word;
|
|
1022
|
+
if (word === word.toLocaleUpperCase()) return word;
|
|
1023
|
+
if (caseType === "lower" && word[0]) return word[0].toLocaleLowerCase() + word.slice(1);
|
|
1024
|
+
if (caseType === "upper" && word[0]) return word[0].toLocaleUpperCase() + word.slice(1);
|
|
1025
|
+
return word;
|
|
1026
|
+
});
|
|
1027
|
+
}
|
|
1028
|
+
//#endregion
|
|
1029
|
+
//#region src/utils/string/stringReplace.ts
|
|
1030
|
+
/**
|
|
1031
|
+
* 字符串替换
|
|
1032
|
+
* - 替换第一个匹配项
|
|
1033
|
+
*
|
|
1034
|
+
* @param input 待处理字符串
|
|
1035
|
+
* @param search 匹配项
|
|
1036
|
+
* @param replacement 替换项
|
|
1037
|
+
* @returns 替换后的字符串
|
|
1038
|
+
* @example
|
|
1039
|
+
* ```ts
|
|
1040
|
+
* stringReplace("hello world", "world", "context"); // "hello context"
|
|
1041
|
+
* ```
|
|
1042
|
+
*/
|
|
1043
|
+
function stringReplace(input, search, replacement) {
|
|
1044
|
+
if (!isString(input, true)) return "";
|
|
1045
|
+
return input.replace(search, replacement);
|
|
1046
|
+
}
|
|
1047
|
+
//#endregion
|
|
1048
|
+
//#region src/utils/string/stringTemplate.ts
|
|
1049
|
+
const R1$1 = /\{\{(.+?)\}\}/g;
|
|
1050
|
+
/**
|
|
1051
|
+
* 字符串模板替换
|
|
1052
|
+
* - 使用对象的属性值替换字符串中的 {{key}} 模板
|
|
1053
|
+
*
|
|
1054
|
+
* @param input 待处理字符串
|
|
1055
|
+
* @param template 模板对象
|
|
1056
|
+
* @param regex 模板匹配正则 (默认: `\{\{(.+?)\}\}`)
|
|
1057
|
+
* @returns 替换后的字符串
|
|
1058
|
+
* @example
|
|
1059
|
+
* ```ts
|
|
1060
|
+
* stringTemplate("Hello {{name}}", { name: "World" }); // "Hello World"
|
|
1061
|
+
* ```
|
|
1062
|
+
*/
|
|
1063
|
+
function stringTemplate(input, template, regex = R1$1) {
|
|
1064
|
+
if (!isString(input, true)) return "";
|
|
1065
|
+
regex.lastIndex = 0;
|
|
1066
|
+
let result = "";
|
|
1067
|
+
let from = 0;
|
|
1068
|
+
let match;
|
|
1069
|
+
while (match = regex.exec(input)) {
|
|
1070
|
+
const replacement = template[match[1]];
|
|
1071
|
+
const valueToInsert = replacement === null || replacement === void 0 ? match[0] : replacement;
|
|
1072
|
+
result += input.slice(from, match.index) + valueToInsert;
|
|
1073
|
+
from = regex.lastIndex;
|
|
1074
|
+
}
|
|
1075
|
+
return result + input.slice(from);
|
|
1076
|
+
}
|
|
1077
|
+
//#endregion
|
|
1078
|
+
//#region src/utils/string/stringToJson.ts
|
|
1079
|
+
/**
|
|
1080
|
+
* 处理 JSON 字符串
|
|
1081
|
+
*
|
|
1082
|
+
* @param input 待处理字符串
|
|
1083
|
+
* @param safeValue 安全值 (当解析失败或输入无效时返回)
|
|
1084
|
+
* @returns 解析后的对象 或 安全值
|
|
1085
|
+
* @example
|
|
1086
|
+
* ```ts
|
|
1087
|
+
* stringToJson('{"a": 1}', {}); // { a: 1 }
|
|
1088
|
+
* stringToJson('invalid', {}); // {}
|
|
1089
|
+
* ```
|
|
1090
|
+
*/
|
|
1091
|
+
function stringToJson(input, safeValue) {
|
|
1092
|
+
if (!isString(input, true)) return safeValue;
|
|
1093
|
+
try {
|
|
1094
|
+
return JSON.parse(input);
|
|
1095
|
+
} catch (error) {
|
|
1096
|
+
return safeValue;
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
//#endregion
|
|
1100
|
+
//#region src/utils/string/stringToLowerCase.ts
|
|
1101
|
+
function stringToLowerCase(input) {
|
|
1102
|
+
if (!isString(input, true)) return "";
|
|
1103
|
+
return input.toLowerCase();
|
|
1104
|
+
}
|
|
1038
1105
|
//#endregion
|
|
1039
1106
|
//#region src/utils/string/stringToNumber.ts
|
|
1040
|
-
const R1
|
|
1107
|
+
const R1 = /[^0-9.-]/g;
|
|
1041
1108
|
/**
|
|
1042
1109
|
* 从字符串中提取数字字符串
|
|
1043
1110
|
* - 移除非数字字符,保留符号和小数点
|
|
@@ -1052,7 +1119,7 @@ const R1$2 = /[^0-9.-]/g;
|
|
|
1052
1119
|
*/
|
|
1053
1120
|
function stringToNumber(input) {
|
|
1054
1121
|
if (!isString(input, true)) return "0";
|
|
1055
|
-
const cleaned = input.replace(R1
|
|
1122
|
+
const cleaned = input.replace(R1, "");
|
|
1056
1123
|
if (!cleaned) return "0";
|
|
1057
1124
|
let isDecimal = false;
|
|
1058
1125
|
let signCount = 0;
|
|
@@ -1077,7 +1144,106 @@ function stringToNumber(input) {
|
|
|
1077
1144
|
if (result.endsWith(".")) result = result.slice(0, -1);
|
|
1078
1145
|
return sign + result;
|
|
1079
1146
|
}
|
|
1080
|
-
|
|
1147
|
+
//#endregion
|
|
1148
|
+
//#region src/utils/string/stringToPosix.ts
|
|
1149
|
+
/**
|
|
1150
|
+
* 将路径转换为 POSIX 风格
|
|
1151
|
+
* - 统一使用正斜杠 (/)
|
|
1152
|
+
* - 可选移除 Windows 盘符 (如 C:)
|
|
1153
|
+
* - 可选移除开头的斜杠
|
|
1154
|
+
* - 规范化连续斜杠为单个斜杠
|
|
1155
|
+
*
|
|
1156
|
+
* @param input 待处理字符串
|
|
1157
|
+
* @param removeLeadingSlash 是否移除开头斜杠,默认为 `false`。如果移除了盘符,路径通常会以 / 开头,此参数可控制是否保留该 /
|
|
1158
|
+
* @returns 转换后的路径,如果输入无效则返回空字符串
|
|
1159
|
+
*
|
|
1160
|
+
* @example
|
|
1161
|
+
* ```ts
|
|
1162
|
+
* stringToPosix("C:\\Windows\\System32");
|
|
1163
|
+
* // 默认: "/Windows/System32" (移除了 C: 并标准化)
|
|
1164
|
+
*
|
|
1165
|
+
* stringToPosix("C:\\Windows\\System32", true);
|
|
1166
|
+
* // 移除开头斜杠: "Windows/System32"
|
|
1167
|
+
*
|
|
1168
|
+
* stringToPosix("\\\\server\\share\\file.txt");
|
|
1169
|
+
* // UNC 路径: "/server/share/file.txt"
|
|
1170
|
+
*
|
|
1171
|
+
* stringToPosix("folder\\subfolder\\file.txt");
|
|
1172
|
+
* // 相对路径: "folder/subfolder/file.txt"
|
|
1173
|
+
* ```
|
|
1174
|
+
*/
|
|
1175
|
+
function stringToPosix(input, removeLeadingSlash = false) {
|
|
1176
|
+
if (!isString(input, true)) return "";
|
|
1177
|
+
let normalized = input.replace(/^[A-Za-z]:([\\/])?/, (_, separator) => {
|
|
1178
|
+
return separator ? "/" : "";
|
|
1179
|
+
});
|
|
1180
|
+
normalized = normalized.replace(/\\/g, "/");
|
|
1181
|
+
normalized = normalized.replace(/\/+/g, "/");
|
|
1182
|
+
if (removeLeadingSlash && normalized.startsWith("/")) normalized = normalized.substring(1);
|
|
1183
|
+
return normalized;
|
|
1184
|
+
}
|
|
1185
|
+
//#endregion
|
|
1186
|
+
//#region src/utils/string/stringToUpperCase.ts
|
|
1187
|
+
function stringToUpperCase(input) {
|
|
1188
|
+
if (!isString(input, true)) return "";
|
|
1189
|
+
return input.toUpperCase();
|
|
1190
|
+
}
|
|
1191
|
+
//#endregion
|
|
1192
|
+
//#region src/utils/string/stringToValues.ts
|
|
1193
|
+
function stringToValues(input, valueType = "number", splitSymbol = ",") {
|
|
1194
|
+
if (!isString(input, true)) return [];
|
|
1195
|
+
try {
|
|
1196
|
+
const values = input.split(splitSymbol);
|
|
1197
|
+
if (valueType === "number") return values.map((d) => Number(d));
|
|
1198
|
+
return values;
|
|
1199
|
+
} catch (error) {
|
|
1200
|
+
return [];
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
//#endregion
|
|
1204
|
+
//#region src/utils/string/stringTrim.ts
|
|
1205
|
+
/**
|
|
1206
|
+
* 从字符串中裁切掉所有的前缀和后缀字符
|
|
1207
|
+
*
|
|
1208
|
+
* @param input 待处理字符串
|
|
1209
|
+
* @param charsToTrim 裁切字符,默认为 `" "`
|
|
1210
|
+
* @returns 裁切后的字符串
|
|
1211
|
+
* @example
|
|
1212
|
+
* ```ts
|
|
1213
|
+
* stringTrim(" hello "); // "hello"
|
|
1214
|
+
* stringTrim("__hello__", "_"); // "hello"
|
|
1215
|
+
* ```
|
|
1216
|
+
*/
|
|
1217
|
+
function stringTrim(input, charsToTrim = " ") {
|
|
1218
|
+
if (!isString(input, true)) return "";
|
|
1219
|
+
const toTrim = charsToTrim.replace(/[\W]{1}/g, "\\$&");
|
|
1220
|
+
const regex = new RegExp(`^[${toTrim}]+|[${toTrim}]+$`, "g");
|
|
1221
|
+
return input.replace(regex, "");
|
|
1222
|
+
}
|
|
1223
|
+
//#endregion
|
|
1224
|
+
//#region src/utils/string/stringTruncate.ts
|
|
1225
|
+
/**
|
|
1226
|
+
* 截取字符串
|
|
1227
|
+
* - 支持自定义省略符,不会截断在汉字中间(因为JS字符串本身按字符处理)
|
|
1228
|
+
*
|
|
1229
|
+
* @param input 待处理字符串
|
|
1230
|
+
* @param maxLength 最大长度 (包含省略符)
|
|
1231
|
+
* @param ellipsis 省略符,默认为 `...`
|
|
1232
|
+
* @returns 截取后的字符串
|
|
1233
|
+
* @example
|
|
1234
|
+
* ```ts
|
|
1235
|
+
* stringTruncate("hello world", 8); // "hello..."
|
|
1236
|
+
* ```
|
|
1237
|
+
*/
|
|
1238
|
+
function stringTruncate(input, maxLength, ellipsis = "...") {
|
|
1239
|
+
if (!isString(input, true)) return "";
|
|
1240
|
+
const codePoints = Array.from(input);
|
|
1241
|
+
if (!isInteger(maxLength) || maxLength < 0) return input;
|
|
1242
|
+
if (codePoints.length <= maxLength) return input;
|
|
1243
|
+
const availableLength = maxLength - ellipsis.length;
|
|
1244
|
+
if (availableLength <= 0) return "";
|
|
1245
|
+
return codePoints.slice(0, availableLength).join("") + ellipsis;
|
|
1246
|
+
}
|
|
1081
1247
|
//#endregion
|
|
1082
1248
|
//#region src/utils/math/mathToBignumber.ts
|
|
1083
1249
|
/**
|
|
@@ -1103,7 +1269,6 @@ function mathToBignumber(mathJsInstance, value, saveValue) {
|
|
|
1103
1269
|
return errorValue;
|
|
1104
1270
|
}
|
|
1105
1271
|
}
|
|
1106
|
-
|
|
1107
1272
|
//#endregion
|
|
1108
1273
|
//#region src/utils/math/mathToDecimal.ts
|
|
1109
1274
|
function mathToDecimal(mathJsInstance, value, precision, isFormat = true) {
|
|
@@ -1113,7 +1278,6 @@ function mathToDecimal(mathJsInstance, value, precision, isFormat = true) {
|
|
|
1113
1278
|
precision
|
|
1114
1279
|
}) : bigNumber;
|
|
1115
1280
|
}
|
|
1116
|
-
|
|
1117
1281
|
//#endregion
|
|
1118
1282
|
//#region src/utils/math/mathToEvaluate.ts
|
|
1119
1283
|
/**
|
|
@@ -1132,7 +1296,6 @@ function mathToEvaluate(mathJsInstance, expr, scope) {
|
|
|
1132
1296
|
const evaluateValue = `${mathJsInstance.evaluate(expr, scope || {})}`;
|
|
1133
1297
|
return mathJsInstance.format(mathToBignumber(mathJsInstance, evaluateValue), { notation: "fixed" });
|
|
1134
1298
|
}
|
|
1135
|
-
|
|
1136
1299
|
//#endregion
|
|
1137
1300
|
//#region src/utils/number/numberWithin.ts
|
|
1138
1301
|
/**
|
|
@@ -1159,7 +1322,6 @@ function numberWithin(input, interval, includeLeft = true, includeRight = false)
|
|
|
1159
1322
|
else if (includeRight) return input > left && input <= right;
|
|
1160
1323
|
else return input > left && input < right;
|
|
1161
1324
|
}
|
|
1162
|
-
|
|
1163
1325
|
//#endregion
|
|
1164
1326
|
//#region src/utils/object/enumEntries.ts
|
|
1165
1327
|
function enumEntries(enumeration) {
|
|
@@ -1169,7 +1331,6 @@ function enumEntries(enumeration) {
|
|
|
1169
1331
|
if (isBidirectionalEnum) return entries.splice(entries.length / 2, entries.length / 2);
|
|
1170
1332
|
return entries;
|
|
1171
1333
|
}
|
|
1172
|
-
|
|
1173
1334
|
//#endregion
|
|
1174
1335
|
//#region src/utils/object/enumKeys.ts
|
|
1175
1336
|
function enumKeys(enumeration) {
|
|
@@ -1179,7 +1340,6 @@ function enumKeys(enumeration) {
|
|
|
1179
1340
|
if (isBidirectionalEnum) return keys.splice(keys.length / 2, keys.length / 2);
|
|
1180
1341
|
return keys;
|
|
1181
1342
|
}
|
|
1182
|
-
|
|
1183
1343
|
//#endregion
|
|
1184
1344
|
//#region src/utils/object/enumValues.ts
|
|
1185
1345
|
function enumValues(enumeration) {
|
|
@@ -1189,13 +1349,11 @@ function enumValues(enumeration) {
|
|
|
1189
1349
|
if (isBidirectionalEnum) return values.splice(values.length / 2, values.length / 2);
|
|
1190
1350
|
return values;
|
|
1191
1351
|
}
|
|
1192
|
-
|
|
1193
1352
|
//#endregion
|
|
1194
1353
|
//#region src/utils/object/objectEntries.ts
|
|
1195
1354
|
function objectEntries(value) {
|
|
1196
1355
|
return Object.entries(value);
|
|
1197
1356
|
}
|
|
1198
|
-
|
|
1199
1357
|
//#endregion
|
|
1200
1358
|
//#region src/utils/object/objectMapEntries.ts
|
|
1201
1359
|
/**
|
|
@@ -1220,7 +1378,6 @@ function objectMapEntries(plainObject, toEntry) {
|
|
|
1220
1378
|
return acc;
|
|
1221
1379
|
}, defaultResult);
|
|
1222
1380
|
}
|
|
1223
|
-
|
|
1224
1381
|
//#endregion
|
|
1225
1382
|
//#region src/utils/object/objectAssign.ts
|
|
1226
1383
|
const OBJECT_PROTO = Object.prototype;
|
|
@@ -1247,7 +1404,6 @@ function _objectAssign(initial, override, _seen) {
|
|
|
1247
1404
|
function objectAssign(initial, override) {
|
|
1248
1405
|
return _objectAssign(initial, override, /* @__PURE__ */ new WeakSet());
|
|
1249
1406
|
}
|
|
1250
|
-
|
|
1251
1407
|
//#endregion
|
|
1252
1408
|
//#region src/utils/object/objectCrush.ts
|
|
1253
1409
|
function objectCrush(obj) {
|
|
@@ -1259,7 +1415,6 @@ function objectCrush(obj) {
|
|
|
1259
1415
|
}
|
|
1260
1416
|
return crushReducer({}, obj, "");
|
|
1261
1417
|
}
|
|
1262
|
-
|
|
1263
1418
|
//#endregion
|
|
1264
1419
|
//#region src/utils/object/objectInvert.ts
|
|
1265
1420
|
function objectInvert(obj) {
|
|
@@ -1268,13 +1423,11 @@ function objectInvert(obj) {
|
|
|
1268
1423
|
for (const [k, v] of objectEntries(obj)) if (isString(v) || isNumber(v) || isSymbol(v)) result[v] = k;
|
|
1269
1424
|
return result;
|
|
1270
1425
|
}
|
|
1271
|
-
|
|
1272
1426
|
//#endregion
|
|
1273
1427
|
//#region src/utils/object/objectKeys.ts
|
|
1274
1428
|
function objectKeys(value) {
|
|
1275
1429
|
return Object.keys(value);
|
|
1276
1430
|
}
|
|
1277
|
-
|
|
1278
1431
|
//#endregion
|
|
1279
1432
|
//#region src/utils/object/objectOmit.ts
|
|
1280
1433
|
function objectOmit(obj, keys) {
|
|
@@ -1287,7 +1440,6 @@ function objectOmit(obj, keys) {
|
|
|
1287
1440
|
return acc;
|
|
1288
1441
|
}, result);
|
|
1289
1442
|
}
|
|
1290
|
-
|
|
1291
1443
|
//#endregion
|
|
1292
1444
|
//#region src/utils/object/objectPick.ts
|
|
1293
1445
|
function objectPick(obj, keys) {
|
|
@@ -1299,230 +1451,11 @@ function objectPick(obj, keys) {
|
|
|
1299
1451
|
return acc;
|
|
1300
1452
|
}, result);
|
|
1301
1453
|
}
|
|
1302
|
-
|
|
1303
1454
|
//#endregion
|
|
1304
1455
|
//#region src/utils/object/objectValues.ts
|
|
1305
1456
|
function objectValues(value) {
|
|
1306
1457
|
return Object.values(value);
|
|
1307
1458
|
}
|
|
1308
|
-
|
|
1309
|
-
//#endregion
|
|
1310
|
-
//#region src/utils/string/stringInitialCase.ts
|
|
1311
|
-
const R1$1 = /\S+/g;
|
|
1312
|
-
const R2 = /[^a-zA-Z\u00C0-\u017F]/;
|
|
1313
|
-
/**
|
|
1314
|
-
* 字符串首字母大小写
|
|
1315
|
-
* - 包含非西欧字母字符时,不处理
|
|
1316
|
-
* - 纯字母且全大写时,不处理
|
|
1317
|
-
* - 纯字母且非全大写时,首字母小写,其余保留
|
|
1318
|
-
* - 纯字母且非全大写时,首字母大写,其余保留
|
|
1319
|
-
*
|
|
1320
|
-
* @param input 待处理字符串
|
|
1321
|
-
* @param caseType 大小写类型
|
|
1322
|
-
* @returns 处理后的字符串
|
|
1323
|
-
* @example
|
|
1324
|
-
* ```ts
|
|
1325
|
-
* stringInitialCase("Hello", "lower"); // "hello"
|
|
1326
|
-
* stringInitialCase("hello", "upper"); // "Hello"
|
|
1327
|
-
* ```
|
|
1328
|
-
*/
|
|
1329
|
-
function stringInitialCase(input, caseType) {
|
|
1330
|
-
if (!isString(input, true)) return "";
|
|
1331
|
-
return input.replace(R1$1, (word) => {
|
|
1332
|
-
if (R2.test(word)) return word;
|
|
1333
|
-
if (word === word.toLocaleUpperCase()) return word;
|
|
1334
|
-
if (caseType === "lower" && word[0]) return word[0].toLocaleLowerCase() + word.slice(1);
|
|
1335
|
-
if (caseType === "upper" && word[0]) return word[0].toLocaleUpperCase() + word.slice(1);
|
|
1336
|
-
return word;
|
|
1337
|
-
});
|
|
1338
|
-
}
|
|
1339
|
-
|
|
1340
|
-
//#endregion
|
|
1341
|
-
//#region src/utils/string/stringReplace.ts
|
|
1342
|
-
/**
|
|
1343
|
-
* 字符串替换
|
|
1344
|
-
* - 替换第一个匹配项
|
|
1345
|
-
*
|
|
1346
|
-
* @param input 待处理字符串
|
|
1347
|
-
* @param search 匹配项
|
|
1348
|
-
* @param replacement 替换项
|
|
1349
|
-
* @returns 替换后的字符串
|
|
1350
|
-
* @example
|
|
1351
|
-
* ```ts
|
|
1352
|
-
* stringReplace("hello world", "world", "context"); // "hello context"
|
|
1353
|
-
* ```
|
|
1354
|
-
*/
|
|
1355
|
-
function stringReplace(input, search, replacement) {
|
|
1356
|
-
if (!isString(input, true)) return "";
|
|
1357
|
-
return input.replace(search, replacement);
|
|
1358
|
-
}
|
|
1359
|
-
|
|
1360
|
-
//#endregion
|
|
1361
|
-
//#region src/utils/string/stringTemplate.ts
|
|
1362
|
-
const R1 = /\{\{(.+?)\}\}/g;
|
|
1363
|
-
/**
|
|
1364
|
-
* 字符串模板替换
|
|
1365
|
-
* - 使用对象的属性值替换字符串中的 {{key}} 模板
|
|
1366
|
-
*
|
|
1367
|
-
* @param input 待处理字符串
|
|
1368
|
-
* @param template 模板对象
|
|
1369
|
-
* @param regex 模板匹配正则 (默认: `\{\{(.+?)\}\}`)
|
|
1370
|
-
* @returns 替换后的字符串
|
|
1371
|
-
* @example
|
|
1372
|
-
* ```ts
|
|
1373
|
-
* stringTemplate("Hello {{name}}", { name: "World" }); // "Hello World"
|
|
1374
|
-
* ```
|
|
1375
|
-
*/
|
|
1376
|
-
function stringTemplate(input, template, regex = R1) {
|
|
1377
|
-
if (!isString(input, true)) return "";
|
|
1378
|
-
regex.lastIndex = 0;
|
|
1379
|
-
let result = "";
|
|
1380
|
-
let from = 0;
|
|
1381
|
-
let match;
|
|
1382
|
-
while (match = regex.exec(input)) {
|
|
1383
|
-
const replacement = template[match[1]];
|
|
1384
|
-
const valueToInsert = replacement === null || replacement === void 0 ? match[0] : replacement;
|
|
1385
|
-
result += input.slice(from, match.index) + valueToInsert;
|
|
1386
|
-
from = regex.lastIndex;
|
|
1387
|
-
}
|
|
1388
|
-
return result + input.slice(from);
|
|
1389
|
-
}
|
|
1390
|
-
|
|
1391
|
-
//#endregion
|
|
1392
|
-
//#region src/utils/string/stringToJson.ts
|
|
1393
|
-
/**
|
|
1394
|
-
* 处理 JSON 字符串
|
|
1395
|
-
*
|
|
1396
|
-
* @param input 待处理字符串
|
|
1397
|
-
* @param safeValue 安全值 (当解析失败或输入无效时返回)
|
|
1398
|
-
* @returns 解析后的对象 或 安全值
|
|
1399
|
-
* @example
|
|
1400
|
-
* ```ts
|
|
1401
|
-
* stringToJson('{"a": 1}', {}); // { a: 1 }
|
|
1402
|
-
* stringToJson('invalid', {}); // {}
|
|
1403
|
-
* ```
|
|
1404
|
-
*/
|
|
1405
|
-
function stringToJson(input, safeValue) {
|
|
1406
|
-
if (!isString(input, true)) return safeValue;
|
|
1407
|
-
try {
|
|
1408
|
-
return JSON.parse(input);
|
|
1409
|
-
} catch (error) {
|
|
1410
|
-
return safeValue;
|
|
1411
|
-
}
|
|
1412
|
-
}
|
|
1413
|
-
|
|
1414
|
-
//#endregion
|
|
1415
|
-
//#region src/utils/string/stringToLowerCase.ts
|
|
1416
|
-
function stringToLowerCase(input) {
|
|
1417
|
-
if (!isString(input, true)) return "";
|
|
1418
|
-
return input.toLowerCase();
|
|
1419
|
-
}
|
|
1420
|
-
|
|
1421
|
-
//#endregion
|
|
1422
|
-
//#region src/utils/string/stringToPosix.ts
|
|
1423
|
-
/**
|
|
1424
|
-
* 将路径转换为 POSIX 风格
|
|
1425
|
-
* - 统一使用正斜杠 (/)
|
|
1426
|
-
* - 可选移除 Windows 盘符 (如 C:)
|
|
1427
|
-
* - 可选移除开头的斜杠
|
|
1428
|
-
* - 规范化连续斜杠为单个斜杠
|
|
1429
|
-
*
|
|
1430
|
-
* @param input 待处理字符串
|
|
1431
|
-
* @param removeLeadingSlash 是否移除开头斜杠,默认为 `false`。如果移除了盘符,路径通常会以 / 开头,此参数可控制是否保留该 /
|
|
1432
|
-
* @returns 转换后的路径,如果输入无效则返回空字符串
|
|
1433
|
-
*
|
|
1434
|
-
* @example
|
|
1435
|
-
* ```ts
|
|
1436
|
-
* stringToPosix("C:\\Windows\\System32");
|
|
1437
|
-
* // 默认: "/Windows/System32" (移除了 C: 并标准化)
|
|
1438
|
-
*
|
|
1439
|
-
* stringToPosix("C:\\Windows\\System32", true);
|
|
1440
|
-
* // 移除开头斜杠: "Windows/System32"
|
|
1441
|
-
*
|
|
1442
|
-
* stringToPosix("\\\\server\\share\\file.txt");
|
|
1443
|
-
* // UNC 路径: "/server/share/file.txt"
|
|
1444
|
-
*
|
|
1445
|
-
* stringToPosix("folder\\subfolder\\file.txt");
|
|
1446
|
-
* // 相对路径: "folder/subfolder/file.txt"
|
|
1447
|
-
* ```
|
|
1448
|
-
*/
|
|
1449
|
-
function stringToPosix(input, removeLeadingSlash = false) {
|
|
1450
|
-
if (!isString(input, true)) return "";
|
|
1451
|
-
let normalized = input.replace(/^[A-Za-z]:([\\/])?/, (_, separator) => {
|
|
1452
|
-
return separator ? "/" : "";
|
|
1453
|
-
});
|
|
1454
|
-
normalized = normalized.replace(/\\/g, "/");
|
|
1455
|
-
normalized = normalized.replace(/\/+/g, "/");
|
|
1456
|
-
if (removeLeadingSlash && normalized.startsWith("/")) normalized = normalized.substring(1);
|
|
1457
|
-
return normalized;
|
|
1458
|
-
}
|
|
1459
|
-
|
|
1460
|
-
//#endregion
|
|
1461
|
-
//#region src/utils/string/stringToUpperCase.ts
|
|
1462
|
-
function stringToUpperCase(input) {
|
|
1463
|
-
if (!isString(input, true)) return "";
|
|
1464
|
-
return input.toUpperCase();
|
|
1465
|
-
}
|
|
1466
|
-
|
|
1467
|
-
//#endregion
|
|
1468
|
-
//#region src/utils/string/stringToValues.ts
|
|
1469
|
-
function stringToValues(input, valueType = "number", splitSymbol = ",") {
|
|
1470
|
-
if (!isString(input, true)) return [];
|
|
1471
|
-
try {
|
|
1472
|
-
const values = input.split(splitSymbol);
|
|
1473
|
-
if (valueType === "number") return values.map((d) => Number(d));
|
|
1474
|
-
return values;
|
|
1475
|
-
} catch (error) {
|
|
1476
|
-
return [];
|
|
1477
|
-
}
|
|
1478
|
-
}
|
|
1479
|
-
|
|
1480
|
-
//#endregion
|
|
1481
|
-
//#region src/utils/string/stringTrim.ts
|
|
1482
|
-
/**
|
|
1483
|
-
* 从字符串中裁切掉所有的前缀和后缀字符
|
|
1484
|
-
*
|
|
1485
|
-
* @param input 待处理字符串
|
|
1486
|
-
* @param charsToTrim 裁切字符,默认为 `" "`
|
|
1487
|
-
* @returns 裁切后的字符串
|
|
1488
|
-
* @example
|
|
1489
|
-
* ```ts
|
|
1490
|
-
* stringTrim(" hello "); // "hello"
|
|
1491
|
-
* stringTrim("__hello__", "_"); // "hello"
|
|
1492
|
-
* ```
|
|
1493
|
-
*/
|
|
1494
|
-
function stringTrim(input, charsToTrim = " ") {
|
|
1495
|
-
if (!isString(input, true)) return "";
|
|
1496
|
-
const toTrim = charsToTrim.replace(/[\W]{1}/g, "\\$&");
|
|
1497
|
-
const regex = new RegExp(`^[${toTrim}]+|[${toTrim}]+$`, "g");
|
|
1498
|
-
return input.replace(regex, "");
|
|
1499
|
-
}
|
|
1500
|
-
|
|
1501
|
-
//#endregion
|
|
1502
|
-
//#region src/utils/string/stringTruncate.ts
|
|
1503
|
-
/**
|
|
1504
|
-
* 截取字符串
|
|
1505
|
-
* - 支持自定义省略符,不会截断在汉字中间(因为JS字符串本身按字符处理)
|
|
1506
|
-
*
|
|
1507
|
-
* @param input 待处理字符串
|
|
1508
|
-
* @param maxLength 最大长度 (包含省略符)
|
|
1509
|
-
* @param ellipsis 省略符,默认为 `...`
|
|
1510
|
-
* @returns 截取后的字符串
|
|
1511
|
-
* @example
|
|
1512
|
-
* ```ts
|
|
1513
|
-
* stringTruncate("hello world", 8); // "hello..."
|
|
1514
|
-
* ```
|
|
1515
|
-
*/
|
|
1516
|
-
function stringTruncate(input, maxLength, ellipsis = "...") {
|
|
1517
|
-
if (!isString(input, true)) return "";
|
|
1518
|
-
const codePoints = Array.from(input);
|
|
1519
|
-
if (!isInteger(maxLength) || maxLength < 0) return input;
|
|
1520
|
-
if (codePoints.length <= maxLength) return input;
|
|
1521
|
-
const availableLength = maxLength - ellipsis.length;
|
|
1522
|
-
if (availableLength <= 0) return "";
|
|
1523
|
-
return codePoints.slice(0, availableLength).join("") + ellipsis;
|
|
1524
|
-
}
|
|
1525
|
-
|
|
1526
1459
|
//#endregion
|
|
1527
1460
|
//#region src/utils/time/timeZone.ts
|
|
1528
1461
|
/**
|
|
@@ -1541,7 +1474,6 @@ function getTimeZone() {
|
|
|
1541
1474
|
timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
1542
1475
|
};
|
|
1543
1476
|
}
|
|
1544
|
-
|
|
1545
1477
|
//#endregion
|
|
1546
1478
|
//#region src/utils/tree/types.ts
|
|
1547
1479
|
function getFinalChildrenKey(tree, meta, options) {
|
|
@@ -1551,7 +1483,6 @@ function getFinalChildrenKey(tree, meta, options) {
|
|
|
1551
1483
|
}
|
|
1552
1484
|
return options.childrenKey;
|
|
1553
1485
|
}
|
|
1554
|
-
|
|
1555
1486
|
//#endregion
|
|
1556
1487
|
//#region src/utils/tree/treeFilter.ts
|
|
1557
1488
|
function preImpl$3(row, callback, options) {
|
|
@@ -1610,8 +1541,8 @@ function breadthImpl$3(row, callback, options) {
|
|
|
1610
1541
|
parents: [...queueOptions.parents, queueRow],
|
|
1611
1542
|
depth: queueOptions.depth + 1
|
|
1612
1543
|
};
|
|
1613
|
-
const subQueueItems = children.map((queueRow
|
|
1614
|
-
queueRow
|
|
1544
|
+
const subQueueItems = children.map((queueRow) => ({
|
|
1545
|
+
queueRow,
|
|
1615
1546
|
queueOptions: nextLevelOptions
|
|
1616
1547
|
}));
|
|
1617
1548
|
queue.push(...subQueueItems);
|
|
@@ -1658,7 +1589,6 @@ function treeFilter(tree, callback, options = {}) {
|
|
|
1658
1589
|
};
|
|
1659
1590
|
return isArray(tree) ? tree.map((row) => traversalMethod(row, callback, innerOptions)).filter((t) => !!t) : traversalMethod(tree, callback, innerOptions) || [];
|
|
1660
1591
|
}
|
|
1661
|
-
|
|
1662
1592
|
//#endregion
|
|
1663
1593
|
//#region src/utils/tree/treeFind.ts
|
|
1664
1594
|
const strategies$2 = {
|
|
@@ -1705,8 +1635,8 @@ function breadthImpl$2(row, callback, options) {
|
|
|
1705
1635
|
parents: [...queueOptions.parents, queueRow],
|
|
1706
1636
|
depth: queueOptions.depth + 1
|
|
1707
1637
|
};
|
|
1708
|
-
const subQueueItems = children.map((queueRow
|
|
1709
|
-
queueRow
|
|
1638
|
+
const subQueueItems = children.map((queueRow) => ({
|
|
1639
|
+
queueRow,
|
|
1710
1640
|
queueOptions: nextLevelOptions
|
|
1711
1641
|
}));
|
|
1712
1642
|
queue.push(...subQueueItems);
|
|
@@ -1748,7 +1678,6 @@ function treeFind(tree, callback, options = {}) {
|
|
|
1748
1678
|
}
|
|
1749
1679
|
return traversalMethod(tree, callback, innerOptions);
|
|
1750
1680
|
}
|
|
1751
|
-
|
|
1752
1681
|
//#endregion
|
|
1753
1682
|
//#region src/utils/tree/treeForEach.ts
|
|
1754
1683
|
const strategies$1 = {
|
|
@@ -1795,8 +1724,8 @@ function breadthImpl$1(row, callback, options) {
|
|
|
1795
1724
|
parents: [...queueOptions.parents, queueRow],
|
|
1796
1725
|
depth: queueOptions.depth + 1
|
|
1797
1726
|
};
|
|
1798
|
-
const subQueueItems = children.map((queueRow
|
|
1799
|
-
queueRow
|
|
1727
|
+
const subQueueItems = children.map((queueRow) => ({
|
|
1728
|
+
queueRow,
|
|
1800
1729
|
queueOptions: nextLevelOptions
|
|
1801
1730
|
}));
|
|
1802
1731
|
queue.push(...subQueueItems);
|
|
@@ -1832,7 +1761,6 @@ function treeForEach(tree, callback, options = {}) {
|
|
|
1832
1761
|
if (isArray(tree)) for (const row of tree) traversalMethod(row, callback, innerOptions);
|
|
1833
1762
|
else traversalMethod(tree, callback, innerOptions);
|
|
1834
1763
|
}
|
|
1835
|
-
|
|
1836
1764
|
//#endregion
|
|
1837
1765
|
//#region src/utils/tree/treeMap.ts
|
|
1838
1766
|
const strategies = {
|
|
@@ -1894,8 +1822,8 @@ function breadthImpl(row, callback, options) {
|
|
|
1894
1822
|
parents: [...queueOptions.parents, queueRow],
|
|
1895
1823
|
depth: queueOptions.depth + 1
|
|
1896
1824
|
};
|
|
1897
|
-
const subQueueItems = children.map((queueRow
|
|
1898
|
-
queueRow
|
|
1825
|
+
const subQueueItems = children.map((queueRow) => ({
|
|
1826
|
+
queueRow,
|
|
1899
1827
|
queueOptions: nextLevelOptions
|
|
1900
1828
|
}));
|
|
1901
1829
|
queue.push(...subQueueItems);
|
|
@@ -1926,7 +1854,6 @@ function treeMap(tree, callback, options = {}) {
|
|
|
1926
1854
|
};
|
|
1927
1855
|
return isArray(tree) ? tree.map((row) => traversalMethod(row, callback, innerOptions)) : traversalMethod(tree, callback, innerOptions);
|
|
1928
1856
|
}
|
|
1929
|
-
|
|
1930
1857
|
//#endregion
|
|
1931
1858
|
//#region src/utils/tree/rowsToTree.ts
|
|
1932
1859
|
/**
|
|
@@ -1971,7 +1898,6 @@ function rowsToTree(rows, options) {
|
|
|
1971
1898
|
}
|
|
1972
1899
|
return result;
|
|
1973
1900
|
}
|
|
1974
|
-
|
|
1975
1901
|
//#endregion
|
|
1976
1902
|
//#region src/utils/tree/treeToRows.ts
|
|
1977
1903
|
/**
|
|
@@ -1998,7 +1924,7 @@ function treeToRows(tree, options = {}) {
|
|
|
1998
1924
|
}), options);
|
|
1999
1925
|
return result;
|
|
2000
1926
|
}
|
|
2001
|
-
|
|
2002
1927
|
//#endregion
|
|
2003
|
-
export {
|
|
2004
|
-
|
|
1928
|
+
export { arrayDifference as $, stringToLowerCase as A, isFalsyLike as At, isWebWorker as B, isBoolean as Bt, mathToBignumber as C, isNull as Ct, stringToUpperCase as D, isIframe as Dt, stringToValues as E, isIterable as Et, to as F, isClass as Ft, arrayReplaceMove as G, isTypedArray as Gt, arrayUnzip as H, isFile as Ht, isIOSMobile as I, isAsyncFunction as It, arrayMerge as J, arrayReplace as K, isAbortSignal as Kt, isMobile as L, isAsyncGeneratorFunction as Lt, stringTemplate as M, isEqual as Mt, stringReplace as N, isEnumeration as Nt, stringToPosix as O, isInIframe as Ot, stringInitialCase as P, isDate as Pt, arrayFirst as Q, isTablet as R, isFunction as Rt, mathToDecimal as S, isPositiveInteger as St, stringTrim as T, isWeakMap as Tt, arrayZip as U, isBigInt as Ut, arrayZipToObject as V, isBlob as Vt, arraySplit as W, isArray as Wt, arrayIntersection as X, arrayLast as Y, arrayFork as Z, enumValues as _, isInfinityLike as _t, treeFind as a, isURLSearchParams as at, numberWithin as b, isNegativeInteger as bt, objectValues as c, isString as ct, objectKeys as d, isRegExp as dt, arrayCounting as et, objectInvert as f, isReadableStream as ft, objectEntries as g, isInfinity as gt, objectMapEntries as h, isObject as ht, treeForEach as i, isWebSocket as it, stringToJson as j, isError as jt, stringToNumber as k, isFalsy as kt, objectPick as l, isSet as lt, objectAssign as m, isPromiseLike as mt, rowsToTree as n, arrayCast as nt, treeFilter as o, isUndefined as ot, objectCrush as p, isPromise as pt, arrayPick as q, treeMap as r, isWindow as rt, getTimeZone as s, isSymbol as st, treeToRows as t, arrayCompete as tt, objectOmit as u, isWeakSet as ut, enumKeys as v, isInteger as vt, stringTruncate as w, isMap as wt, mathToEvaluate as x, isNumber as xt, enumEntries as y, isNaN as yt, isBrowser as z, isGeneratorFunction as zt };
|
|
1929
|
+
|
|
1930
|
+
//# sourceMappingURL=utils-DvWLCdYR.js.map
|