@pawover/kit 0.0.1 → 0.1.1
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/package.json +42 -45
- package/packages/hooks/dist/alova.d.ts +3 -4
- package/packages/hooks/dist/metadata.json +0 -1
- package/packages/hooks/dist/react.d.ts +4 -13
- package/packages/hooks/dist/react.js +820 -244
- package/packages/utils/dist/index.d.ts +697 -70
- package/packages/utils/dist/index.js +216 -2
- package/packages/utils/dist/math.d.ts +4 -0
- package/packages/utils/dist/math.js +1 -1
- package/packages/utils/dist/{string-DCWqoW4P.js → string-p6hZ1Mjb.js} +174 -7
- package/packages/utils/dist/vite.d.ts +13 -0
- package/packages/utils/dist/vite.js +13 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//#region \0@oxc-project+runtime@0.
|
|
1
|
+
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/typeof.js
|
|
2
2
|
function _typeof(o) {
|
|
3
3
|
"@babel/helpers - typeof";
|
|
4
4
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -8,7 +8,7 @@ function _typeof(o) {
|
|
|
8
8
|
}, _typeof(o);
|
|
9
9
|
}
|
|
10
10
|
//#endregion
|
|
11
|
-
//#region \0@oxc-project+runtime@0.
|
|
11
|
+
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPrimitive.js
|
|
12
12
|
function toPrimitive(t, r) {
|
|
13
13
|
if ("object" != _typeof(t) || !t) return t;
|
|
14
14
|
var e = t[Symbol.toPrimitive];
|
|
@@ -20,13 +20,13 @@ function toPrimitive(t, r) {
|
|
|
20
20
|
return ("string" === r ? String : Number)(t);
|
|
21
21
|
}
|
|
22
22
|
//#endregion
|
|
23
|
-
//#region \0@oxc-project+runtime@0.
|
|
23
|
+
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPropertyKey.js
|
|
24
24
|
function toPropertyKey(t) {
|
|
25
25
|
var i = toPrimitive(t, "string");
|
|
26
26
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
27
27
|
}
|
|
28
28
|
//#endregion
|
|
29
|
-
//#region \0@oxc-project+runtime@0.
|
|
29
|
+
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/defineProperty.js
|
|
30
30
|
function _defineProperty(e, r, t) {
|
|
31
31
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
32
32
|
value: t,
|
|
@@ -60,25 +60,29 @@ var TypeUtil = class {
|
|
|
60
60
|
}
|
|
61
61
|
/**
|
|
62
62
|
* 检查 value 是否为 string 类型
|
|
63
|
+
* - 当 `checkEmpty` 为 `true` 时,会先 trim 再判断是否为空
|
|
63
64
|
*
|
|
64
65
|
* @param value 待检查值
|
|
65
|
-
* @param checkEmpty
|
|
66
|
+
* @param checkEmpty 是否检查空字符串(含空白字符串),默认为 `false`
|
|
66
67
|
* @returns 是否为字符串
|
|
67
68
|
* @example
|
|
68
69
|
* ```ts
|
|
69
70
|
* TypeUtil.isString("abc"); // true
|
|
70
71
|
* TypeUtil.isString(""); // true
|
|
71
72
|
* TypeUtil.isString("", true); // false
|
|
73
|
+
* TypeUtil.isString(" ", true); // false
|
|
74
|
+
* TypeUtil.isString(" a ", true); // true
|
|
72
75
|
* ```
|
|
73
76
|
*/
|
|
74
77
|
static isString(value, checkEmpty = false) {
|
|
75
|
-
return typeof value === "string" && (!checkEmpty ||
|
|
78
|
+
return typeof value === "string" && (!checkEmpty || value.trim().length > 0);
|
|
76
79
|
}
|
|
77
80
|
/**
|
|
78
81
|
* 检查 value 是否为 number 类型
|
|
82
|
+
* - 默认会调用 `TypeUtil.isNaN`(内部基于 `Number.isNaN`)过滤掉 `NaN`
|
|
79
83
|
*
|
|
80
84
|
* @param value 待检查值
|
|
81
|
-
* @param checkNaN
|
|
85
|
+
* @param checkNaN 是否检查 `NaN`,默认为 `true`
|
|
82
86
|
* @returns 是否为 number
|
|
83
87
|
* @example
|
|
84
88
|
* ```ts
|
|
@@ -92,9 +96,15 @@ var TypeUtil = class {
|
|
|
92
96
|
}
|
|
93
97
|
/**
|
|
94
98
|
* 检查 value 是否为 NaN
|
|
99
|
+
* - 禁止使用全局 `isNaN`,其会先进行隐式数字转换,可能导致误判(例如 `isNaN("foo") === true`)
|
|
100
|
+
* - 使用 `Number.isNaN` 仅在值本身就是 `NaN` 时返回 `true`,语义更严格且更安全
|
|
95
101
|
*
|
|
96
102
|
* @param value 待检查值
|
|
97
103
|
* @returns 是否为 NaN
|
|
104
|
+
* @example
|
|
105
|
+
* ```ts
|
|
106
|
+
* TypeUtil.isNaN(NaN); // true
|
|
107
|
+
* ```
|
|
98
108
|
*/
|
|
99
109
|
static isNaN(value) {
|
|
100
110
|
return Number.isNaN(value);
|
|
@@ -105,6 +115,11 @@ var TypeUtil = class {
|
|
|
105
115
|
* @param value 待检查值
|
|
106
116
|
* @param checkSafe 是否附加安全整数检查
|
|
107
117
|
* @returns 是否为整数
|
|
118
|
+
* @example
|
|
119
|
+
* ```ts
|
|
120
|
+
* TypeUtil.isInteger(1); // true
|
|
121
|
+
* TypeUtil.isInteger(1.1); // false
|
|
122
|
+
* ```
|
|
108
123
|
*/
|
|
109
124
|
static isInteger(value, checkSafe = true) {
|
|
110
125
|
const check = Number.isInteger(value);
|
|
@@ -116,6 +131,11 @@ var TypeUtil = class {
|
|
|
116
131
|
*
|
|
117
132
|
* @param value 待检查值
|
|
118
133
|
* @param checkSafe 是否附加安全整数检查
|
|
134
|
+
* @example
|
|
135
|
+
* ```ts
|
|
136
|
+
* TypeUtil.isPositiveInteger(1); // true
|
|
137
|
+
* TypeUtil.isPositiveInteger(0); // false
|
|
138
|
+
* ```
|
|
119
139
|
*/
|
|
120
140
|
static isPositiveInteger(value, checkSafe = true) {
|
|
121
141
|
return this.isInteger(value, checkSafe) && value > 0;
|
|
@@ -126,6 +146,11 @@ var TypeUtil = class {
|
|
|
126
146
|
*
|
|
127
147
|
* @param value 待检查值
|
|
128
148
|
* @param checkSafe 是否附加安全整数检查
|
|
149
|
+
* @example
|
|
150
|
+
* ```ts
|
|
151
|
+
* TypeUtil.isNegativeInteger(-1); // true
|
|
152
|
+
* TypeUtil.isNegativeInteger(0); // false
|
|
153
|
+
* ```
|
|
129
154
|
*/
|
|
130
155
|
static isNegativeInteger(value, checkSafe = true) {
|
|
131
156
|
return this.isInteger(value, checkSafe) && value < 0;
|
|
@@ -135,6 +160,11 @@ var TypeUtil = class {
|
|
|
135
160
|
* - 排除 `NaN`
|
|
136
161
|
*
|
|
137
162
|
* @param value 待检查值
|
|
163
|
+
* @example
|
|
164
|
+
* ```ts
|
|
165
|
+
* TypeUtil.isInfinity(Infinity); // true
|
|
166
|
+
* TypeUtil.isInfinity(1); // false
|
|
167
|
+
* ```
|
|
138
168
|
*/
|
|
139
169
|
static isInfinity(value) {
|
|
140
170
|
return this.isNumber(value) && (Number.POSITIVE_INFINITY === value || Number.NEGATIVE_INFINITY === value);
|
|
@@ -144,6 +174,11 @@ var TypeUtil = class {
|
|
|
144
174
|
* - 排除 `NaN`
|
|
145
175
|
*
|
|
146
176
|
* @param value 待检查值
|
|
177
|
+
* @example
|
|
178
|
+
* ```ts
|
|
179
|
+
* TypeUtil.isInfinityLike("Infinity"); // true
|
|
180
|
+
* TypeUtil.isInfinityLike("123"); // false
|
|
181
|
+
* ```
|
|
147
182
|
*/
|
|
148
183
|
static isInfinityLike(value) {
|
|
149
184
|
const check = this.isInfinity(value);
|
|
@@ -162,6 +197,10 @@ var TypeUtil = class {
|
|
|
162
197
|
* 检查 value 是否为 Boolean
|
|
163
198
|
* @param value 待检查值
|
|
164
199
|
* @returns 是否为 Boolean
|
|
200
|
+
* @example
|
|
201
|
+
* ```ts
|
|
202
|
+
* TypeUtil.isBoolean(false); // true
|
|
203
|
+
* ```
|
|
165
204
|
*/
|
|
166
205
|
static isBoolean(value) {
|
|
167
206
|
return typeof value === "boolean";
|
|
@@ -170,6 +209,10 @@ var TypeUtil = class {
|
|
|
170
209
|
* 检查 value 是否为 BigInt
|
|
171
210
|
* @param value 待检查值
|
|
172
211
|
* @returns 是否为 BigInt
|
|
212
|
+
* @example
|
|
213
|
+
* ```ts
|
|
214
|
+
* TypeUtil.isBigInt(1n); // true
|
|
215
|
+
* ```
|
|
173
216
|
*/
|
|
174
217
|
static isBigInt(value) {
|
|
175
218
|
return typeof value === "bigint";
|
|
@@ -178,6 +221,10 @@ var TypeUtil = class {
|
|
|
178
221
|
* 检查 value 是否为 Symbol
|
|
179
222
|
* @param value 待检查值
|
|
180
223
|
* @returns 是否为 Symbol
|
|
224
|
+
* @example
|
|
225
|
+
* ```ts
|
|
226
|
+
* TypeUtil.isSymbol(Symbol("a")); // true
|
|
227
|
+
* ```
|
|
181
228
|
*/
|
|
182
229
|
static isSymbol(value) {
|
|
183
230
|
return typeof value === "symbol";
|
|
@@ -186,6 +233,10 @@ var TypeUtil = class {
|
|
|
186
233
|
* 检查 value 是否为 undefined
|
|
187
234
|
* @param value 待检查值
|
|
188
235
|
* @returns 是否为 undefined
|
|
236
|
+
* @example
|
|
237
|
+
* ```ts
|
|
238
|
+
* TypeUtil.isUndefined(undefined); // true
|
|
239
|
+
* ```
|
|
189
240
|
*/
|
|
190
241
|
static isUndefined(value) {
|
|
191
242
|
return typeof value === "undefined";
|
|
@@ -194,6 +245,10 @@ var TypeUtil = class {
|
|
|
194
245
|
* 检查 value 是否为 null
|
|
195
246
|
* @param value 待检查值
|
|
196
247
|
* @returns 是否为 null
|
|
248
|
+
* @example
|
|
249
|
+
* ```ts
|
|
250
|
+
* TypeUtil.isNull(null); // true
|
|
251
|
+
* ```
|
|
197
252
|
*/
|
|
198
253
|
static isNull(value) {
|
|
199
254
|
return value === null;
|
|
@@ -202,6 +257,10 @@ var TypeUtil = class {
|
|
|
202
257
|
* 检查 value 是否为 Function
|
|
203
258
|
* @param value 待检查值
|
|
204
259
|
* @returns 是否为 Function
|
|
260
|
+
* @example
|
|
261
|
+
* ```ts
|
|
262
|
+
* TypeUtil.isFunction(() => {}); // true
|
|
263
|
+
* ```
|
|
205
264
|
*/
|
|
206
265
|
static isFunction(value) {
|
|
207
266
|
return typeof value === "function";
|
|
@@ -210,6 +269,10 @@ var TypeUtil = class {
|
|
|
210
269
|
* 检查 value 是否为 AsyncFunction
|
|
211
270
|
* @param value 待检查值
|
|
212
271
|
* @returns 是否为 AsyncFunction
|
|
272
|
+
* @example
|
|
273
|
+
* ```ts
|
|
274
|
+
* TypeUtil.isAsyncFunction(async () => {}); // true
|
|
275
|
+
* ```
|
|
213
276
|
*/
|
|
214
277
|
static isAsyncFunction(value) {
|
|
215
278
|
return this.isFunction(value) && this.getPrototypeString(value) === this.PROTOTYPE_TAGS.ASYNC_FUNCTION;
|
|
@@ -218,6 +281,10 @@ var TypeUtil = class {
|
|
|
218
281
|
* 检查 value 是否为 GeneratorFunction
|
|
219
282
|
* @param value 待检查值
|
|
220
283
|
* @returns 是否为 GeneratorFunction
|
|
284
|
+
* @example
|
|
285
|
+
* ```ts
|
|
286
|
+
* TypeUtil.isGeneratorFunction(function * a () {}); // true
|
|
287
|
+
* ```
|
|
221
288
|
*/
|
|
222
289
|
static isGeneratorFunction(value) {
|
|
223
290
|
return this.isFunction(value) && this.getPrototypeString(value) === this.PROTOTYPE_TAGS.GENERATOR_FUNCTION;
|
|
@@ -226,6 +293,10 @@ var TypeUtil = class {
|
|
|
226
293
|
* 检查 value 是否为 AsyncGeneratorFunction
|
|
227
294
|
* @param value 待检查值
|
|
228
295
|
* @returns 是否为 AsyncGeneratorFunction
|
|
296
|
+
* @example
|
|
297
|
+
* ```ts
|
|
298
|
+
* TypeUtil.isAsyncGeneratorFunction(async function * a () {}); // true
|
|
299
|
+
* ```
|
|
229
300
|
*/
|
|
230
301
|
static isAsyncGeneratorFunction(value) {
|
|
231
302
|
return this.isFunction(value) && this.getPrototypeString(value) === this.PROTOTYPE_TAGS.ASYNC_GENERATOR_FUNCTION;
|
|
@@ -234,6 +305,10 @@ var TypeUtil = class {
|
|
|
234
305
|
* 检查 value 是否为 Promise
|
|
235
306
|
* @param value 待检查值
|
|
236
307
|
* @returns 是否为 Promise
|
|
308
|
+
* @example
|
|
309
|
+
* ```ts
|
|
310
|
+
* TypeUtil.isPromise(Promise.resolve(1)); // true
|
|
311
|
+
* ```
|
|
237
312
|
*/
|
|
238
313
|
static isPromise(value) {
|
|
239
314
|
return this.getPrototypeString(value) === this.PROTOTYPE_TAGS.PROMISE;
|
|
@@ -243,6 +318,10 @@ var TypeUtil = class {
|
|
|
243
318
|
* - 可识别拥有 then 方法的非 Promise 对象
|
|
244
319
|
* @param value 待检查值
|
|
245
320
|
* @returns 是否为 PromiseLike
|
|
321
|
+
* @example
|
|
322
|
+
* ```ts
|
|
323
|
+
* TypeUtil.isPromiseLike({ then: () => {} }); // true
|
|
324
|
+
* ```
|
|
246
325
|
*/
|
|
247
326
|
static isPromiseLike(value) {
|
|
248
327
|
return this.isPromise(value) || this.isObject(value, false) && this.isFunction(value["then"]);
|
|
@@ -278,6 +357,11 @@ var TypeUtil = class {
|
|
|
278
357
|
*
|
|
279
358
|
* @param enumeration 待检查值
|
|
280
359
|
* @returns [是否为有效的枚举, 是否为双向枚举]
|
|
360
|
+
* @example
|
|
361
|
+
* ```ts
|
|
362
|
+
* enum A { X, Y }
|
|
363
|
+
* TypeUtil.isEnumeration(A); // [true, true]
|
|
364
|
+
* ```
|
|
281
365
|
*/
|
|
282
366
|
static isEnumeration(enumeration) {
|
|
283
367
|
if (typeof enumeration !== "object" || enumeration === null) return [false, false];
|
|
@@ -359,6 +443,10 @@ var TypeUtil = class {
|
|
|
359
443
|
* 检查 value 是否为 Map
|
|
360
444
|
* @param value 待检查值
|
|
361
445
|
* @returns 是否为 Map
|
|
446
|
+
* @example
|
|
447
|
+
* ```ts
|
|
448
|
+
* TypeUtil.isMap(new Map()); // true
|
|
449
|
+
* ```
|
|
362
450
|
*/
|
|
363
451
|
static isMap(value) {
|
|
364
452
|
return this.getPrototypeString(value) === this.PROTOTYPE_TAGS.MAP;
|
|
@@ -367,6 +455,10 @@ var TypeUtil = class {
|
|
|
367
455
|
* 检查 value 是否为 WeakMap
|
|
368
456
|
* @param value 待检查值
|
|
369
457
|
* @returns 是否为 WeakMap
|
|
458
|
+
* @example
|
|
459
|
+
* ```ts
|
|
460
|
+
* TypeUtil.isWeakMap(new WeakMap()); // true
|
|
461
|
+
* ```
|
|
370
462
|
*/
|
|
371
463
|
static isWeakMap(value) {
|
|
372
464
|
return this.getPrototypeString(value) === this.PROTOTYPE_TAGS.WEAK_MAP;
|
|
@@ -375,6 +467,10 @@ var TypeUtil = class {
|
|
|
375
467
|
* 检查 value 是否为 Set
|
|
376
468
|
* @param value 待检查值
|
|
377
469
|
* @returns 是否为 Set
|
|
470
|
+
* @example
|
|
471
|
+
* ```ts
|
|
472
|
+
* TypeUtil.isSet(new Set()); // true
|
|
473
|
+
* ```
|
|
378
474
|
*/
|
|
379
475
|
static isSet(value) {
|
|
380
476
|
return this.getPrototypeString(value) === this.PROTOTYPE_TAGS.SET;
|
|
@@ -383,6 +479,10 @@ var TypeUtil = class {
|
|
|
383
479
|
* 检查 value 是否为 WeakSet
|
|
384
480
|
* @param value 待检查值
|
|
385
481
|
* @returns 是否为 WeakSet
|
|
482
|
+
* @example
|
|
483
|
+
* ```ts
|
|
484
|
+
* TypeUtil.isWeakSet(new WeakSet()); // true
|
|
485
|
+
* ```
|
|
386
486
|
*/
|
|
387
487
|
static isWeakSet(value) {
|
|
388
488
|
return this.getPrototypeString(value) === this.PROTOTYPE_TAGS.WEAK_SET;
|
|
@@ -391,6 +491,10 @@ var TypeUtil = class {
|
|
|
391
491
|
* 检查 value 是否为 Blob
|
|
392
492
|
* @param value 待检查值
|
|
393
493
|
* @returns 是否为 Blob
|
|
494
|
+
* @example
|
|
495
|
+
* ```ts
|
|
496
|
+
* TypeUtil.isBlob(new Blob(["a"])); // true
|
|
497
|
+
* ```
|
|
394
498
|
*/
|
|
395
499
|
static isBlob(value) {
|
|
396
500
|
return this.getPrototypeString(value) === this.PROTOTYPE_TAGS.BLOB;
|
|
@@ -399,6 +503,10 @@ var TypeUtil = class {
|
|
|
399
503
|
* 检查 value 是否为 File
|
|
400
504
|
* @param value 待检查值
|
|
401
505
|
* @returns 是否为 File
|
|
506
|
+
* @example
|
|
507
|
+
* ```ts
|
|
508
|
+
* TypeUtil.isFile(new File(["a"], "a.txt")); // true
|
|
509
|
+
* ```
|
|
402
510
|
*/
|
|
403
511
|
static isFile(value) {
|
|
404
512
|
return this.getPrototypeString(value) === this.PROTOTYPE_TAGS.FILE;
|
|
@@ -412,6 +520,10 @@ var TypeUtil = class {
|
|
|
412
520
|
*
|
|
413
521
|
* @param value 待检查值
|
|
414
522
|
* @returns 是否为 ReadableStream
|
|
523
|
+
* @example
|
|
524
|
+
* ```ts
|
|
525
|
+
* TypeUtil.isReadableStream(new ReadableStream()); // true
|
|
526
|
+
* ```
|
|
415
527
|
*/
|
|
416
528
|
static isReadableStream(value) {
|
|
417
529
|
if (this.getPrototypeString(value) === this.PROTOTYPE_TAGS.READABLE_STREAM) return true;
|
|
@@ -421,6 +533,10 @@ var TypeUtil = class {
|
|
|
421
533
|
* 检查 value 是否为 Window
|
|
422
534
|
* @param value 待检查值
|
|
423
535
|
* @returns 是否为 Window
|
|
536
|
+
* @example
|
|
537
|
+
* ```ts
|
|
538
|
+
* TypeUtil.isWindow(window); // true
|
|
539
|
+
* ```
|
|
424
540
|
*/
|
|
425
541
|
static isWindow(value) {
|
|
426
542
|
return this.getPrototypeString(value) === this.PROTOTYPE_TAGS.WINDOW;
|
|
@@ -429,6 +545,10 @@ var TypeUtil = class {
|
|
|
429
545
|
* 检查 value 是否为 HTMLIFrameElement
|
|
430
546
|
* @param value 待检查值
|
|
431
547
|
* @returns 是否为 HTMLIFrameElement
|
|
548
|
+
* @example
|
|
549
|
+
* ```ts
|
|
550
|
+
* TypeUtil.isIframe(document.createElement("iframe")); // true
|
|
551
|
+
* ```
|
|
432
552
|
*/
|
|
433
553
|
static isIframe(value) {
|
|
434
554
|
if (typeof window === "undefined") return false;
|
|
@@ -467,6 +587,10 @@ var TypeUtil = class {
|
|
|
467
587
|
* 检查 value 是否为 Error 对象
|
|
468
588
|
* @param value 待检查值
|
|
469
589
|
* @returns 是否为 Error
|
|
590
|
+
* @example
|
|
591
|
+
* ```ts
|
|
592
|
+
* TypeUtil.isError(new Error("x")); // true
|
|
593
|
+
* ```
|
|
470
594
|
*/
|
|
471
595
|
static isError(value) {
|
|
472
596
|
return value instanceof Error || this.getPrototypeString(value) === this.PROTOTYPE_TAGS.ERROR;
|
|
@@ -475,6 +599,10 @@ var TypeUtil = class {
|
|
|
475
599
|
* 检查 value 是否为 RegExp
|
|
476
600
|
* @param value 待检查值
|
|
477
601
|
* @returns 是否为 RegExp
|
|
602
|
+
* @example
|
|
603
|
+
* ```ts
|
|
604
|
+
* TypeUtil.isRegExp(/a/); // true
|
|
605
|
+
* ```
|
|
478
606
|
*/
|
|
479
607
|
static isRegExp(value) {
|
|
480
608
|
if (typeof value !== "object" || value === null) return false;
|
|
@@ -489,6 +617,10 @@ var TypeUtil = class {
|
|
|
489
617
|
* 检查 value 是否为 WebSocket
|
|
490
618
|
* @param value 待检查值
|
|
491
619
|
* @returns 是否为 WebSocket
|
|
620
|
+
* @example
|
|
621
|
+
* ```ts
|
|
622
|
+
* TypeUtil.isWebSocket(new WebSocket("wss://echo.websocket.events")); // true
|
|
623
|
+
* ```
|
|
492
624
|
*/
|
|
493
625
|
static isWebSocket(value) {
|
|
494
626
|
return this.getPrototypeString(value) === this.PROTOTYPE_TAGS.WEB_SOCKET;
|
|
@@ -497,6 +629,10 @@ var TypeUtil = class {
|
|
|
497
629
|
* 检查 value 是否为 URLSearchParams
|
|
498
630
|
* @param value 待检查值
|
|
499
631
|
* @returns 是否为 URLSearchParams
|
|
632
|
+
* @example
|
|
633
|
+
* ```ts
|
|
634
|
+
* TypeUtil.isURLSearchParams(new URLSearchParams("a=1")); // true
|
|
635
|
+
* ```
|
|
500
636
|
*/
|
|
501
637
|
static isURLSearchParams(value) {
|
|
502
638
|
return this.getPrototypeString(value) === this.PROTOTYPE_TAGS.URL_SEARCH_PARAMS;
|
|
@@ -505,6 +641,10 @@ var TypeUtil = class {
|
|
|
505
641
|
* 检查 value 是否为 AbortSignal
|
|
506
642
|
* @param value 待检查值
|
|
507
643
|
* @returns 是否为 AbortSignal
|
|
644
|
+
* @example
|
|
645
|
+
* ```ts
|
|
646
|
+
* TypeUtil.isAbortSignal(new AbortController().signal); // true
|
|
647
|
+
* ```
|
|
508
648
|
*/
|
|
509
649
|
static isAbortSignal(value) {
|
|
510
650
|
return this.getPrototypeString(value) === this.PROTOTYPE_TAGS.ABORT_SIGNAL;
|
|
@@ -513,6 +653,10 @@ var TypeUtil = class {
|
|
|
513
653
|
* 检查 value 是否为可迭代对象 (Iterable)
|
|
514
654
|
* @param value 待检查值
|
|
515
655
|
* @returns 是否为 Iterable
|
|
656
|
+
* @example
|
|
657
|
+
* ```ts
|
|
658
|
+
* TypeUtil.isIterable([1, 2]); // true
|
|
659
|
+
* ```
|
|
516
660
|
*/
|
|
517
661
|
static isIterable(value) {
|
|
518
662
|
return !!value && typeof value[Symbol.iterator] === "function";
|
|
@@ -521,11 +665,27 @@ var TypeUtil = class {
|
|
|
521
665
|
* 检查 value 是否为 Falsy 值 (false, 0, "", null, undefined, NaN)
|
|
522
666
|
* @param value 待检查值
|
|
523
667
|
* @returns 是否为 Falsy
|
|
668
|
+
* @example
|
|
669
|
+
* ```ts
|
|
670
|
+
* TypeUtil.isFalsy(0); // true
|
|
671
|
+
* ```
|
|
524
672
|
*/
|
|
525
673
|
static isFalsy(value) {
|
|
526
674
|
if (this.isNaN(value) || this.isNull(value) || this.isUndefined(value)) return true;
|
|
527
675
|
return value === false || value === 0 || value === 0n || value === "";
|
|
528
676
|
}
|
|
677
|
+
/**
|
|
678
|
+
* 检查 value 是否为 FalsyLike 值
|
|
679
|
+
* - 包含字符串形式的 `"null"`、`"undefined"`、`"false"`、`"0"` 等
|
|
680
|
+
*
|
|
681
|
+
* @param value 待检查值
|
|
682
|
+
* @returns 是否为 FalsyLike
|
|
683
|
+
* @example
|
|
684
|
+
* ```ts
|
|
685
|
+
* TypeUtil.isFalsyLike("false"); // true
|
|
686
|
+
* TypeUtil.isFalsyLike("hello"); // false
|
|
687
|
+
* ```
|
|
688
|
+
*/
|
|
529
689
|
static isFalsyLike(value) {
|
|
530
690
|
if (this.isFalsy(value)) return true;
|
|
531
691
|
return typeof value === "string" && (value === "null" || value === "undefined" || value === "NaN" || value === "false" || value === "0" || value === "-0" || value === "0n");
|
|
@@ -581,6 +741,13 @@ _defineProperty(TypeUtil, "TYPED_ARRAY_TAGS", new Set([
|
|
|
581
741
|
* 字符串工具类
|
|
582
742
|
*/
|
|
583
743
|
var StringUtil = class {
|
|
744
|
+
static cast(candidate, checkEmpty = true) {
|
|
745
|
+
if (checkEmpty) {
|
|
746
|
+
if (candidate === null || candidate === void 0) return "";
|
|
747
|
+
if (typeof candidate === "string" && candidate.trim().length === 0) return "";
|
|
748
|
+
}
|
|
749
|
+
return String(candidate);
|
|
750
|
+
}
|
|
584
751
|
/**
|
|
585
752
|
* 从字符串中提取数字字符串
|
|
586
753
|
* - 移除非数字字符,保留符号和小数点
|
|
@@ -9,6 +9,19 @@ declare class ViteUtil {
|
|
|
9
9
|
* 开发服务器反向代理配置
|
|
10
10
|
*
|
|
11
11
|
* @param proxyList 代理配置项
|
|
12
|
+
* @param options 追加到每个代理项的 Vite `ProxyOptions`
|
|
13
|
+
* @returns Vite `server.proxy` 可直接使用的配置对象
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* ViteUtil.toProxy([
|
|
17
|
+
* ["/api", "http://localhost:3000"],
|
|
18
|
+
* ["/mock", "https://example.com"],
|
|
19
|
+
* ]);
|
|
20
|
+
* // {
|
|
21
|
+
* // "/api": { target: "http://localhost:3000", changeOrigin: true, ws: true, rewrite: [Function] },
|
|
22
|
+
* // "/mock": { target: "https://example.com", changeOrigin: true, ws: true, secure: false, rewrite: [Function] }
|
|
23
|
+
* // }
|
|
24
|
+
* ```
|
|
12
25
|
*/
|
|
13
26
|
static toProxy<L extends [string, string][]>(proxyList: L, options?: ProxyOptions | undefined): Record<string, ProxyOptions>;
|
|
14
27
|
}
|
|
@@ -7,6 +7,19 @@ var ViteUtil = class {
|
|
|
7
7
|
* 开发服务器反向代理配置
|
|
8
8
|
*
|
|
9
9
|
* @param proxyList 代理配置项
|
|
10
|
+
* @param options 追加到每个代理项的 Vite `ProxyOptions`
|
|
11
|
+
* @returns Vite `server.proxy` 可直接使用的配置对象
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* ViteUtil.toProxy([
|
|
15
|
+
* ["/api", "http://localhost:3000"],
|
|
16
|
+
* ["/mock", "https://example.com"],
|
|
17
|
+
* ]);
|
|
18
|
+
* // {
|
|
19
|
+
* // "/api": { target: "http://localhost:3000", changeOrigin: true, ws: true, rewrite: [Function] },
|
|
20
|
+
* // "/mock": { target: "https://example.com", changeOrigin: true, ws: true, secure: false, rewrite: [Function] }
|
|
21
|
+
* // }
|
|
22
|
+
* ```
|
|
10
23
|
*/
|
|
11
24
|
static toProxy(proxyList, options) {
|
|
12
25
|
const httpsRE = /^https:\/\//;
|