@pawover/kit 0.0.0-beta.9 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/package.json +94 -70
  2. package/packages/hooks/dist/alova.d.ts +30 -0
  3. package/packages/hooks/dist/alova.js +64 -0
  4. package/packages/hooks/dist/index.d.ts +1 -0
  5. package/packages/hooks/dist/index.js +0 -0
  6. package/packages/hooks/dist/metadata.json +15 -0
  7. package/packages/hooks/dist/react.d.ts +155 -0
  8. package/packages/hooks/dist/react.js +2678 -0
  9. package/packages/utils/dist/index.d.ts +4884 -0
  10. package/packages/utils/dist/index.js +1741 -0
  11. package/packages/utils/dist/math.d.ts +58 -0
  12. package/packages/utils/dist/math.js +56 -0
  13. package/packages/utils/dist/metadata.json +14 -0
  14. package/packages/utils/dist/string-C_OCj9Lg.js +950 -0
  15. package/packages/utils/dist/vite.d.ts +29 -0
  16. package/packages/utils/dist/vite.js +39 -0
  17. package/packages/zod/dist/index.d.ts +58 -0
  18. package/packages/zod/dist/index.js +61 -0
  19. package/dist/enums.d.ts +0 -25
  20. package/dist/enums.d.ts.map +0 -1
  21. package/dist/enums.js +0 -25
  22. package/dist/enums.js.map +0 -1
  23. package/dist/hooks-alova.d.ts +0 -23
  24. package/dist/hooks-alova.d.ts.map +0 -1
  25. package/dist/hooks-alova.js +0 -39
  26. package/dist/hooks-alova.js.map +0 -1
  27. package/dist/hooks-react.d.ts +0 -95
  28. package/dist/hooks-react.d.ts.map +0 -1
  29. package/dist/hooks-react.js +0 -328
  30. package/dist/hooks-react.js.map +0 -1
  31. package/dist/index.d.ts +0 -3726
  32. package/dist/index.d.ts.map +0 -1
  33. package/dist/index.js +0 -1469
  34. package/dist/index.js.map +0 -1
  35. package/dist/patches-fetchEventSource.d.ts +0 -815
  36. package/dist/patches-fetchEventSource.d.ts.map +0 -1
  37. package/dist/patches-fetchEventSource.js +0 -316
  38. package/dist/patches-fetchEventSource.js.map +0 -1
  39. package/dist/vite.d.ts +0 -13
  40. package/dist/vite.d.ts.map +0 -1
  41. package/dist/vite.js +0 -23
  42. package/dist/vite.js.map +0 -1
  43. package/dist/zod.d.ts +0 -109
  44. package/dist/zod.d.ts.map +0 -1
  45. package/dist/zod.js +0 -143
  46. package/dist/zod.js.map +0 -1
  47. package/metadata.json +0 -167
