@pawover/kit 0.0.0-beta.5 → 0.0.0-beta.50

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