@@ -0,0 +1,950 @@
1
+ //#region \0@oxc-project+runtime@0.133.0/helpers/esm/typeof.js
2
+ function _typeof(o) {
3
+ "@babel/helpers - typeof";
4
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
5
+ return typeof o;
6
+ } : function(o) {
7
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
8
+ }, _typeof(o);
9
+ }
10
+ //#endregion
11
+ //#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPrimitive.js
12
+ function toPrimitive(t, r) {
13
+ if ("object" != _typeof(t) || !t) return t;
14
+ var e = t[Symbol.toPrimitive];
15
+ if (void 0 !== e) {
16
+ var i = e.call(t, r || "default");
17
+ if ("object" != _typeof(i)) return i;
18
+ throw new TypeError("@@toPrimitive must return a primitive value.");
19
+ }
20
+ return ("string" === r ? String : Number)(t);
21
+ }
22
+ //#endregion
23
+ //#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPropertyKey.js
24
+ function toPropertyKey(t) {
25
+ var i = toPrimitive(t, "string");
26
+ return "symbol" == _typeof(i) ? i : i + "";
27
+ }
28
+ //#endregion
29
+ //#region \0@oxc-project+runtime@0.133.0/helpers/esm/defineProperty.js
30
+ function _defineProperty(e, r, t) {
31
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
32
+ value: t,
33
+ enumerable: !0,
34
+ configurable: !0,
35
+ writable: !0
36
+ }) : e[r] = t, e;
37
+ }
38
+ //#endregion
39
+ //#region src/type/typeUtil.ts
40
+ /**
41
+ * 类型工具类
42
+ */
43
+ var TypeUtil = class {
44
+ /**
45
+ * 获取值的 [[Prototype]] 标签
46
+ *
47
+ * @param value - 任意 JavaScript 值
48
+ * @returns 标准化的类型标签字符串
49
+ */
50
+ static getPrototypeString(value) {
51
+ return Object.prototype.toString.call(value);
52
+ }
53
+ static isConstructable(fn) {
54
+ try {
55
+ Reflect.construct(fn, []);
56
+ return true;
57
+ } catch {
58
+ return false;
59
+ }
60
+ }
61
+ /**
62
+ * 检查 value 是否为 string 类型
63
+ *
64
+ * @param value 待检查值
65
+ * @param checkEmpty 是否检查空字符串
66
+ * @returns 是否为字符串
67
+ * @example
68
+ * ```ts
69
+ * TypeUtil.isString("abc"); // true
70
+ * TypeUtil.isString(""); // true
71
+ * TypeUtil.isString("", true); // false
72
+ * ```
73
+ */
74
+ static isString(value, checkEmpty = false) {
75
+ return typeof value === "string" && (!checkEmpty || !!value.length);
76
+ }
77
+ /**
78
+ * 检查 value 是否为 number 类型
79
+ * - 默认会调用 `TypeUtil.isNaN`(内部基于 `Number.isNaN`)过滤掉 `NaN`
80
+ *
81
+ * @param value 待检查值
82
+ * @param checkNaN 是否检查 `NaN`,默认为 `true`
83
+ * @returns 是否为 number
84
+ * @example
85
+ * ```ts
86
+ * TypeUtil.isNumber(1); // true
87
+ * TypeUtil.isNumber(NaN); // false (default)
88
+ * TypeUtil.isNumber(NaN, false); // true
89
+ * ```
90
+ */
91
+ static isNumber(value, checkNaN = true) {
92
+ return typeof value === "number" && (!checkNaN || !this.isNaN(value));
93
+ }
94
+ /**
95
+ * 检查 value 是否为 NaN
96
+ * - 禁止使用全局 `isNaN`,其会先进行隐式数字转换,可能导致误判(例如 `isNaN("foo") === true`)
97
+ * - 使用 `Number.isNaN` 仅在值本身就是 `NaN` 时返回 `true`,语义更严格且更安全
98
+ *
99
+ * @param value 待检查值
100
+ * @returns 是否为 NaN
101
+ * @example
102
+ * ```ts
103
+ * TypeUtil.isNaN(NaN); // true
104
+ * ```
105
+ */
106
+ static isNaN(value) {
107
+ return Number.isNaN(value);
108
+ }
109
+ /**
110
+ * 检查 value 是否为整数
111
+ *
112
+ * @param value 待检查值
113
+ * @param checkSafe 是否附加安全整数检查
114
+ * @returns 是否为整数
115
+ * @example
116
+ * ```ts
117
+ * TypeUtil.isInteger(1); // true
118
+ * TypeUtil.isInteger(1.1); // false
119
+ * ```
120
+ */
121
+ static isInteger(value, checkSafe = true) {
122
+ const check = Number.isInteger(value);
123
+ return checkSafe ? check && Number.isSafeInteger(value) : check;
124
+ }
125
+ /**
126
+ * 检查 value 是否为正整数
127
+ * - 此函数中 `0` 不被视为正整数
128
+ *
129
+ * @param value 待检查值
130
+ * @param checkSafe 是否附加安全整数检查
131
+ * @example
132
+ * ```ts
133
+ * TypeUtil.isPositiveInteger(1); // true
134
+ * TypeUtil.isPositiveInteger(0); // false
135
+ * ```
136
+ */
137
+ static isPositiveInteger(value, checkSafe = true) {
138
+ return this.isInteger(value, checkSafe) && value > 0;
139
+ }
140
+ /**
141
+ * 检查 value 是否为负整数
142
+ * - 此函数中 `0` 不被视为负整数
143
+ *
144
+ * @param value 待检查值
145
+ * @param checkSafe 是否附加安全整数检查
146
+ * @example
147
+ * ```ts
148
+ * TypeUtil.isNegativeInteger(-1); // true
149
+ * TypeUtil.isNegativeInteger(0); // false
150
+ * ```
151
+ */
152
+ static isNegativeInteger(value, checkSafe = true) {
153
+ return this.isInteger(value, checkSafe) && value < 0;
154
+ }
155
+ /**
156
+ * 检查 value 是否为 Infinity
157
+ * - 排除 `NaN`
158
+ *
159
+ * @param value 待检查值
160
+ * @example
161
+ * ```ts
162
+ * TypeUtil.isInfinity(Infinity); // true
163
+ * TypeUtil.isInfinity(1); // false
164
+ * ```
165
+ */
166
+ static isInfinity(value) {
167
+ return this.isNumber(value) && (Number.POSITIVE_INFINITY === value || Number.NEGATIVE_INFINITY === value);
168
+ }
169
+ /**
170
+ * 检查 value 是否类似 Infinity
171
+ * - 排除 `NaN`
172
+ *
173
+ * @param value 待检查值
174
+ * @example
175
+ * ```ts
176
+ * TypeUtil.isInfinityLike("Infinity"); // true
177
+ * TypeUtil.isInfinityLike("123"); // false
178
+ * ```
179
+ */
180
+ static isInfinityLike(value) {
181
+ const check = this.isInfinity(value);
182
+ if (check) return check;
183
+ if (typeof value === "string") return [
184
+ "infinity",
185
+ "-infinity",
186
+ "+infinity",
187
+ "Infinity",
188
+ "-Infinity",
189
+ "+Infinity"
190
+ ].includes(value.trim());
191
+ return false;
192
+ }
193
+ /**
194
+ * 检查 value 是否为 Boolean
195
+ * @param value 待检查值
196
+ * @returns 是否为 Boolean
197
+ * @example
198
+ * ```ts
199
+ * TypeUtil.isBoolean(false); // true
200
+ * ```
201
+ */
202
+ static isBoolean(value) {
203
+ return typeof value === "boolean";
204
+ }
205
+ /**
206
+ * 检查 value 是否为 BigInt
207
+ * @param value 待检查值
208
+ * @returns 是否为 BigInt
209
+ * @example
210
+ * ```ts
211
+ * TypeUtil.isBigInt(1n); // true
212
+ * ```
213
+ */
214
+ static isBigInt(value) {
215
+ return typeof value === "bigint";
216
+ }
217
+ /**
218
+ * 检查 value 是否为 Symbol
219
+ * @param value 待检查值
220
+ * @returns 是否为 Symbol
221
+ * @example
222
+ * ```ts
223
+ * TypeUtil.isSymbol(Symbol("a")); // true
224
+ * ```
225
+ */
226
+ static isSymbol(value) {
227
+ return typeof value === "symbol";
228
+ }
229
+ /**
230
+ * 检查 value 是否为 undefined
231
+ * @param value 待检查值
232
+ * @returns 是否为 undefined
233
+ * @example
234
+ * ```ts
235
+ * TypeUtil.isUndefined(undefined); // true
236
+ * ```
237
+ */
238
+ static isUndefined(value) {
239
+ return typeof value === "undefined";
240
+ }
241
+ /**
242
+ * 检查 value 是否为 null
243
+ * @param value 待检查值
244
+ * @returns 是否为 null
245
+ * @example
246
+ * ```ts
247
+ * TypeUtil.isNull(null); // true
248
+ * ```
249
+ */
250
+ static isNull(value) {
251
+ return value === null;
252
+ }
253
+ /**
254
+ * 检查 value 是否为 Function
255
+ * @param value 待检查值
256
+ * @returns 是否为 Function
257
+ * @example
258
+ * ```ts
259
+ * TypeUtil.isFunction(() => {}); // true
260
+ * ```
261
+ */
262
+ static isFunction(value) {
263
+ return typeof value === "function";
264
+ }
265
+ /**
266
+ * 检查 value 是否为 AsyncFunction
267
+ * @param value 待检查值
268
+ * @returns 是否为 AsyncFunction
269
+ * @example
270
+ * ```ts
271
+ * TypeUtil.isAsyncFunction(async () => {}); // true
272
+ * ```
273
+ */
274
+ static isAsyncFunction(value) {
275
+ return this.isFunction(value) && this.getPrototypeString(value) === this.PROTOTYPE_TAGS.ASYNC_FUNCTION;
276
+ }
277
+ /**
278
+ * 检查 value 是否为 GeneratorFunction
279
+ * @param value 待检查值
280
+ * @returns 是否为 GeneratorFunction
281
+ * @example
282
+ * ```ts
283
+ * TypeUtil.isGeneratorFunction(function * a () {}); // true
284
+ * ```
285
+ */
286
+ static isGeneratorFunction(value) {
287
+ return this.isFunction(value) && this.getPrototypeString(value) === this.PROTOTYPE_TAGS.GENERATOR_FUNCTION;
288
+ }
289
+ /**
290
+ * 检查 value 是否为 AsyncGeneratorFunction
291
+ * @param value 待检查值
292
+ * @returns 是否为 AsyncGeneratorFunction
293
+ * @example
294
+ * ```ts
295
+ * TypeUtil.isAsyncGeneratorFunction(async function * a () {}); // true
296
+ * ```
297
+ */
298
+ static isAsyncGeneratorFunction(value) {
299
+ return this.isFunction(value) && this.getPrototypeString(value) === this.PROTOTYPE_TAGS.ASYNC_GENERATOR_FUNCTION;
300
+ }
301
+ /**
302
+ * 检查 value 是否为 Promise
303
+ * @param value 待检查值
304
+ * @returns 是否为 Promise
305
+ * @example
306
+ * ```ts
307
+ * TypeUtil.isPromise(Promise.resolve(1)); // true
308
+ * ```
309
+ */
310
+ static isPromise(value) {
311
+ return this.getPrototypeString(value) === this.PROTOTYPE_TAGS.PROMISE;
312
+ }
313
+ /**
314
+ * 检查 value 是否为 PromiseLike
315
+ * - 可识别拥有 then 方法的非 Promise 对象
316
+ * @param value 待检查值
317
+ * @returns 是否为 PromiseLike
318
+ * @example
319
+ * ```ts
320
+ * TypeUtil.isPromiseLike({ then: () => {} }); // true
321
+ * ```
322
+ */
323
+ static isPromiseLike(value) {
324
+ return this.isPromise(value) || this.isObject(value, false) && this.isFunction(value["then"]);
325
+ }
326
+ /**
327
+ * 判断是否为普通对象类型
328
+ * - 可选是否检查原型为 `Object.prototype`,防止原型链污染
329
+ *
330
+ * @param value 待检查值
331
+ * @param prototypeCheck 是否进行原型检查,默认 `true`
332
+ * @returns 是否为 Plain Object (当 checkPrototype=true) 或 object
333
+ * @example
334
+ * ```ts
335
+ * TypeUtil.isObject({}); // true
336
+ * TypeUtil.isObject([]); // false
337
+ * TypeUtil.isObject(new Date()); // false
338
+ * TypeUtil.isObject(new Date(), false); // true
339
+ * TypeUtil.isObject(Object.create(null)) // false
340
+ * TypeUtil.isObject(Object.create(null), false) // true
341
+ * ```
342
+ */
343
+ static isObject(value, prototypeCheck = true) {
344
+ const check = this.getPrototypeString(value) === this.PROTOTYPE_TAGS.OBJECT;
345
+ return prototypeCheck ? check && Object.getPrototypeOf(value) === Object.prototype : check;
346
+ }
347
+ /**
348
+ * 判断一个对象是否为有效的枚举
349
+ * - 枚举成员不能为空
350
+ * - 枚举成员的键不能具有数值名
351
+ * - 枚举成员的值必须类型一致且为 `string` 或 `number` 类型
352
+ * - 枚举成员的值不能重复
353
+ * - 枚举成员的值必须全部为双向映射或非双向映射
354
+ *
355
+ * @param enumeration 待检查值
356
+ * @returns [是否为有效的枚举, 是否为双向枚举]
357
+ * @example
358
+ * ```ts
359
+ * enum A { X, Y }
360
+ * TypeUtil.isEnumeration(A); // [true, true]
361
+ * ```
362
+ */
363
+ static isEnumeration(enumeration) {
364
+ if (typeof enumeration !== "object" || enumeration === null) return [false, false];
365
+ const keys = Object.keys(enumeration);
366
+ if (keys.length === 0) return [false, false];
367
+ const originalKeys = [];
368
+ const numericKeys = [];
369
+ for (const key of keys) if (/^\d+$/.test(key)) numericKeys.push(key);
370
+ else originalKeys.push(key);
371
+ if (originalKeys.length === 0) return [false, false];
372
+ let valueType = null;
373
+ const values = [];
374
+ for (const key of originalKeys) {
375
+ const value = enumeration[key];
376
+ const type = typeof value;
377
+ if (type !== "string" && type !== "number") return [false, false];
378
+ if (valueType === null) valueType = type;
379
+ else if (type !== valueType) return [false, false];
380
+ values.push(value);
381
+ }
382
+ if (new Set(values).size !== values.length) return [false, false];
383
+ let isBidirectional = false;
384
+ if (numericKeys.length > 0) {
385
+ if (numericKeys.length !== originalKeys.length) return [false, false];
386
+ const reverseMappedNames = /* @__PURE__ */ new Set();
387
+ for (const numKey of numericKeys) {
388
+ const reverseValue = enumeration[numKey];
389
+ if (typeof reverseValue !== "string") return [false, false];
390
+ if (!originalKeys.includes(reverseValue)) return [false, false];
391
+ reverseMappedNames.add(reverseValue);
392
+ }
393
+ if (reverseMappedNames.size !== originalKeys.length) return [false, false];
394
+ isBidirectional = true;
395
+ }
396
+ return [true, isBidirectional];
397
+ }
398
+ /**
399
+ * 检查 value 是否为 Class
400
+ *
401
+ * @param value 待检查值
402
+ * @returns 是否为 Class
403
+ * @example
404
+ * ```ts
405
+ * class A {}
406
+ * TypeUtil.isClass(A); // true
407
+ * TypeUtil.isClass(() => {}); // false
408
+ * ```
409
+ */
410
+ static isClass(value) {
411
+ return this.isFunction(value) && !this.isAsyncFunction(value) && Function.prototype.toString.call(value).startsWith("class ") && this.isConstructable(value) && value.prototype !== void 0;
412
+ }
413
+ /**
414
+ * 检查 value 是否为数组
415
+ *
416
+ * @param value 待检查值
417
+ * @returns 是否为数组
418
+ * @example
419
+ * ```ts
420
+ * TypeUtil.isArray([]); // true
421
+ * ```
422
+ */
423
+ static isArray(value) {
424
+ return Array.isArray(value);
425
+ }
426
+ /**
427
+ * 检查 value 是否为 TypedArray
428
+ *
429
+ * @param value 待检查值
430
+ * @returns 是否为 TypedArray
431
+ * @example
432
+ * ```ts
433
+ * TypeUtil.isTypedArray(new Int8Array()); // true
434
+ * ```
435
+ */
436
+ static isTypedArray(value) {
437
+ return typeof value === "object" && value !== null && this.TYPED_ARRAY_TAGS.has(this.getPrototypeString(value));
438
+ }
439
+ /**
440
+ * 检查 value 是否为 Map
441
+ * @param value 待检查值
442
+ * @returns 是否为 Map
443
+ * @example
444
+ * ```ts
445
+ * TypeUtil.isMap(new Map()); // true
446
+ * ```
447
+ */
448
+ static isMap(value) {
449
+ return this.getPrototypeString(value) === this.PROTOTYPE_TAGS.MAP;
450
+ }
451
+ /**
452
+ * 检查 value 是否为 WeakMap
453
+ * @param value 待检查值
454
+ * @returns 是否为 WeakMap
455
+ * @example
456
+ * ```ts
457
+ * TypeUtil.isWeakMap(new WeakMap()); // true
458
+ * ```
459
+ */
460
+ static isWeakMap(value) {
461
+ return this.getPrototypeString(value) === this.PROTOTYPE_TAGS.WEAK_MAP;
462
+ }
463
+ /**
464
+ * 检查 value 是否为 Set
465
+ * @param value 待检查值
466
+ * @returns 是否为 Set
467
+ * @example
468
+ * ```ts
469
+ * TypeUtil.isSet(new Set()); // true
470
+ * ```
471
+ */
472
+ static isSet(value) {
473
+ return this.getPrototypeString(value) === this.PROTOTYPE_TAGS.SET;
474
+ }
475
+ /**
476
+ * 检查 value 是否为 WeakSet
477
+ * @param value 待检查值
478
+ * @returns 是否为 WeakSet
479
+ * @example
480
+ * ```ts
481
+ * TypeUtil.isWeakSet(new WeakSet()); // true
482
+ * ```
483
+ */
484
+ static isWeakSet(value) {
485
+ return this.getPrototypeString(value) === this.PROTOTYPE_TAGS.WEAK_SET;
486
+ }
487
+ /**
488
+ * 检查 value 是否为 Blob
489
+ * @param value 待检查值
490
+ * @returns 是否为 Blob
491
+ * @example
492
+ * ```ts
493
+ * TypeUtil.isBlob(new Blob(["a"])); // true
494
+ * ```
495
+ */
496
+ static isBlob(value) {
497
+ return this.getPrototypeString(value) === this.PROTOTYPE_TAGS.BLOB;
498
+ }
499
+ /**
500
+ * 检查 value 是否为 File
501
+ * @param value 待检查值
502
+ * @returns 是否为 File
503
+ * @example
504
+ * ```ts
505
+ * TypeUtil.isFile(new File(["a"], "a.txt")); // true
506
+ * ```
507
+ */
508
+ static isFile(value) {
509
+ return this.getPrototypeString(value) === this.PROTOTYPE_TAGS.FILE;
510
+ }
511
+ /**
512
+ * 检查 value 是否为 ReadableStream
513
+ * - Uses `Object.prototype.toString` where supported (modern browsers, Node.js ≥18).
514
+ * - Falls back to duck-typing in older environments.
515
+ * - Resistant to basic forgery, but not 100% secure in all polyfill scenarios.
516
+ * - ⚠️ Note: In older Node.js (<18) or with non-compliant polyfills, this may return false positives or negatives.
517
+ *
518
+ * @param value 待检查值
519
+ * @returns 是否为 ReadableStream
520
+ * @example
521
+ * ```ts
522
+ * TypeUtil.isReadableStream(new ReadableStream()); // true
523
+ * ```
524
+ */
525
+ static isReadableStream(value) {
526
+ if (this.getPrototypeString(value) === this.PROTOTYPE_TAGS.READABLE_STREAM) return true;
527
+ return this.isObject(value) && this.isFunction(value["getReader"]) && this.isFunction(value["pipeThrough"]);
528
+ }
529
+ /**
530
+ * 检查 value 是否为 Window
531
+ * @param value 待检查值
532
+ * @returns 是否为 Window
533
+ * @example
534
+ * ```ts
535
+ * TypeUtil.isWindow(window); // true
536
+ * ```
537
+ */
538
+ static isWindow(value) {
539
+ return this.getPrototypeString(value) === this.PROTOTYPE_TAGS.WINDOW;
540
+ }
541
+ /**
542
+ * 检查 value 是否为 HTMLIFrameElement
543
+ * @param value 待检查值
544
+ * @returns 是否为 HTMLIFrameElement
545
+ * @example
546
+ * ```ts
547
+ * TypeUtil.isIframe(document.createElement("iframe")); // true
548
+ * ```
549
+ */
550
+ static isIframe(value) {
551
+ if (typeof window === "undefined") return false;
552
+ return this.getPrototypeString(value) === this.PROTOTYPE_TAGS.IFRAME;
553
+ }
554
+ /**
555
+ * 检查 value 是否为 Date 对象
556
+ *
557
+ * @param value 待检查值
558
+ * @param invalidCheck 是否要求日期有效(非 Invalid Date)。默认 true
559
+ * - true: 仅当是有效 Date 对象时返回 true(排除 new Date('invalid'))
560
+ * - false: 只要 [[Prototype]] 是 Date 即返回 true(包含 Invalid Date)
561
+ * @returns 是否为 Date 对象,根据 invalidCheck 返回不同语义的 Date 判定
562
+ *
563
+ * @example
564
+ * ```ts
565
+ * TypeUtil.isDate(new Date()); // true
566
+ * TypeUtil.isDate(new Date('invalid')); // false
567
+ * TypeUtil.isDate(new Date('invalid'), false); // true
568
+ * TypeUtil.isDate(null); // false
569
+ * TypeUtil.isDate({}); // false
570
+ * ```
571
+ */
572
+ static isDate(value, invalidCheck = true) {
573
+ if (!value || typeof value !== "object") return false;
574
+ if (this.getPrototypeString(value) !== this.PROTOTYPE_TAGS.DATE) return false;
575
+ if (!invalidCheck) return true;
576
+ try {
577
+ const time = value.getTime();
578
+ return typeof time === "number" && !Number.isNaN(time);
579
+ } catch {
580
+ return false;
581
+ }
582
+ }
583
+ /**
584
+ * 检查 value 是否为 Error 对象
585
+ * @param value 待检查值
586
+ * @returns 是否为 Error
587
+ * @example
588
+ * ```ts
589
+ * TypeUtil.isError(new Error("x")); // true
590
+ * ```
591
+ */
592
+ static isError(value) {
593
+ return value instanceof Error || this.getPrototypeString(value) === this.PROTOTYPE_TAGS.ERROR;
594
+ }
595
+ /**
596
+ * 检查 value 是否为 RegExp
597
+ * @param value 待检查值
598
+ * @returns 是否为 RegExp
599
+ * @example
600
+ * ```ts
601
+ * TypeUtil.isRegExp(/a/); // true
602
+ * ```
603
+ */
604
+ static isRegExp(value) {
605
+ if (typeof value !== "object" || value === null) return false;
606
+ try {
607
+ const regex = value;
608
+ return this.getPrototypeString(value) === this.PROTOTYPE_TAGS.REG_EXP && this.isString(regex.source) && this.isString(regex.flags) && this.isBoolean(regex.global) && this.isFunction(regex.test);
609
+ } catch (error) {
610
+ return false;
611
+ }
612
+ }
613
+ /**
614
+ * 检查 value 是否为 WebSocket
615
+ * @param value 待检查值
616
+ * @returns 是否为 WebSocket
617
+ * @example
618
+ * ```ts
619
+ * TypeUtil.isWebSocket(new WebSocket("wss://echo.websocket.events")); // true
620
+ * ```
621
+ */
622
+ static isWebSocket(value) {
623
+ return this.getPrototypeString(value) === this.PROTOTYPE_TAGS.WEB_SOCKET;
624
+ }
625
+ /**
626
+ * 检查 value 是否为 URLSearchParams
627
+ * @param value 待检查值
628
+ * @returns 是否为 URLSearchParams
629
+ * @example
630
+ * ```ts
631
+ * TypeUtil.isURLSearchParams(new URLSearchParams("a=1")); // true
632
+ * ```
633
+ */
634
+ static isURLSearchParams(value) {
635
+ return this.getPrototypeString(value) === this.PROTOTYPE_TAGS.URL_SEARCH_PARAMS;
636
+ }
637
+ /**
638
+ * 检查 value 是否为 AbortSignal
639
+ * @param value 待检查值
640
+ * @returns 是否为 AbortSignal
641
+ * @example
642
+ * ```ts
643
+ * TypeUtil.isAbortSignal(new AbortController().signal); // true
644
+ * ```
645
+ */
646
+ static isAbortSignal(value) {
647
+ return this.getPrototypeString(value) === this.PROTOTYPE_TAGS.ABORT_SIGNAL;
648
+ }
649
+ /**
650
+ * 检查 value 是否为可迭代对象 (Iterable)
651
+ * @param value 待检查值
652
+ * @returns 是否为 Iterable
653
+ * @example
654
+ * ```ts
655
+ * TypeUtil.isIterable([1, 2]); // true
656
+ * ```
657
+ */
658
+ static isIterable(value) {
659
+ return !!value && typeof value[Symbol.iterator] === "function";
660
+ }
661
+ /**
662
+ * 检查 value 是否为 Falsy 值 (false, 0, "", null, undefined, NaN)
663
+ * @param value 待检查值
664
+ * @returns 是否为 Falsy
665
+ * @example
666
+ * ```ts
667
+ * TypeUtil.isFalsy(0); // true
668
+ * ```
669
+ */
670
+ static isFalsy(value) {
671
+ if (this.isNaN(value) || this.isNull(value) || this.isUndefined(value)) return true;
672
+ return value === false || value === 0 || value === 0n || value === "";
673
+ }
674
+ /**
675
+ * 检查 value 是否为 FalsyLike 值
676
+ * - 包含字符串形式的 `"null"`、`"undefined"`、`"false"`、`"0"` 等
677
+ *
678
+ * @param value 待检查值
679
+ * @returns 是否为 FalsyLike
680
+ * @example
681
+ * ```ts
682
+ * TypeUtil.isFalsyLike("false"); // true
683
+ * TypeUtil.isFalsyLike("hello"); // false
684
+ * ```
685
+ */
686
+ static isFalsyLike(value) {
687
+ if (this.isFalsy(value)) return true;
688
+ return typeof value === "string" && (value === "null" || value === "undefined" || value === "NaN" || value === "false" || value === "0" || value === "-0" || value === "0n");
689
+ }
690
+ };
691
+ _defineProperty(TypeUtil, "PROTOTYPE_TAGS", {
692
+ STRING: "[object String]",
693
+ NUMBER: "[object Number]",
694
+ BOOLEAN: "[object Boolean]",
695
+ BIGINT: "[object BigInt]",
696
+ SYMBOL: "[object Symbol]",
697
+ UNDEFINED: "[object Undefined]",
698
+ NULL: "[object Null]",
699
+ OBJECT: "[object Object]",
700
+ FUNCTION: "[object Function]",
701
+ GENERATOR_FUNCTION: "[object GeneratorFunction]",
702
+ ASYNC_FUNCTION: "[object AsyncFunction]",
703
+ ASYNC_GENERATOR_FUNCTION: "[object AsyncGeneratorFunction]",
704
+ PROMISE: "[object Promise]",
705
+ MAP: "[object Map]",
706
+ SET: "[object Set]",
707
+ WEAK_MAP: "[object WeakMap]",
708
+ WEAK_SET: "[object WeakSet]",
709
+ BLOB: "[object Blob]",
710
+ FILE: "[object File]",
711
+ READABLE_STREAM: "[object ReadableStream]",
712
+ GLOBAL: "[object global]",
713
+ WINDOW: "[object Window]",
714
+ IFRAME: "[object HTMLIFrameElement]",
715
+ DATE: "[object Date]",
716
+ ERROR: "[object Error]",
717
+ REG_EXP: "[object RegExp]",
718
+ WEB_SOCKET: "[object WebSocket]",
719
+ URL_SEARCH_PARAMS: "[object URLSearchParams]",
720
+ ABORT_SIGNAL: "[object AbortSignal]"
721
+ });
722
+ _defineProperty(TypeUtil, "TYPED_ARRAY_TAGS", new Set([
723
+ "[object Int8Array]",
724
+ "[object Uint8Array]",
725
+ "[object Uint8ClampedArray]",
726
+ "[object Int16Array]",
727
+ "[object Uint16Array]",
728
+ "[object Int32Array]",
729
+ "[object Uint32Array]",
730
+ "[object Float32Array]",
731
+ "[object Float64Array]",
732
+ "[object BigInt64Array]",
733
+ "[object BigUint64Array]"
734
+ ]));
735
+ //#endregion
736
+ //#region src/string/stringUtil.ts
737
+ /**
738
+ * 字符串工具类
739
+ */
740
+ var StringUtil = class {
741
+ /**
742
+ * 从字符串中提取数字字符串
743
+ * - 移除非数字字符,保留符号和小数点
744
+ *
745
+ * @param input 待处理字符串
746
+ * @returns 提取出的数字字符串
747
+ * @example
748
+ * ```ts
749
+ * StringUtil.toNumber("$1,234.56"); // "1234.56"
750
+ * StringUtil.toNumber("abc-123"); // "-123"
751
+ * ```
752
+ */
753
+ static toNumber(input) {
754
+ if (!TypeUtil.isString(input, true)) return "0";
755
+ const cleaned = input.replace(/[^0-9.-]/g, "");
756
+ if (!cleaned) return "0";
757
+ let isDecimal = false;
758
+ let signCount = 0;
759
+ let firstIndex = -1;
760
+ const stringList = cleaned.split("").map((s, i) => {
761
+ if (s === ".") {
762
+ if (isDecimal) return "";
763
+ isDecimal = true;
764
+ return ".";
765
+ }
766
+ if (s === "-") {
767
+ firstIndex === -1 && signCount++;
768
+ return "";
769
+ }
770
+ firstIndex === -1 && (firstIndex = i);
771
+ return s;
772
+ });
773
+ const sign = signCount % 2 === 1 ? "-" : "";
774
+ if (firstIndex === -1) return sign + "0";
775
+ let result = stringList.join("");
776
+ if (result.startsWith(".")) result = "0" + result;
777
+ if (result.endsWith(".")) result = result.slice(0, -1);
778
+ return sign + result;
779
+ }
780
+ static toLowerCase(input) {
781
+ if (!TypeUtil.isString(input, true)) return "";
782
+ return input.toLowerCase();
783
+ }
784
+ static toUpperCase(input) {
785
+ if (!TypeUtil.isString(input, true)) return "";
786
+ return input.toUpperCase();
787
+ }
788
+ /**
789
+ * 字符串首字母大小写
790
+ * - 包含非西欧字母字符时,不处理
791
+ * - 纯字母且全大写时,不处理
792
+ * - 纯字母且非全大写时,首字母小写,其余保留
793
+ * - 纯字母且非全大写时,首字母大写,其余保留
794
+ *
795
+ * @param input 待处理字符串
796
+ * @param caseType 大小写类型
797
+ * @returns 处理后的字符串
798
+ * @example
799
+ * ```ts
800
+ * StringUtil.toInitialCase("Hello", "lower"); // "hello"
801
+ * StringUtil.toInitialCase("hello", "upper"); // "Hello"
802
+ * ```
803
+ */
804
+ static toInitialCase(input, caseType) {
805
+ if (!TypeUtil.isString(input, true)) return "";
806
+ return input.replace(/\S+/g, (word) => {
807
+ if (/[^a-zA-Z\u00C0-\u017F]/.test(word)) return word;
808
+ if (word === word.toLocaleUpperCase()) return word;
809
+ if (caseType === "lower" && word[0]) return word[0].toLocaleLowerCase() + word.slice(1);
810
+ if (caseType === "upper" && word[0]) return word[0].toLocaleUpperCase() + word.slice(1);
811
+ return word;
812
+ });
813
+ }
814
+ /**
815
+ * 将路径转换为 POSIX 风格
816
+ * - 统一使用正斜杠 (/)
817
+ * - 可选移除 Windows 盘符 (如 C:)
818
+ * - 可选移除开头的斜杠
819
+ * - 规范化连续斜杠为单个斜杠
820
+ *
821
+ * @param input 待处理字符串
822
+ * @param removeLeadingSlash 是否移除开头斜杠,默认为 `false`。如果移除了盘符,路径通常会以 / 开头,此参数可控制是否保留该 /
823
+ * @returns 转换后的路径,如果输入无效则返回空字符串
824
+ *
825
+ * @example
826
+ * ```ts
827
+ * StringUtil.toPosix("C:\\Windows\\System32"); // 默认: "/Windows/System32" (移除了 C: 并标准化)
828
+ *
829
+ * StringUtil.toPosix("C:\\Windows\\System32", true); // 移除开头斜杠: "Windows/System32"
830
+ *
831
+ * StringUtil.toPosix("\\\\server\\share\\file.txt"); // UNC 路径: "/server/share/file.txt"
832
+ *
833
+ * StringUtil.toPosix("folder\\subfolder\\file.txt"); // 相对路径: "folder/subfolder/file.txt"
834
+ * ```
835
+ */
836
+ static toPosix(input, removeLeadingSlash = false) {
837
+ if (!TypeUtil.isString(input, true)) return "";
838
+ let normalized = input.replace(/^[A-Za-z]:([\\/])?/, (_, separator) => {
839
+ return separator ? "/" : "";
840
+ });
841
+ normalized = normalized.replace(/\\/g, "/");
842
+ normalized = normalized.replace(/\/+/g, "/");
843
+ if (removeLeadingSlash && normalized.startsWith("/")) normalized = normalized.substring(1);
844
+ return normalized;
845
+ }
846
+ static toJson(input, fallback) {
847
+ if (!TypeUtil.isString(input, true)) return fallback;
848
+ try {
849
+ return JSON.parse(input);
850
+ } catch (error) {
851
+ return fallback;
852
+ }
853
+ }
854
+ static toValues(input, valueType = "number", splitSymbol = ",") {
855
+ if (!TypeUtil.isString(input, true)) return [];
856
+ try {
857
+ const values = input.split(splitSymbol);
858
+ if (valueType === "number") return values.map((d) => Number(d));
859
+ return values;
860
+ } catch (error) {
861
+ return [];
862
+ }
863
+ }
864
+ /**
865
+ * 从字符串中裁切掉所有的前缀和后缀字符
866
+ *
867
+ * @param input 待处理字符串
868
+ * @param charsToTrim 裁切字符,默认为 `" "`
869
+ * @returns 裁切后的字符串
870
+ * @example
871
+ * ```ts
872
+ * StringUtil.trim(" hello "); // "hello"
873
+ * StringUtil.trim("__hello__", "_"); // "hello"
874
+ * ```
875
+ */
876
+ static trim(input, charsToTrim = " ") {
877
+ if (!TypeUtil.isString(input, true)) return "";
878
+ const toTrim = charsToTrim.replace(/[\W]{1}/g, "\\$&");
879
+ const regex = new RegExp(`^[${toTrim}]+|[${toTrim}]+$`, "g");
880
+ return input.replace(regex, "");
881
+ }
882
+ /**
883
+ * 截取字符串
884
+ * - 支持自定义省略符,不会截断在汉字中间(因为JS字符串本身按字符处理)
885
+ *
886
+ * @param input 待处理字符串
887
+ * @param maxLength 最大长度 (包含省略符)
888
+ * @param ellipsis 省略符,默认为 `...`
889
+ * @returns 截取后的字符串
890
+ * @example
891
+ * ```ts
892
+ * StringUtil.truncate("hello world", 8); // "hello..."
893
+ * ```
894
+ */
895
+ static truncate(input, maxLength, ellipsis = "...") {
896
+ if (!TypeUtil.isString(input, true)) return "";
897
+ const codePoints = Array.from(input);
898
+ if (!TypeUtil.isInteger(maxLength) || maxLength < 0) return input;
899
+ if (codePoints.length <= maxLength) return input;
900
+ const availableLength = maxLength - ellipsis.length;
901
+ if (availableLength <= 0) return "";
902
+ return codePoints.slice(0, availableLength).join("") + ellipsis;
903
+ }
904
+ /**
905
+ * 字符串模板替换
906
+ * - 使用对象的属性值替换字符串中的 {{key}} 模板
907
+ *
908
+ * @param input 待处理字符串
909
+ * @param template 模板对象
910
+ * @param regex 模板匹配正则 (默认: `\{\{(.+?)\}\}`)
911
+ * @returns 替换后的字符串
912
+ * @example
913
+ * ```ts
914
+ * StringUtil.template("Hello {{name}}", { name: "World" }); // "Hello World"
915
+ * ```
916
+ */
917
+ static template(input, template, regex = /\{\{(.+?)\}\}/g) {
918
+ if (!TypeUtil.isString(input, true)) return "";
919
+ regex.lastIndex = 0;
920
+ let result = "";
921
+ let from = 0;
922
+ let match;
923
+ while (match = regex.exec(input)) {
924
+ const replacement = template[match[1]];
925
+ const valueToInsert = replacement === null || replacement === void 0 ? match[0] : replacement;
926
+ result += input.slice(from, match.index) + valueToInsert;
927
+ from = regex.lastIndex;
928
+ }
929
+ return result + input.slice(from);
930
+ }
931
+ /**
932
+ * 字符串替换
933
+ * - 替换第一个匹配项
934
+ *
935
+ * @param input 待处理字符串
936
+ * @param search 匹配项
937
+ * @param replacement 替换项
938
+ * @returns 替换后的字符串
939
+ * @example
940
+ * ```ts
941
+ * StringUtil.replace("hello world", "world", "context"); // "hello context"
942
+ * ```
943
+ */
944
+ static replace(input, search, replacement) {
945
+ if (!TypeUtil.isString(input, true)) return "";
946
+ return input.replace(search, replacement);
947
+ }
948
+ };
949
+ //#endregion
950
+ export { TypeUtil as n, _defineProperty as r, StringUtil as t };