@pawover/kit 0.6.0 → 0.7.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 (121) hide show
  1. package/README.en.md +123 -0
  2. package/README.md +123 -1
  3. package/entry/eslint-rules.cjs +1 -0
  4. package/entry/eslint-rules.d.cts +1 -0
  5. package/entry/eslint-rules.d.ts +2 -0
  6. package/entry/eslint-rules.js +2 -0
  7. package/entry/hooks-alova.cjs +1 -0
  8. package/entry/hooks-alova.d.cts +1 -0
  9. package/entry/hooks-alova.d.ts +1 -0
  10. package/entry/hooks-alova.js +1 -0
  11. package/entry/hooks-react.cjs +1 -0
  12. package/entry/hooks-react.d.cts +1 -0
  13. package/entry/hooks-react.d.ts +1 -0
  14. package/entry/hooks-react.js +1 -0
  15. package/entry/index.cjs +1 -0
  16. package/entry/index.d.cts +1 -0
  17. package/entry/index.d.ts +1 -0
  18. package/entry/index.js +1 -0
  19. package/entry/math.cjs +1 -0
  20. package/entry/math.d.cts +1 -0
  21. package/entry/math.d.ts +1 -0
  22. package/entry/math.js +1 -0
  23. package/entry/types-react.cjs +1 -0
  24. package/entry/types-react.d.cts +1 -0
  25. package/entry/types-react.d.ts +1 -0
  26. package/entry/types-react.js +1 -0
  27. package/entry/types.cjs +1 -0
  28. package/entry/types.d.cts +1 -0
  29. package/entry/types.d.ts +1 -0
  30. package/entry/types.js +1 -0
  31. package/entry/vite.cjs +1 -0
  32. package/entry/vite.d.cts +1 -0
  33. package/entry/vite.d.ts +1 -0
  34. package/entry/vite.js +1 -0
  35. package/entry/zod.cjs +1 -0
  36. package/entry/zod.d.cts +1 -0
  37. package/entry/zod.d.ts +1 -0
  38. package/entry/zod.js +1 -0
  39. package/package.json +72 -96
  40. package/packages/eslint-rules/dist/core.antfu.cjs +0 -78
  41. package/packages/eslint-rules/dist/core.antfu.d.cts +0 -1
  42. package/packages/eslint-rules/dist/core.antfu.d.ts +0 -74
  43. package/packages/eslint-rules/dist/core.antfu.js +0 -79
  44. package/packages/eslint-rules/dist/core.imports.cjs +0 -59
  45. package/packages/eslint-rules/dist/core.imports.d.cts +0 -1
  46. package/packages/eslint-rules/dist/core.imports.d.ts +0 -61
  47. package/packages/eslint-rules/dist/core.imports.js +0 -59
  48. package/packages/eslint-rules/dist/core.importsSort.cjs +0 -7
  49. package/packages/eslint-rules/dist/core.importsSort.d.cts +0 -1
  50. package/packages/eslint-rules/dist/core.importsSort.d.ts +0 -7
  51. package/packages/eslint-rules/dist/core.importsSort.js +0 -7
  52. package/packages/eslint-rules/dist/core.javascript.cjs +0 -1208
  53. package/packages/eslint-rules/dist/core.javascript.d.cts +0 -1
  54. package/packages/eslint-rules/dist/core.javascript.d.ts +0 -1216
  55. package/packages/eslint-rules/dist/core.javascript.js +0 -1208
  56. package/packages/eslint-rules/dist/core.react.cjs +0 -551
  57. package/packages/eslint-rules/dist/core.react.d.cts +0 -1
  58. package/packages/eslint-rules/dist/core.react.d.ts +0 -551
  59. package/packages/eslint-rules/dist/core.react.js +0 -551
  60. package/packages/eslint-rules/dist/core.reactHooks.cjs +0 -107
  61. package/packages/eslint-rules/dist/core.reactHooks.d.cts +0 -1
  62. package/packages/eslint-rules/dist/core.reactHooks.d.ts +0 -107
  63. package/packages/eslint-rules/dist/core.reactHooks.js +0 -107
  64. package/packages/eslint-rules/dist/core.stylistic.cjs +0 -608
  65. package/packages/eslint-rules/dist/core.stylistic.d.cts +0 -1
  66. package/packages/eslint-rules/dist/core.stylistic.d.ts +0 -595
  67. package/packages/eslint-rules/dist/core.stylistic.js +0 -608
  68. package/packages/eslint-rules/dist/core.typescript.cjs +0 -905
  69. package/packages/eslint-rules/dist/core.typescript.d.cts +0 -1
  70. package/packages/eslint-rules/dist/core.typescript.d.ts +0 -917
  71. package/packages/eslint-rules/dist/core.typescript.js +0 -906
  72. package/packages/eslint-rules/dist/core.vue.cjs +0 -312
  73. package/packages/eslint-rules/dist/core.vue.d.cts +0 -1
  74. package/packages/eslint-rules/dist/core.vue.d.ts +0 -293
  75. package/packages/eslint-rules/dist/core.vue.js +0 -313
  76. package/packages/eslint-rules/dist/index.cjs +0 -126
  77. package/packages/eslint-rules/dist/index.d.cts +0 -1
  78. package/packages/eslint-rules/dist/index.d.ts +0 -113
  79. package/packages/eslint-rules/dist/index.js +0 -126
  80. package/packages/eslint-rules/dist/preset-Bk6lxNP0.cjs +0 -107
  81. package/packages/eslint-rules/dist/preset-CQJST7pW.js +0 -102
  82. package/packages/hooks/dist/alova.cjs +0 -53
  83. package/packages/hooks/dist/alova.d.cts +0 -1
  84. package/packages/hooks/dist/alova.d.ts +0 -33
  85. package/packages/hooks/dist/alova.js +0 -50
  86. package/packages/hooks/dist/index.cjs +0 -0
  87. package/packages/hooks/dist/index.d.cts +0 -1
  88. package/packages/hooks/dist/index.d.ts +0 -1
  89. package/packages/hooks/dist/index.js +0 -0
  90. package/packages/hooks/dist/react.cjs +0 -169
  91. package/packages/hooks/dist/react.d.cts +0 -1
  92. package/packages/hooks/dist/react.d.ts +0 -95
  93. package/packages/hooks/dist/react.js +0 -163
  94. package/packages/types/dist/index.cjs +0 -0
  95. package/packages/types/dist/index.d.cts +0 -1
  96. package/packages/types/dist/index.d.ts +0 -271
  97. package/packages/types/dist/index.js +0 -0
  98. package/packages/types/dist/react.cjs +0 -0
  99. package/packages/types/dist/react.d.cts +0 -1
  100. package/packages/types/dist/react.d.ts +0 -64
  101. package/packages/types/dist/react.js +0 -0
  102. package/packages/utils/dist/index.cjs +0 -2300
  103. package/packages/utils/dist/index.d.cts +0 -1
  104. package/packages/utils/dist/index.d.ts +0 -2740
  105. package/packages/utils/dist/index.js +0 -2287
  106. package/packages/utils/dist/math-BznvO4qI.cjs +0 -1029
  107. package/packages/utils/dist/math-DRbCtLQH.js +0 -1012
  108. package/packages/utils/dist/math.cjs +0 -3
  109. package/packages/utils/dist/math.d.cts +0 -1
  110. package/packages/utils/dist/math.d.ts +0 -60
  111. package/packages/utils/dist/math.js +0 -2
  112. package/packages/utils/dist/vite.cjs +0 -44
  113. package/packages/utils/dist/vite.d.cts +0 -1
  114. package/packages/utils/dist/vite.d.ts +0 -28
  115. package/packages/utils/dist/vite.js +0 -43
  116. package/packages/zod/dist/index.cjs +0 -91
  117. package/packages/zod/dist/index.d.cts +0 -1
  118. package/packages/zod/dist/index.d.ts +0 -57
  119. package/packages/zod/dist/index.js +0 -61
  120. /package/{packages/hooks/dist/metadata.json → entry/hooks-metadata.json} +0 -0
  121. /package/{packages/utils/dist → entry}/metadata.json +0 -0
@@ -1,2740 +0,0 @@
1
- import { MathJsInstance } from "mathjs";
2
- import { Except, If, IsAny, Replace, Simplify, Split, Trim, TupleOf, TypedArray, UnionToIntersection, UnionToTuple, ValueOf } from "type-fest";
3
- import { AnyAsyncFunction, AnyAsyncGeneratorFunction, AnyFunction, AnyGeneratorFunction, AnyObject, PlainObject, TreeLike, TreeLikeOptionalChildren } from "@pawover/kit-types";
4
- import { Any, List } from "ts-toolbelt";
5
- import { AnyObject as AnyObject$1 } from "@pawover/types";
6
- //#region src/array/index.type.d.ts
7
- type MatchFunction<T, R = unknown> = (row: T, index: number) => R;
8
- /**
9
- * `ArrayUtil.zip` / `ArrayUtil.unzip` 的配置项
10
- * - `truncate`: 为 `true` 时按最短数组截断
11
- */
12
- interface ZipOptions {
13
- truncate?: boolean | undefined;
14
- }
15
- //#endregion
16
- //#region src/array/arrayUtil.d.ts
17
- /**
18
- * 数组工具类
19
- */
20
- declare class ArrayUtil {
21
- /**
22
- * 构造数组
23
- * @param candidate 待构造项
24
- * @param checkNullish 是否检查 `undefined` 和 `null`,默认为 `true`
25
- * @returns 构造后的数组
26
- * @example
27
- * ```ts
28
- * // 重载 1: checkNullish = true (默认)
29
- * ArrayUtil.cast(1); // [1]
30
- * ArrayUtil.cast(null); // []
31
- *
32
- * // 重载 2: checkNullish = false
33
- * ArrayUtil.cast(null, false); // [null]
34
- *
35
- * // 通用场景
36
- * ArrayUtil.cast([1, 2]); // [1, 2]
37
- * ArrayUtil.cast(undefined); // []
38
- * ```
39
- */
40
- static cast<T>(candidate: T | T[] | null | undefined, checkNullish?: true): NonNullable<T>[];
41
- static cast<T>(candidate: T | T[] | null | undefined, checkNullish: false): T[];
42
- /**
43
- * 获取数组第一项
44
- *
45
- * @param initialList 初始数组
46
- * @param fallback 回退值
47
- * @returns 数组第一项,如果为空则返回回退值
48
- * @example
49
- * ```ts
50
- * // 重载 1: 无 fallback
51
- * ArrayUtil.first([1, 2]); // 1
52
- * ArrayUtil.first([]); // undefined
53
- *
54
- * // 重载 2: 有 fallback
55
- * ArrayUtil.first([], 0); // 0
56
- * ```
57
- */
58
- static first<T>(initialList: readonly T[]): T | undefined;
59
- static first<T>(initialList: readonly T[], fallback: T): T;
60
- /**
61
- * 获取数组最后一项
62
- *
63
- * @param initialList 初始数组
64
- * @param fallback 回退值
65
- * @returns 数组最后一项,如果为空则返回回退值
66
- * @example
67
- * ```ts
68
- * // 重载 1: 无 fallback
69
- * ArrayUtil.last([1, 2, 3]); // 3
70
- * ArrayUtil.last([]); // undefined
71
- *
72
- * // 重载 2: 有 fallback
73
- * ArrayUtil.last([], 0); // 0
74
- * ```
75
- */
76
- static last<T>(initialList: readonly T[]): T | undefined;
77
- static last<T>(initialList: readonly T[], fallback: T): T;
78
- /**
79
- * 数组竞选
80
- * - 返回在匹配函数的比较条件中获胜的最终项目,适用于更复杂的最小值/最大值计算
81
- *
82
- * @param initialList 数组
83
- * @param match 匹配函数
84
- * @returns 获胜的元素,如果数组为空或参数无效则返回 `null`
85
- * @example
86
- * ```ts
87
- * const list = [1, 10, 5];
88
- * ArrayUtil.compete(list, (a, b) => (a > b ? a : b)); // 10
89
- * ArrayUtil.compete(list, (a, b) => (a < b ? a : b)); // 1
90
- * ```
91
- */
92
- static compete<T>(initialList: readonly T[], match: (a: T, b: T, index: number) => T): T | null;
93
- /**
94
- * 统计数组的项目出现次数
95
- * - 通过给定的标识符匹配函数,返回一个对象,其中键是回调函数返回的 key 值,每个值是一个整数,表示该 key 出现的次数
96
- *
97
- * @param initialList 初始数组
98
- * @param match 匹配函数
99
- * @returns 统计对象
100
- * @example
101
- * ```ts
102
- * const list = ["a", "b", "a", "c"];
103
- * ArrayUtil.count(list, (x) => x); // { a: 2, b: 1, c: 1 }
104
- *
105
- * const users = [{ id: 1, group: "A" }, { id: 2, group: "B" }, { id: 3, group: "A" }];
106
- * ArrayUtil.count(users, (u) => u.group); // { A: 2, B: 1 }
107
- * ```
108
- */
109
- static count<T, K extends PropertyKey>(initialList: readonly T[], match: MatchFunction<T, K>): Record<string, number>;
110
- /**
111
- * 获取数组差集
112
- * - 返回在 `initialList` 中存在,但在 `diffList` 中不存在的元素
113
- *
114
- * @param initialList 初始数组
115
- * @param diffList 对比数组
116
- * @param match 匹配函数
117
- * @returns 差集数组
118
- * @example
119
- * ```ts
120
- * // 重载 1: 按元素本身比较(自动去重)
121
- * ArrayUtil.difference([1, 2, 3], [2, 3, 4]); // [1]
122
- * ArrayUtil.difference([1, 1, 2], [2]); // [1],重复项会被去重
123
- *
124
- * // 重载 2: 按 match 结果比较(不去重,保留 initialList 原始重复项与顺序)
125
- * ArrayUtil.difference([{ id: 1 }, { id: 2 }], [{ id: 2 }], (x) => x.id); // [{ id: 1 }]
126
- * ArrayUtil.difference([{ id: 1 }, { id: 1 }], [{ id: 2 }], (x) => x.id); // [{ id: 1 }, { id: 1 }]
127
- * ```
128
- */
129
- static difference<T>(initialList: readonly T[], diffList: readonly T[], match?: (row: T, index: number) => unknown): T[];
130
- /**
131
- * 获取数组交集
132
- * - 返回在 `initialList` 和 `diffList` 中都存在的元素
133
- *
134
- * @param initialList 初始数组
135
- * @param diffList 对比数组
136
- * @param match 匹配函数
137
- * @returns 交集数组
138
- * @example
139
- * ```ts
140
- * // 重载 1: 按元素本身比较
141
- * ArrayUtil.intersection([1, 2], [2, 3]); // [2]
142
- *
143
- * // 重载 2: 按 match 结果比较
144
- * ArrayUtil.intersection([{ id: 1 }, { id: 2 }], [{ id: 2 }], (x) => x.id); // [{ id: 2 }]
145
- * ```
146
- */
147
- static intersection<T>(initialList: readonly T[], diffList: readonly T[]): T[];
148
- static intersection<T, D = T>(initialList: readonly T[], diffList: readonly D[], match: MatchFunction<T>): T[];
149
- /**
150
- * 数组合并
151
- * - 如果未提供 `match` 函数,则合并两个数组并去重(Union)
152
- * - 如果提供了 `match` 函数,则仅更新 `initialList` 中匹配到的项(Left Join Update),不会追加 `mergeList` 中新增的项
153
- *
154
- * @param initialList 初始数组
155
- * @param mergeList 待合并数组
156
- * @param match 匹配函数
157
- * @returns 合并后的数组
158
- * @example
159
- * ```ts
160
- * // 重载 1: 基础合并去重
161
- * ArrayUtil.merge([1, 2], [2, 3]); // [1, 2, 3]
162
- * ArrayUtil.merge([], [1, 2, 3]); // [1, 2, 3]
163
- *
164
- * // 重载 2: 按条件更新
165
- * const source = [{ id: 1, val: "a" }, { id: 2, val: "b" }];
166
- * const update = [{ id: 2, val: "new" }, { id: 3, val: "c" }];
167
- * ArrayUtil.merge(source, update, (x) => x.id); // [{ id: 1, val: "a" }, { id: 2, val: "new" }] -> id:3 被忽略
168
- * ```
169
- */
170
- static merge<T>(initialList: readonly T[], mergeList: readonly T[]): T[];
171
- static merge<T, D = T>(initialList: readonly T[], mergeList: readonly D[], match: MatchFunction<T>): (T | D)[];
172
- /**
173
- * 数组选择
174
- * - 一次性应用 `filter` 和 `map` 操作
175
- *
176
- * @param initialList 初始数组
177
- * @param filter filter 函数
178
- * @param mapper map 函数
179
- * @returns 处理后的新数组
180
- * @example
181
- * ```ts
182
- * const list = [1, 2, 3, 4];
183
- *
184
- * // 重载 1: 仅过滤
185
- * ArrayUtil.pick(list, (n) => n % 2 === 0); // [2, 4]
186
- *
187
- * // 重载 2: 过滤 + 映射
188
- * ArrayUtil.pick(list, (n) => n % 2 === 0, (n) => n * 2); // [4, 8]
189
- * ```
190
- */
191
- static pick<const T>(initialList: readonly T[], filter: (row: T, index: number) => boolean): T[];
192
- static pick<const T, K = T>(initialList: readonly T[], filter: (row: T, index: number) => boolean, mapper: (row: T, index: number) => K): K[];
193
- /**
194
- * 数组项替换
195
- * - 在给定的数组中,替换符合匹配函数结果的项目
196
- * - 只替换第一个匹配项
197
- *
198
- * @param initialList 初始数组
199
- * @param newItem 替换项
200
- * @param match 匹配函数
201
- * @returns 替换后的新数组
202
- * @example
203
- * ```ts
204
- * // 重载 1/2: newItem 与数组元素类型兼容
205
- * ArrayUtil.replace([1, 2, 3], 4, (n) => n === 2); // [1, 4, 3]
206
- *
207
- * // 重载 3: newItem 可扩展为新类型
208
- * ArrayUtil.replace([1, 2, 3], "X", (n) => n === 2); // [1, "X", 3]
209
- * ```
210
- */
211
- static replace<const T>(initialList: readonly T[], newItem: T, match: MatchFunction<T, boolean>): T[];
212
- static replace<const T, K extends T>(initialList: readonly T[], newItem: K, match: MatchFunction<T, boolean>): T[];
213
- static replace<const T, K>(initialList: readonly T[], newItem: K, match: MatchFunction<T, boolean>): (T | K)[];
214
- /**
215
- * 数组项替换并移动
216
- * - 在给定的数组中,替换并移动符合匹配函数结果的项目
217
- * - 只替换和移动第一个匹配项
218
- * - 未匹配时,根据 `position` 在指定位置插入 `newItem`
219
- * - ⚠️ `position` 为负数或非正整数(如 `-1`、`2.5`)时不生效,静默回退为 `push`(追加到末尾)
220
- *
221
- * @param initialList 初始数组
222
- * @param newItem 替换项
223
- * @param match 匹配函数
224
- * @param position 移动位置,可选 `start` | `end` | 索引位置, 默认为 `end`
225
- * @returns
226
- * @example
227
- * ```ts
228
- * ArrayUtil.replaceMove([1, 2, 3, 4], 5, (n) => n === 2, 0); // [5, 1, 3, 4]
229
- * ArrayUtil.replaceMove([1, 2, 3, 4], 5, (n) => n === 2, 2); // [1, 3, 5, 4]
230
- * ArrayUtil.replaceMove([1, 2, 3, 4], 5, (n) => n === 2, "start"); // [5, 1, 3, 4]
231
- * ArrayUtil.replaceMove([1, 2, 3, 4], 5, (n) => n === 2); // [1, 3, 4, 5]
232
- *
233
- * // position 为负数 → 静默回退为 push
234
- * ArrayUtil.replaceMove([1, 2, 3, 4], 5, (n) => n === 2, -1); // [1, 3, 4, 5]
235
- * ```
236
- */
237
- static replaceMove<const T>(initialList: readonly T[], newItem: T, match: MatchFunction<T, boolean>, position?: "start" | "end" | number): T[];
238
- /**
239
- * 数组切分
240
- * - 将数组以指定的长度切分后,组合在高维数组中
241
- *
242
- * @param initialList 初始数组
243
- * @param size 分割尺寸,默认 `10`
244
- * @returns 切分后的二维数组
245
- * @example
246
- * ```ts
247
- * ArrayUtil.split([1, 2, 3, 4, 5], 2); // [[1, 2], [3, 4], [5]]
248
- * ```
249
- */
250
- static split<T>(initialList: readonly T[], size?: number): T[][];
251
- /**
252
- * 数组分组过滤
253
- * - 给定一个数组和一个条件,返回一个由两个数组组成的元组,其中第一个数组包含所有满足条件的项,第二个数组包含所有不满足条件的项
254
- *
255
- * @param initialList 初始数组
256
- * @param match 条件匹配函数
257
- * @returns [满足条件的项[], 不满足条件的项[]]
258
- * @example
259
- * ```ts
260
- * ArrayUtil.fork([1, 2, 3, 4], (n) => n % 2 === 0); // [[2, 4], [1, 3]]
261
- * ```
262
- */
263
- static fork<T>(initialList: readonly T[], match: MatchFunction<T, boolean>): [T[], T[]];
264
- /**
265
- * 数组解压
266
- * - `ArrayUtil.zip` 的反向操作
267
- * - 默认按最长数组补齐 `undefined`
268
- *
269
- * @param arrayList 压缩后的数组
270
- * @param options 配置项(`truncate` 为 `true` 时按最短数组截断)
271
- * @returns 解压后的二维数组
272
- * @example
273
- * ```ts
274
- * ArrayUtil.unzip([[1, "a"], [2, "b"]]); // [[1, 2], ["a", "b"]]
275
- *
276
- * // 补齐语义
277
- * ArrayUtil.unzip([[1, 2], [3]]); // [[1, 3], [2, undefined]]
278
- *
279
- * // 截断语义
280
- * ArrayUtil.unzip([[1, 2], [3]], { truncate: true }); // [[1, 3]]
281
- * ```
282
- */
283
- static unzip<T>(arrayList: readonly (readonly T[])[], options?: ZipOptions): T[][];
284
- /**
285
- * 数组压缩
286
- * - 将多个数组的元素按索引组合成元组
287
- * - 默认按最长数组补齐 `undefined`
288
- *
289
- * @param arrays 多个数组
290
- * @param options 配置项(`truncate` 为 `true` 时按最短数组截断)
291
- * @returns 压缩后的元组数组
292
- * @example
293
- * ```ts
294
- * // 重载 1: 两个数组
295
- * ArrayUtil.zip([1, 2], ["a", "b"]); // [[1, "a"], [2, "b"]]
296
- * // 长度不一致时默认补齐 undefined
297
- * ArrayUtil.zip([1, 2, 3], ["a"]); // [[1, "a"], [2, undefined], [3, undefined]]
298
- *
299
- * // 重载 2: 三个数组
300
- * ArrayUtil.zip([1, 2], ["a", "b"], [true, false]); // [[1, "a", true], [2, "b", false]]
301
- *
302
- * // 重载 3: 四个数组
303
- * ArrayUtil.zip([1], ["a"], [true], ["x"]); // [[1, "a", true, "x"]]
304
- *
305
- * // 重载 4: 五个数组
306
- * ArrayUtil.zip([1], ["a"], [true], ["x"], [9]); // [[1, "a", true, "x", 9]]
307
- *
308
- * // 重载 5: 空参数
309
- * ArrayUtil.zip(); // []
310
- *
311
- * // 重载 6: 两个数组 + options(truncate: true 截断到最短数组)
312
- * ArrayUtil.zip([1, 2, 3], ["a"], { truncate: true }); // [[1, "a"]]
313
- *
314
- * // 重载 7: 三个数组 + options
315
- * ArrayUtil.zip([1, 2], ["a"], [true], { truncate: true }); // [[1, "a", true]]
316
- *
317
- * // 重载 8: 四个数组 + options
318
- * ArrayUtil.zip([1], ["a"], [true], ["x"], { truncate: true }); // [[1, "a", true, "x"]]
319
- *
320
- * // 重载 9: 五个数组 + options
321
- * ArrayUtil.zip([1], ["a"], [true], ["x"], [9], { truncate: true }); // [[1, "a", true, "x", 9]]
322
- * ```
323
- */
324
- static zip<T1, T2, T3, T4, T5>(array1: readonly T1[], array2: readonly T2[], array3: readonly T3[], array4: readonly T4[], array5: readonly T5[], options: ZipOptions): [T1, T2, T3, T4, T5][];
325
- static zip<T1, T2, T3, T4>(array1: readonly T1[], array2: readonly T2[], array3: readonly T3[], array4: readonly T4[], options: ZipOptions): [T1, T2, T3, T4][];
326
- static zip<T1, T2, T3>(array1: readonly T1[], array2: readonly T2[], array3: readonly T3[], options: ZipOptions): [T1, T2, T3][];
327
- static zip<T1, T2>(array1: readonly T1[], array2: readonly T2[], options: ZipOptions): [T1, T2][];
328
- static zip<T1, T2, T3, T4, T5>(array1: readonly T1[], array2: readonly T2[], array3: readonly T3[], array4: readonly T4[], array5: readonly T5[]): [T1, T2, T3, T4, T5][];
329
- static zip<T1, T2, T3, T4>(array1: readonly T1[], array2: readonly T2[], array3: readonly T3[], array4: readonly T4[]): [T1, T2, T3, T4][];
330
- static zip<T1, T2, T3>(array1: readonly T1[], array2: readonly T2[], array3: readonly T3[]): [T1, T2, T3][];
331
- static zip<T1, T2>(array1: readonly T1[], array2: readonly T2[]): [T1, T2][];
332
- static zip(): [];
333
- /**
334
- * 数组压缩为对象
335
- * - 将键数组和值(数组、函数或静态值)组合成对象
336
- *
337
- * @param keys 键数组
338
- * @param values 值数组、生成值的函数或静态值
339
- * @returns 生成的对象
340
- * @example
341
- * ```ts
342
- * // 重载 1: 传值数组
343
- * ArrayUtil.zipToObject(["a", "b"], [1, 2]); // { a: 1, b: 2 }
344
- *
345
- * // 重载 2: 传生成函数
346
- * ArrayUtil.zipToObject(["a", "b"], (k, i) => k + i); // { a: "a0", b: "b1" }
347
- *
348
- * // 重载 3: 传静态值
349
- * ArrayUtil.zipToObject(["a", "b"], 1); // { a: 1, b: 1 }
350
- * ```
351
- */
352
- static zipToObject<const K extends PropertyKey, const V>(keys: readonly K[], array: readonly V[]): Record<K, V>;
353
- static zipToObject<const K extends PropertyKey, const V>(keys: readonly K[], match: MatchFunction<K, V>): Record<K, V>;
354
- static zipToObject<const K extends PropertyKey, const V>(keys: readonly K[], value: V): Record<K, V>;
355
- }
356
- //#endregion
357
- //#region src/currency/index.type.d.ts
358
- type CurrencyCode = keyof typeof CurrencyUtil.CURRENCY_ENUM;
359
- type CurrencyLocale = ValueOf<typeof CurrencyUtil.CURRENCY_ENUM>;
360
- interface FormatterOptions {
361
- locales: [CurrencyLocale, CurrencyLocale];
362
- currencySign: string;
363
- currencySignPosition: "start" | "end";
364
- currencyFormatOptions: Intl.NumberFormatOptions;
365
- }
366
- //#endregion
367
- //#region src/currency/currencyUtil.d.ts
368
- /**
369
- * 货币工具类
370
- * - 基于 [`Intl.NumberFormat`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat) 进行本地化格式化
371
- * - 支持精确小数位处理(依赖 `mathjs`)
372
- */
373
- declare class CurrencyUtil {
374
- /**
375
- * 货币代码到 Locale 的映射枚举
376
- * - 键为 ISO 4217 货币代码,值为 BCP 47 语言标签
377
- * - 用于 `Intl.NumberFormat` 的本地化数字格式化
378
- * - 格式示例基于 `Intl.NumberFormat` 对 `1,234,567.89` 的输出
379
- *
380
- * @example
381
- * ```ts
382
- * import { CurrencyUtil } from "@pawover/kit/utils";
383
- * // 获取人民币的格式化 locale
384
- * const locale = CurrencyUtil.CURRENCY_ENUM.CNY; // "zh-CN"
385
- *
386
- * // 结合 Intl.NumberFormat 使用
387
- * new Intl.NumberFormat(CurrencyUtil.CURRENCY_ENUM.USD, {
388
- * style: "currency",
389
- * currency: "USD",
390
- * }).format(1234.56); // "$1,234.56"
391
- * ```
392
- */
393
- static readonly CURRENCY_ENUM: {
394
- /** 美元(美国及美元化国家,Locale: 美式英语) → 1,234,567.89 */
395
- readonly USD: "en-US";
396
- /** 加拿大元(加拿大,Locale: 加拿大英语) → 1,234,567.89 */
397
- readonly CAD: "en-CA";
398
- /** 墨西哥比索(墨西哥,Locale: 墨西哥西班牙语) → 1,234,567.89 */
399
- readonly MXN: "es-MX";
400
- /** 巴西雷亚尔(巴西,Locale: 巴西葡萄牙语) → 1.234.567,89 */
401
- readonly BRL: "pt-BR";
402
- /** 阿根廷比索(阿根廷,Locale: 阿根廷西班牙语) → 1.234.567,89 */
403
- readonly ARS: "es-AR";
404
- /** 智利比索(智利,Locale: 智利西班牙语) → 1.234.567,89 */
405
- readonly CLP: "es-CL";
406
- /** 秘鲁新索尔(秘鲁,Locale: 秘鲁西班牙语) → 1,234,567.89 */
407
- readonly PEN: "es-PE";
408
- /** 哥伦比亚比索(哥伦比亚,Locale: 哥伦比亚西班牙语) → 1.234.567,89 */
409
- readonly COP: "es-CO";
410
- /** 哥斯达黎加科朗(哥斯达黎加,Locale: 哥斯达黎加西班牙语) → 1 234 567,89(空格千分位) */
411
- readonly CRC: "es-CR";
412
- /** 人民币(中国,Locale: 简体中文) → 1,234,567.89 */
413
- readonly CNY: "zh-CN";
414
- /** 港元(中国香港,Locale: 繁体中文+香港) → 1,234,567.89 */
415
- readonly HKD: "zh-HK";
416
- /** 澳门元(中国澳门,Locale: 繁体中文+澳门) → 1,234,567.89 */
417
- readonly MOP: "zh-MO";
418
- /** 日元(日本,Locale: 日语) → 1,234,567.89 */
419
- readonly JPY: "ja-JP";
420
- /** 韩元(韩国,Locale: 韩语) → 1,234,567.89 */
421
- readonly KRW: "ko-KR";
422
- /** 新加坡元(新加坡,Locale: 英语+新加坡) → 1,234,567.89 */
423
- readonly SGD: "en-SG";
424
- /** 泰铢(泰国,Locale: 泰语) → 1,234,567.89 */
425
- readonly THB: "th-TH";
426
- /** 印度卢比(印度,Locale: 英语+印度) → 12,34,567.89(2,2,3 分组) */
427
- readonly INR: "en-IN";
428
- /** 沙特里亚尔(沙特,Locale: 阿拉伯语+沙特) → ١٬٢٣٤٬٥٦٧٫٨٩(阿拉伯数字) */
429
- readonly SAR: "ar-SA";
430
- /** 阿联酋迪拉姆(阿联酋,Locale: 阿拉伯语+阿联酋) → 1,234,567.89 */
431
- readonly AED: "ar-AE";
432
- /** 印尼盾(印尼,Locale: 印尼语) → 1.234.567,89 */
433
- readonly IDR: "id-ID";
434
- /** 马来西亚林吉特(马来西亚,Locale: 马来语) → 1,234,567.89 */
435
- readonly MYR: "ms-MY";
436
- /** 越南盾(越南,Locale: 越南语) → 1.234.567,89 */
437
- readonly VND: "vi-VN";
438
- /** 菲律宾比索(菲律宾,Locale: 英语+菲律宾) → 1,234,567.89 */
439
- readonly PHP: "en-PH";
440
- /** 巴基斯坦卢比(巴基斯坦,Locale: 英语+巴基斯坦) → 1,234,567.89 */
441
- readonly PKR: "en-PK";
442
- /** 新台币(中国台湾地区,Locale: 繁体中文+台湾) → 1,234,567.89 */
443
- readonly TWD: "zh-TW";
444
- /** 欧元(德国,Locale: 德语+德国,代表欧元区) → 1.234.567,89 */
445
- readonly EUR: "de-DE";
446
- /** 英镑(英国,Locale: 英式英语) → 1,234,567.89 */
447
- readonly GBP: "en-GB";
448
- /** 瑞士法郎(瑞士,Locale: 德语+瑞士) → 1'234'567.89 */
449
- readonly CHF: "de-CH";
450
- /** 瑞典克朗(瑞典,Locale: 瑞典语) → 1 234 567,89(空格千分位) */
451
- readonly SEK: "sv-SE";
452
- /** 挪威克朗(挪威,Locale: 挪威语) → 1 234 567,89(空格千分位) */
453
- readonly NOK: "no-NO";
454
- /** 丹麦克朗(丹麦,Locale: 丹麦语) → 1.234.567,89 */
455
- readonly DKK: "da-DK";
456
- /** 波兰兹罗提(波兰,Locale: 波兰语) → 1 234 567,89(空格千分位) */
457
- readonly PLN: "pl-PL";
458
- /** 捷克克朗(捷克,Locale: 捷克语) → 1 234 567,89(空格千分位) */
459
- readonly CZK: "cs-CZ";
460
- /** 匈牙利福林(匈牙利,Locale: 匈牙利语) → 1 234 567,89(空格千分位) */
461
- readonly HUF: "hu-HU";
462
- /** 俄罗斯卢布(俄罗斯,Locale: 俄语) → 1 234 567,89(空格千分位) */
463
- readonly RUB: "ru-RU";
464
- /** 罗马尼亚列伊(罗马尼亚,Locale: 罗马尼亚语) → 1.234.567,89 */
465
- readonly RON: "ro-RO";
466
- /** 乌克兰格里夫纳(乌克兰,Locale: 乌克兰语) → 1 234 567,89(空格千分位) */
467
- readonly UAH: "uk-UA";
468
- /** 澳大利亚元(澳大利亚,Locale: 澳大利亚英语) → 1,234,567.89 */
469
- readonly AUD: "en-AU";
470
- /** 新西兰元(新西兰,Locale: 新西兰英语) → 1,234,567.89 */
471
- readonly NZD: "en-NZ";
472
- /** 南非兰特(南非,Locale: 英语+南非) → 1 234 567,89(空格千分位) */
473
- readonly ZAR: "en-ZA";
474
- /** 埃及镑(埃及,Locale: 阿拉伯语+埃及) → ١٬٢٣٤٬٥٦٧٫٨٩(阿拉伯数字) */
475
- readonly EGP: "ar-EG";
476
- /** 土耳其里拉(土耳其,Locale: 土耳其语) → 1.234.567,89 */
477
- readonly TRY: "tr-TR";
478
- /** 以色列新谢克尔(以色列,Locale: 希伯来语) → 1,234,567.89 */
479
- readonly ILS: "he-IL";
480
- /** 摩洛哥迪拉姆(摩洛哥,Locale: 阿拉伯语+摩洛哥) → 1.234.567,89 */
481
- readonly MAD: "ar-MA";
482
- /** 科威特第纳尔(科威特,Locale: 阿拉伯语+科威特) → ١٬٢٣٤٬٥٦٧٫٨٩(阿拉伯数字) */
483
- readonly KWD: "ar-KW";
484
- /** 卡塔尔里亚尔(卡塔尔,Locale: 阿拉伯语+卡塔尔) → ١٬٢٣٤٬٥٦٧٫٨٩(阿拉伯数字) */
485
- readonly QAR: "ar-QA";
486
- /** 尼日利亚奈拉(尼日利亚,Locale: 英语+尼日利亚) → 1,234,567.89 */
487
- readonly NGN: "en-NG";
488
- /** 太平洋法郎(法属波利尼西亚,Locale: 法语+太平洋) → 1[U+202F]234[U+202F]567,89(窄空格千分位) */
489
- readonly XPF: "fr-PF";
490
- };
491
- /**
492
- * 货币格式化
493
- * - 使用 `Intl.NumberFormat` 进行本地化数字格式化
494
- * - 支持自定义货币符号及位置(首/尾)
495
- * - 当值为 `null` 或 `undefined` 时返回 `null`
496
- *
497
- * @param value 待格式化的数值
498
- * @param options 格式化选项
499
- * @param options.locales locale 元组,同时指定格式化语言和货币所属地区
500
- * @param options.currencySign 货币符号(如 `¥`、`$`、`€`)
501
- * @param options.currencySignPosition 货币符号位置
502
- * @param options.currencyFormatOptions `Intl.NumberFormatOptions` 格式化选项
503
- * @returns 格式化后的货币字符串,无效输入返回 `null`
504
- *
505
- * @example
506
- * ```ts
507
- * import { CurrencyUtil } from "@pawover/kit/utils";
508
- *
509
- * // 重载 1: 有效数值
510
- * CurrencyUtil.currencyFormatter(1234.56, {
511
- * locales: [CurrencyUtil.CURRENCY_ENUM.CNY, CurrencyUtil.CURRENCY_ENUM.USD],
512
- * currencySign: "¥",
513
- * currencySignPosition: "start",
514
- * currencyFormatOptions: { style: "currency", currency: "CNY" },
515
- * }); // "¥ 1,234.56"
516
- *
517
- * // 重载 2: null / undefined
518
- * CurrencyUtil.currencyFormatter(null, options); // null
519
- * CurrencyUtil.currencyFormatter(undefined, options); // null
520
- * ```
521
- */
522
- static currencyFormatter(value: string | number, options: FormatterOptions): string | null;
523
- static currencyFormatter(value: string | number | null | undefined, options: FormatterOptions): string | null;
524
- /**
525
- * 将任意数值转换为精确的十进制值
526
- * - 基于 `mathjs` 的 `bignumber` 处理,避免浮点数精度问题
527
- * - 当值为 `null` 或 `undefined` 时返回 `null`
528
- *
529
- * @param mathJsInstance `mathjs` 实例
530
- * @param value 待转换的数值
531
- * @param precision 小数精度位数
532
- * @param stringMode 是否返回字符串类型,默认 `true`
533
- * @returns 精确的十进制值,无效输入返回 `null`
534
- *
535
- * @example
536
- * ```ts
537
- * import { create, all } from "mathjs";
538
- * import { CurrencyUtil } from "@pawover/kit/utils";
539
- *
540
- * const math = create(all);
541
- *
542
- * // 重载 1: 有效值 + stringMode = true(默认)
543
- * CurrencyUtil.toRealValue(math, "0.1"); // "0.1"
544
- * CurrencyUtil.toRealValue(math, 0.1 + 0.2, 2); // "0.30"
545
- *
546
- * // 重载 2: stringMode = false → number
547
- * CurrencyUtil.toRealValue(math, "0.1", undefined, false); // 0.1
548
- *
549
- * // 重载 3: null / undefined(含 stringMode 显式组合)
550
- * CurrencyUtil.toRealValue(math, null); // null
551
- * CurrencyUtil.toRealValue(math, undefined); // null
552
- * CurrencyUtil.toRealValue(math, null, 2, true); // null
553
- * CurrencyUtil.toRealValue(math, null, 2, false); // null
554
- * ```
555
- */
556
- static toRealValue(mathJsInstance: MathJsInstance, value: string | number, precision: number | undefined, stringMode: true): string;
557
- static toRealValue(mathJsInstance: MathJsInstance, value: string | number, precision: number | undefined, stringMode: false): number;
558
- static toRealValue(mathJsInstance: MathJsInstance, value: string | number, precision?: number | undefined): string;
559
- static toRealValue(mathJsInstance: MathJsInstance, value: string | number | null | undefined, precision: number | undefined, stringMode: true): string | null;
560
- static toRealValue(mathJsInstance: MathJsInstance, value: string | number | null | undefined, precision: number | undefined, stringMode: false): number | null;
561
- static toRealValue(mathJsInstance: MathJsInstance, value: string | number | null | undefined, precision?: number | undefined): string | null;
562
- }
563
- //#endregion
564
- //#region src/dateTime/dateTimeUtil.d.ts
565
- /**
566
- * 日期工具类
567
- */
568
- declare class DateTimeUtil {
569
- /**
570
- * 每秒的毫秒数
571
- * @example
572
- * ```ts
573
- * DateTimeUtil.MILLISECONDS_PER_SECOND; // 1000
574
- * ```
575
- */
576
- static readonly MILLISECONDS_PER_SECOND: number;
577
- /**
578
- * 每分钟的秒数
579
- * @example
580
- * ```ts
581
- * DateTimeUtil.SECOND_PER_MINUTE; // 60
582
- * ```
583
- */
584
- static readonly SECOND_PER_MINUTE: number;
585
- /**
586
- * 每小时的分钟数
587
- * @example
588
- * ```ts
589
- * DateTimeUtil.MINUTE_PER_HOUR; // 60
590
- * ```
591
- */
592
- static readonly MINUTE_PER_HOUR: number;
593
- /**
594
- * 每小时的秒数
595
- * @example
596
- * ```ts
597
- * DateTimeUtil.SECOND_PER_HOUR; // 3600
598
- * ```
599
- */
600
- static readonly SECOND_PER_HOUR: number;
601
- /**
602
- * 每天小时数
603
- * @example
604
- * ```ts
605
- * DateTimeUtil.HOUR_PER_DAY; // 24
606
- * ```
607
- */
608
- static readonly HOUR_PER_DAY: number;
609
- /**
610
- * 每天秒数
611
- * @example
612
- * ```ts
613
- * DateTimeUtil.SECOND_PER_DAY; // 86400
614
- * ```
615
- */
616
- static readonly SECOND_PER_DAY: number;
617
- /**
618
- * 每周天数
619
- * @example
620
- * ```ts
621
- * DateTimeUtil.DAY_PER_WEEK; // 7
622
- * ```
623
- */
624
- static readonly DAY_PER_WEEK: number;
625
- /**
626
- * 每月天数
627
- * @example
628
- * ```ts
629
- * DateTimeUtil.DAY_PER_MONTH; // 30
630
- * ```
631
- */
632
- static readonly DAY_PER_MONTH: number;
633
- /**
634
- * 每年天数
635
- * @example
636
- * ```ts
637
- * DateTimeUtil.DAY_PER_YEAR; // 365
638
- * ```
639
- */
640
- static readonly DAY_PER_YEAR: number;
641
- /**
642
- * 每年月数
643
- * @example
644
- * ```ts
645
- * DateTimeUtil.MONTH_PER_YEAR; // 12
646
- * ```
647
- */
648
- static readonly MONTH_PER_YEAR: number;
649
- /**
650
- * 每年平均周
651
- * @example
652
- * ```ts
653
- * DateTimeUtil.WEEK_PER_YEAR; // 52
654
- * ```
655
- */
656
- static readonly WEEK_PER_YEAR: number;
657
- /**
658
- * 每月平均周
659
- * @example
660
- * ```ts
661
- * DateTimeUtil.WEEK_PER_MONTH; // 4
662
- * ```
663
- */
664
- static readonly WEEK_PER_MONTH: number;
665
- /**
666
- * 常用时间格式模板集合
667
- *
668
- * @example
669
- * ```ts
670
- * DateTimeUtil.FORMAT.ISO_DATE; // "yyyy-MM-dd"
671
- * DateTimeUtil.FORMAT.CN_DATE_TIME; // "yyyy年MM月dd日 HH时mm分ss秒"
672
- * ```
673
- */
674
- static readonly FORMAT: {
675
- readonly ISO_DATE: "yyyy-MM-dd";
676
- readonly ISO_TIME: "HH:mm:ss";
677
- readonly ISO_DATE_TIME: "yyyy-MM-dd HH:mm:ss";
678
- readonly ISO_DATE_TIME_MS: "yyyy-MM-dd HH:mm:ss.SSS";
679
- readonly ISO_DATETIME_TZ: "yyyy-MM-dd'T'HH:mm:ssXXX";
680
- readonly ISO_DATETIME_TZ_MS: "yyyy-MM-dd'T'HH:mm:ss.SSSXXX";
681
- readonly US_DATE: "MM/dd/yyyy";
682
- readonly US_DATE_TIME: "MM/dd/yyyy HH:mm:ss";
683
- readonly US_DATE_SHORT_YEAR: "MM/dd/yy";
684
- readonly EU_DATE: "dd/MM/yyyy";
685
- readonly EU_DATE_TIME: "dd/MM/yyyy HH:mm:ss";
686
- readonly CN_DATE: "yyyy年MM月dd日";
687
- readonly CN_DATE_TIME: "yyyy年MM月dd日 HH时mm分ss秒";
688
- readonly CN_DATE_WEEKDAY: "yyyy年MM月dd日 EEE";
689
- readonly CN_WEEKDAY_FULL: "EEEE";
690
- readonly SHORT_DATE: "yy-MM-dd";
691
- readonly SHORT_DATE_SLASH: "yy/MM/dd";
692
- readonly MONTH_DAY: "MM-dd";
693
- readonly MONTH_DAY_CN: "MM月dd日";
694
- readonly DATE_WITH_WEEKDAY_SHORT: "yyyy-MM-dd (EEE)";
695
- readonly DATE_WITH_WEEKDAY_FULL: "yyyy-MM-dd (EEEE)";
696
- readonly TIME_24: "HH:mm:ss";
697
- readonly TIME_24_NO_SEC: "HH:mm";
698
- readonly TIME_12: "hh:mm:ss a";
699
- readonly TIME_12_NO_SEC: "hh:mm a";
700
- readonly TIMESTAMP: "yyyyMMddHHmmss";
701
- readonly TIMESTAMP_MS: "yyyyMMddHHmmssSSS";
702
- readonly RFC2822: "EEE, dd MMM yyyy HH:mm:ss xxx";
703
- readonly READABLE_DATE: "MMM dd, yyyy";
704
- readonly READABLE_DATE_TIME: "MMM dd, yyyy HH:mm";
705
- readonly COMPACT_DATETIME: "yyyyMMdd_HHmmss";
706
- };
707
- /**
708
- * 获取当前时区信息
709
- *
710
- * @returns 时区信息对象 (UTC偏移和时区名称)
711
- * @example
712
- * ```ts
713
- * DateTimeUtil.getTimeZone(); // { UTC: "UTC+8", timeZone: "Asia/Shanghai" }
714
- * ```
715
- */
716
- static getTimeZone(): {
717
- UTC: string;
718
- timeZone: string;
719
- };
720
- }
721
- //#endregion
722
- //#region src/env/envUtil.d.ts
723
- /**
724
- * 环境检查工具类
725
- * - ⚠️ `isBrowser` / `isWebWorker` / `isReactNative` 基于静态字段判定,在**模块加载时**求值一次。
726
- * SSR 场景下若在 Node 端 import(此时 `window` 未定义),结果会永久为 `false`,不会随运行时环境变化重算。
727
- */
728
- declare class EnvUtil {
729
- private static readonly _isBrowser;
730
- private static readonly _isWebWorker;
731
- private static readonly _isReactNative;
732
- /**
733
- * 检测是否处于浏览器环境
734
- *
735
- * @returns 是否为浏览器环境
736
- * @example
737
- * ```ts
738
- * EnvUtil.isBrowser(); // true: 浏览器, false: Node.js
739
- * ```
740
- */
741
- static isBrowser(): boolean;
742
- /**
743
- * 检测是否处于 Web Worker 环境
744
- *
745
- * @returns 是否为 Web Worker 环境
746
- * @example
747
- * ```ts
748
- * EnvUtil.isWebWorker(); // true: Worker, false: 主线程/Node.js
749
- * ```
750
- */
751
- static isWebWorker(): boolean;
752
- /**
753
- * 检测是否处于 React Native 环境
754
- *
755
- * @returns 是否为 React Native 环境
756
- * @example
757
- * ```ts
758
- * EnvUtil.isReactNative(); // true: React Native, false: Web/Node.js
759
- * ```
760
- */
761
- static isReactNative(): boolean;
762
- /**
763
- * 检查是否在 iframe 环境中
764
- *
765
- * @returns 是否在 iframe 中
766
- * @example
767
- * ```ts
768
- * EnvUtil.isIframe(); // true: 当前页面在 iframe 中
769
- * ```
770
- */
771
- static isIframe(): boolean;
772
- /**
773
- * 检测当前设备是否为桌面设备
774
- *
775
- * @param minWidth - 桌面设备最小宽度(默认 1200px)
776
- * @param minScreenSize - 桌面设备最小屏幕尺寸(默认 10英寸)
777
- * @param dpi - 标准 DPI 基准(默认 160)
778
- * @returns 是否为桌面设备
779
- * @example
780
- * ```ts
781
- * // 假设 window.innerWidth = 1920
782
- * EnvUtil.isDesktop(); // true
783
- *
784
- * // 自定义阈值
785
- * EnvUtil.isDesktop(1440, 13); // 更严格的桌面检测
786
- * ```
787
- */
788
- static isDesktop(minWidth?: number, minScreenSize?: number, dpi?: number): boolean;
789
- /**
790
- * 检测当前设备是否为 Windows 桌面设备
791
- *
792
- * @param minWidth - 桌面设备最小宽度(默认 1200px)
793
- * @param minScreenSize - 桌面设备最小屏幕尺寸(默认 10英寸)
794
- * @param dpi - 标准 DPI 基准(默认 160)
795
- * @returns 是否为 Windows 桌面设备
796
- * @example
797
- * ```ts
798
- * // UA contains Windows
799
- * EnvUtil.isWindowsDesktop(); // true
800
- * ```
801
- */
802
- static isWindowsDesktop(minWidth?: number, minScreenSize?: number, dpi?: number): boolean;
803
- /**
804
- * 检测当前设备是否为 macOS 桌面设备
805
- *
806
- * @param minWidth - 桌面设备最小宽度(默认 1200px)
807
- * @param minScreenSize - 桌面设备最小屏幕尺寸(默认 10英寸)
808
- * @param dpi - 标准 DPI 基准(默认 160)
809
- * @returns 是否为 macOS 桌面设备
810
- * @example
811
- * ```ts
812
- * // UA contains Macintosh
813
- * EnvUtil.isMacOSDesktop(); // true
814
- * ```
815
- */
816
- static isMacOSDesktop(minWidth?: number, minScreenSize?: number, dpi?: number): boolean;
817
- /**
818
- * 检测当前设备是否为移动设备
819
- *
820
- * @param maxWidth - 移动设备最大宽度(默认 768px)
821
- * @param dpi - 标准 DPI 基准(默认 160)
822
- * @returns 是否为移动设备
823
- * @example
824
- * ```ts
825
- * // 假设 window.innerWidth = 500
826
- * EnvUtil.isMobile(); // true
827
- * ```
828
- */
829
- static isMobile(maxWidth?: number, dpi?: number): boolean;
830
- /**
831
- * 检测当前设备是否为IOS移动设备
832
- *
833
- * @param maxWidth - 移动设备最大宽度(默认 768px)
834
- * @param dpi - 标准 DPI 基准(默认 160)
835
- * @returns 是否为 iOS 移动设备 (iPhone/iPod)
836
- * @example
837
- * ```ts
838
- * // UA contains iPhone
839
- * EnvUtil.isIOSMobile(); // true
840
- * ```
841
- */
842
- static isIOSMobile(maxWidth?: number, dpi?: number): boolean;
843
- /**
844
- * 检测当前设备是否为平板
845
- *
846
- * @param minWidth - 平板最小宽度(默认 768px)
847
- * @param maxWidth - 平板最大宽度(默认 1200px)
848
- * @param dpi - 标准 DPI 基准(默认 160)
849
- * @returns 是否为平板设备
850
- * - 宽度命中 `[minWidth, maxWidth]` 区间,或 CSS/DPI 折算尺寸落在 `[7, 13)` 英寸(排除 DPR=1 的 1920×1080 桌面)
851
- * @example
852
- * ```ts
853
- * // 假设 window.innerWidth = 1000
854
- * EnvUtil.isTablet(); // true
855
- * ```
856
- */
857
- static isTablet(minWidth?: number, maxWidth?: number, dpi?: number): boolean;
858
- }
859
- //#endregion
860
- //#region src/function/functionUtil.d.ts
861
- /**
862
- * 函数工具类
863
- */
864
- declare class FunctionUtil {
865
- /**
866
- *将 Promise 转换为 `[err, result]` 格式,方便 async/await 错误处理
867
- *
868
- * @param promise 待处理的 Promise
869
- * @param errorExt 附加到 error 对象的扩展信息(注意:如果原 error 是 Error 实例,扩展属性可能会覆盖或无法正确合并非枚举属性)
870
- * @returns `[err, null]` 或 `[null, data]`
871
- * @example
872
- * ```ts
873
- * const [err, data] = await FunctionUtil.to(someAsyncFunc());
874
- * ```
875
- */
876
- static to<T, U = Error>(promise: Readonly<Promise<T>>, errorExt?: PlainObject): Promise<[U, undefined] | [null, T]>;
877
- /**
878
- * 将 Arguments 对象转换为数组
879
- *
880
- * ⚠️ 注意:TypeScript 官方推荐使用 rest parameters (...args) 替代 arguments
881
- * 本函数仅用于处理遗留代码或特殊场景(如装饰器中需保留 this 绑定)
882
- *
883
- * @param args Arguments 对象(必须为类数组对象)
884
- * @param start 起始索引(可选,默认为 0)
885
- * @returns 转换后的数组,元素类型为 T
886
- *
887
- * @throws TypeError 如果 args 为 null 或 undefined
888
- *
889
- * @example
890
- * ```ts
891
- * // 遗留代码场景
892
- * function legacyFn(a: number, b: string) {
893
- * const argsArray = FunctionUtil.toArgs(arguments);
894
- * // argsArray: unknown[]
895
- * }
896
- *
897
- * // 现代替代方案(推荐)
898
- * function modernFn(a: number, b: string, ...rest: unknown[]) {
899
- * // rest 已经是数组,无需 toArgs
900
- * }
901
- *
902
- * // 参数截取
903
- * function skipFirst(...args: unknown[]) {
904
- * const rest = FunctionUtil.toArgs(arguments, 1);
905
- * // rest: unknown[],跳过第一个参数
906
- * }
907
- * ```
908
- */
909
- static toArgs<T = unknown>(args: IArguments, start?: number | undefined): T[];
910
- /**
911
- * 将同步或异步函数统一包装为 Promise
912
- * - 自动捕获同步异常
913
- *
914
- * @param fn 返回值可为同步值或 Promise 的函数
915
- * @returns 标准化的 Promise
916
- *
917
- * @example
918
- * ```ts
919
- * // 同步函数
920
- * FunctionUtil.toPromise(() => 42).then(v => console.log(v)); // 42
921
- *
922
- * // 异步函数
923
- * FunctionUtil.toPromise(async () => await fetchData()).then(data => ...);
924
- *
925
- * // 异常处理
926
- * FunctionUtil.toPromise(() => { throw new Error('fail'); }).catch(err => console.error(err)); // 捕获同步异常
927
- * ```
928
- */
929
- static toPromise<T>(fn: () => T | Promise<T>): Promise<T>;
930
- }
931
- //#endregion
932
- //#region src/mime/mimeUtil.d.ts
933
- /**
934
- * MIME 工具类
935
- */
936
- declare class MimeUtil {
937
- /**
938
- * 文件类型 MIME 常量
939
- * - 每个类型对应具体的文件扩展名
940
- */
941
- static readonly FILE_MIME: {
942
- /** 普通文本文件(.txt) */
943
- readonly TEXT: "text/plain";
944
- /** 超文本标记语言文档(.html/.htm) */
945
- readonly HTML: "text/html";
946
- /** 层叠样式表文件(.css) */
947
- readonly CSS: "text/css";
948
- /** 逗号分隔值文件/表格数据(.csv) */
949
- readonly CSV: "text/csv";
950
- /** 制表符分隔值文件(.tsv) */
951
- readonly TSV: "text/tab-separated-values";
952
- /** XML 文档(.xml) */
953
- readonly XML: "application/xml";
954
- /** XML 文档/兼容值 */
955
- readonly XML_LEGACY: "text/xml";
956
- /** XHTML 文档(.xhtml/.xht) */
957
- readonly XHTML: "application/xhtml+xml";
958
- /** JavaScript 文件(.js) */
959
- readonly JS: "text/javascript";
960
- /** TypeScript 文件(.ts) */
961
- readonly TS: "text/typescript";
962
- /** Python 文件(.py) */
963
- readonly PY: "text/x-python";
964
- /** Shell 脚本 (.sh) */
965
- readonly SH: "text/x-sh";
966
- /** C 语言源文件(.c) */
967
- readonly C: "text/x-c";
968
- /** C++ 源文件(.cpp/.cc/.cxx) */
969
- readonly CPP: "text/x-c++";
970
- /** C# 源文件(.cs) */
971
- readonly CSHARP: "text/x-csharp";
972
- /** Java 源文件(.java) */
973
- readonly JAVA: "text/x-java";
974
- /** Go 源文件(.go) */
975
- readonly GO: "text/x-go";
976
- /** Rust 源文件(.rs) */
977
- readonly RUST: "text/x-rust";
978
- /** PHP 文件(.php) */
979
- readonly PHP: "text/x-php";
980
- /** Ruby 文件(.rb) */
981
- readonly RUBY: "text/x-ruby";
982
- /** Swift 源文件(.swift) */
983
- readonly SWIFT: "text/x-swift";
984
- /** YAML 文档(.yaml/.yml) */
985
- readonly YAML: "application/yaml";
986
- /** YAML 文档/兼容值 */
987
- readonly YAML_LEGACY: "text/vnd.yaml";
988
- /** TOML 文档(.toml) */
989
- readonly TOML: "application/toml";
990
- /** TOML 文档/兼容值 */
991
- readonly TOML_LEGACY: "text/x-toml";
992
- /** SQL 脚本(.sql) */
993
- readonly SQL: "application/sql";
994
- /** SQL 脚本/兼容值 */
995
- readonly SQL_LEGACY: "text/x-sql";
996
- /** Markdown 格式文档(.md/.markdown) */
997
- readonly MARKDOWN: "text/markdown";
998
- /** 富文本格式文档(.rtf) */
999
- readonly RTF: "application/rtf";
1000
- /** iCalendar 日历格式(.ics) */
1001
- readonly CALENDAR: "text/calendar";
1002
- /** JPEG 图像(.jpg/.jpeg) */
1003
- readonly JPEG: "image/jpeg";
1004
- /** JPG 图像(JPEG 别名,.jpg) */
1005
- readonly JPG: "image/jpeg";
1006
- /** PNG 图像/无损压缩,支持透明(.png) */
1007
- readonly PNG: "image/png";
1008
- /** GIF 图像/支持动画(.gif) */
1009
- readonly GIF: "image/gif";
1010
- /** Windows 位图(.bmp) */
1011
- readonly BMP: "image/bmp";
1012
- /** SVG 向量图形(.svg) */
1013
- readonly SVG: "image/svg+xml";
1014
- /** APNG 动态图像(.apng) */
1015
- readonly APNG: "image/apng";
1016
- /** AVIF 图像/高效压缩(.avif) */
1017
- readonly AVIF: "image/avif";
1018
- /** 图标文件格式(.ico) */
1019
- readonly ICO: "image/vnd.microsoft.icon";
1020
- /** 图标文件格式/兼容值(.ico) */
1021
- readonly ICO_LEGACY: "image/x-icon";
1022
- /** WebP 图像/高效压缩(.webp) */
1023
- readonly WEBP: "image/webp";
1024
- /** TIFF 图像(.tif/.tiff) */
1025
- readonly TIFF: "image/tiff";
1026
- /** HEIC 图像/高效编码(.heic) */
1027
- readonly HEIC: "image/heic";
1028
- /** HEIF 图像/高效编码(.heif) */
1029
- readonly HEIF: "image/heif";
1030
- /** Adobe Photoshop 文件(.psd) */
1031
- readonly PSD: "image/vnd.adobe.photoshop";
1032
- /** MP3 音频(.mp3) */
1033
- readonly MP3: "audio/mpeg";
1034
- /** AAC 音频(.aac) */
1035
- readonly AAC: "audio/aac";
1036
- /** MIDI 音乐文件(.mid/.midi) */
1037
- readonly MIDI: "audio/midi";
1038
- /** OGG 音频(.oga) */
1039
- readonly OGG_AUDIO: "audio/ogg";
1040
- /** Opus 音频(.opus) */
1041
- readonly OPUS: "audio/opus";
1042
- /** FLAC 无损音频(.flac) */
1043
- readonly FLAC: "audio/flac";
1044
- /** WAV 音频(.wav) */
1045
- readonly WAV: "audio/wav";
1046
- /** WebM 音频(.weba) */
1047
- readonly WEBM_AUDIO: "audio/webm";
1048
- /** RealAudio 音频(.ra/.ram) */
1049
- readonly REAL_AUDIO: "audio/x-pn-realaudio";
1050
- /** MP4 视频(.mp4) */
1051
- readonly MP4: "video/mp4";
1052
- /** MPEG 视频(.mpeg/.mpg) */
1053
- readonly MPEG: "video/mpeg";
1054
- /** OGG 视频(.ogv) */
1055
- readonly OGG_VIDEO: "video/ogg";
1056
- /** AVI 视频(.avi) */
1057
- readonly AVI: "video/x-msvideo";
1058
- /** 3GPP 视频(.3gp) */
1059
- readonly THREE_GPP: "video/3gpp";
1060
- /** 3GPP2 视频(.3g2) */
1061
- readonly THREE_GPP2: "video/3gpp2";
1062
- /** WebM 视频(.webm) */
1063
- readonly WEBM: "video/webm";
1064
- /** Matroska 视频(.mkv) */
1065
- readonly MKV: "video/x-matroska";
1066
- /** Matroska 音频(.mka) */
1067
- readonly MKA: "audio/x-matroska";
1068
- /** QuickTime 视频(.mov) */
1069
- readonly QUICKTIME: "video/quicktime";
1070
- /** PDF 文档(.pdf) */
1071
- readonly PDF: "application/pdf";
1072
- /** Word 97-2003 文档(.doc) */
1073
- readonly DOC: "application/msword";
1074
- /** Word 2007+ 文档(.docx) */
1075
- readonly DOCX: "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
1076
- /** Excel 2007+ 工作簿(.xlsx) */
1077
- readonly XLSX: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
1078
- /** 启用宏的Excel工作簿(.xlsm) */
1079
- readonly XLSM: "application/vnd.ms-excel.sheet.macroEnabled.12";
1080
- /** Excel模板文件(.xltx) */
1081
- readonly XLTX: "application/vnd.openxmlformats-officedocument.spreadsheetml.template";
1082
- /** PowerPoint 2007+ 演示文稿(.pptx) */
1083
- readonly PPTX: "application/vnd.openxmlformats-officedocument.presentationml.presentation";
1084
- /** PowerPoint 97-2003 演示文稿(.ppt) */
1085
- readonly PPT: "application/vnd.ms-powerpoint";
1086
- /** OpenDocument 文本文档(.odt) */
1087
- readonly ODT: "application/vnd.oasis.opendocument.text";
1088
- /** OpenDocument 表格文档(.ods) */
1089
- readonly ODS: "application/vnd.oasis.opendocument.spreadsheet";
1090
- /** OpenDocument 演示文稿(.odp) */
1091
- readonly ODP: "application/vnd.oasis.opendocument.presentation";
1092
- /** EPUB 电子书(.epub) */
1093
- readonly EPUB: "application/epub+zip";
1094
- /** Kindle 电子书(.azw) */
1095
- readonly AZW: "application/vnd.amazon.ebook";
1096
- /** ZIP 压缩文件(.zip) */
1097
- readonly ZIP: "application/zip";
1098
- /** GZIP 压缩文件(.gz) */
1099
- readonly GZIP: "application/gzip";
1100
- /** TAR 归档文件(.tar) */
1101
- readonly TAR: "application/x-tar";
1102
- /** BZip 归档(.bz) */
1103
- readonly BZIP: "application/x-bzip";
1104
- /** BZip2 归档(.bz2) */
1105
- readonly BZIP2: "application/x-bzip2";
1106
- /** 7-Zip 压缩文件(.7z) */
1107
- readonly SEVEN_Z: "application/x-7z-compressed";
1108
- /** RAR 压缩文件(.rar) */
1109
- readonly RAR: "application/vnd.rar";
1110
- /** XZ 压缩文件(.xz) */
1111
- readonly XZ: "application/x-xz";
1112
- /** Zstandard 压缩文件(.zst) */
1113
- readonly ZSTD: "application/zstd";
1114
- /** ISO 光盘镜像(.iso) */
1115
- readonly ISO9660_IMAGE: "application/x-iso9660-image";
1116
- /** JSON 数据格式(.json) */
1117
- readonly JSON: "application/json";
1118
- /** JSON-LD 格式(.jsonld) */
1119
- readonly LD_JSON: "application/ld+json";
1120
- /** Web App Manifest(.webmanifest) */
1121
- readonly MANIFEST: "application/manifest+json";
1122
- /** Java 归档文件(.jar) */
1123
- readonly JAR: "application/java-archive";
1124
- /** WebAssembly 二进制指令格式(.wasm) */
1125
- readonly WASM: "application/wasm";
1126
- /** MS 嵌入式 OpenType 字体(.eot) */
1127
- readonly EOT: "application/vnd.ms-fontobject";
1128
- /** OpenType 字体(.otf) */
1129
- readonly OTF: "font/otf";
1130
- /** WOFF 字体(.woff) */
1131
- readonly WOFF: "font/woff";
1132
- /** WOFF2 字体(.woff2) */
1133
- readonly WOFF2: "font/woff2";
1134
- /** TrueType 字体(.ttf) */
1135
- readonly TTF: "font/ttf";
1136
- /** Excel 97-2003 工作簿(.xls) */
1137
- readonly XLS: "application/vnd.ms-excel";
1138
- /** Microsoft XPS 文档(.xps) */
1139
- readonly XPS: "application/vnd.ms-xpsdocument";
1140
- /** Word 启用宏文档(.docm) */
1141
- readonly DOCM: "application/vnd.ms-word.document.macroEnabled.12";
1142
- };
1143
- /**
1144
- * 协议/内容类型 MIME 常量
1145
- * - 用于 HTTP 请求/响应内容协商,无对应文件扩展名
1146
- */
1147
- static readonly PROTOCOL_MIME: {
1148
- /** 通用二进制数据流 */
1149
- readonly OCTET_STREAM: "application/octet-stream";
1150
- /** URL 编码表单 */
1151
- readonly FORM_URLENCODED: "application/x-www-form-urlencoded";
1152
- /** multipart 表单 */
1153
- readonly FORM_DATA: "multipart/form-data";
1154
- /** Server-Sent Events 数据流 */
1155
- readonly EVENT_STREAM: "text/event-stream";
1156
- /** 问题详情 JSON(RFC 9457) */
1157
- readonly PROBLEM_JSON: "application/problem+json";
1158
- /** JSON Patch(RFC 6902) */
1159
- readonly JSON_PATCH: "application/json-patch+json";
1160
- /** JSON Merge Patch(RFC 7386) */
1161
- readonly MERGE_PATCH_JSON: "application/merge-patch+json";
1162
- };
1163
- /**
1164
- * 根据文件后缀名获取对应的标准 MIME 类型(含历史兼容值)
1165
- * - 支持带 `.` 或不带 `.` 的后缀名,不区分大小写
1166
- * - 元组第一项始终为 IANA 官方标准 MIME,后续项为历史兼容值
1167
- * - 仅查询文件类型 MIME,不包含无后缀对应的协议类型
1168
- *
1169
- * @param extension 文件后缀名(如 `".png"` / `"png"` / `".PNG"`)
1170
- * @returns 标准 MIME + 兼容值的元组;如无匹配则返回 `undefined`
1171
- * @example
1172
- * ```ts
1173
- * MimeUtil.fromExtension(".png"); // ["image/png"]
1174
- * MimeUtil.fromExtension("ico"); // ["image/vnd.microsoft.icon", "image/x-icon"]
1175
- * MimeUtil.fromExtension(".xml"); // ["application/xml", "text/xml"]
1176
- * MimeUtil.fromExtension(".xyz"); // undefined
1177
- * ```
1178
- */
1179
- static fromExtension(extension: string): readonly [string, ...string[]] | undefined;
1180
- /**
1181
- * 根据 MIME 类型获取对应的文件后缀名列表
1182
- * - 一个 MIME 类型可能对应多个后缀名(如 `text/html` → `.html` / `.htm`)
1183
- * - 兼容值和标准值映射到相同的后缀(如 `image/x-icon` 和 `image/vnd.microsoft.icon` 均返回 `[".ico"]`)
1184
- * - 仅查询文件类型 MIME,协议类型无对应后缀
1185
- *
1186
- * @param mime MIME 类型字符串(如 `"image/png"` / `"IMAGE/PNG"`)
1187
- * @returns 文件后缀名列表;如无匹配则返回 `undefined`
1188
- * @example
1189
- * ```ts
1190
- * MimeUtil.toExtension("IMAGE/PNG"); // [".png"]
1191
- * MimeUtil.toExtension("text/html"); // [".html", ".htm"]
1192
- * MimeUtil.toExtension("image/jpeg"); // [".jpg", ".jpeg"]
1193
- * MimeUtil.toExtension("application/octet-stream"); // undefined
1194
- * ```
1195
- */
1196
- static toExtension(mime: string): readonly [string, ...string[]] | undefined;
1197
- }
1198
- //#endregion
1199
- //#region src/number/numberUtil.d.ts
1200
- /**
1201
- * 数字工具类
1202
- */
1203
- declare class NumberUtil {
1204
- /**
1205
- * 数字区间检查函数
1206
- *
1207
- * @param input 待检查数字
1208
- * @param interval 由两个数字组成的元组 [left, right]
1209
- * @param includeLeft 是否包含左边界(默认 true)
1210
- * @param includeRight 是否包含右边界(默认 false)
1211
- * @returns 是否在区间内
1212
- * @example
1213
- * ```ts
1214
- * NumberUtil.within(5, [1, 10]); // true
1215
- * NumberUtil.within(1, [1, 10], false); // false
1216
- * ```
1217
- */
1218
- static within(input: number, interval: [number, number], includeLeft?: boolean, includeRight?: boolean): boolean;
1219
- }
1220
- //#endregion
1221
- //#region src/object/index.type.d.ts
1222
- type Range<Start extends number, End extends number> = Exclude<keyof TupleOf<End>, keyof TupleOf<Start>>;
1223
- type AnyArray<A = any> = readonly A[];
1224
- type TupleToEntries<A extends readonly unknown[]> = If<IsAny<A>, unknown, { [Key in keyof A]: [Key, A[Key]]; }>;
1225
- type Groups<L extends AnyArray, LN extends AnyArray = [], D extends number[] = []> = D["length"] extends 40 ? LN : {
1226
- 0: Groups<List.Drop<L, 1>, List.Append<LN, [`${LN["length"]}`, List.Take<L, 1>]>, [...D, 0]>;
1227
- 1: LN;
1228
- }[Any.Extends<L, AnyArray<never>>];
1229
- type TupleToGroups<L extends AnyArray> = Groups<L> extends (infer X) ? Any.Cast<X, AnyArray> : never;
1230
- type Crush<T> = T extends readonly (infer U)[] ? Record<string, U extends object ? unknown : U> : Simplify<UnionToIntersection<keyof T extends (infer Prop) ? Prop extends keyof T ? T[Prop] extends (infer Value) ? ([Extract<Value, object>] extends [never] ? never : Record<string, unknown>) | ([Exclude<Value, object>] extends [never] ? never : [Extract<Value, object>] extends [never] ? { [P in Prop]: Value; } : Record<string, unknown>) : never : never : never>>;
1231
- type IntersectOf<U> = (U extends unknown ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
1232
- type ComputeRaw<A> = A extends AnyFunction ? A : { [K in keyof A]: A[K]; } & unknown;
1233
- type _Invert<O extends Record<PropertyKey, PropertyKey>> = ComputeRaw<IntersectOf<{ [K in keyof O]: Record<O[K], K>; }[keyof O]>>;
1234
- type Invert<O extends Record<keyof O, PropertyKey>> = O extends unknown ? _Invert<O> : never;
1235
- //#endregion
1236
- //#region src/object/objectUtil.d.ts
1237
- /**
1238
- * 对象工具类
1239
- */
1240
- declare class ObjectUtil {
1241
- /**
1242
- * 返回对象可枚举属性和方法的名称
1243
- * - `Object.keys` 始终返回 `string[]` 类型,此函数可以返回具体类型
1244
- *
1245
- * @param value 对象
1246
- * @returns 键数组
1247
- * @example
1248
- * ```ts
1249
- * // 重载 1: string
1250
- * ObjectUtil.keys("abc"); // ["0", "1", "2"]
1251
- *
1252
- * // 重载 2: ArrayLike
1253
- * ObjectUtil.keys([10, 20]); // ["0", "1"]
1254
- *
1255
- * // 重载 3: PlainObject
1256
- * ObjectUtil.keys({ a: 1, b: 2 }); // ["a", "b"]
1257
- *
1258
- * // 重载 4: AnyObject
1259
- * const anyObj = { x: 1, y: 2 } as Record<string, unknown>;
1260
- * ObjectUtil.keys(anyObj); // ["x", "y"]
1261
- * ```
1262
- */
1263
- static keys<const S extends string>(string: S): UnionToTuple<Range<0, Split<S, "">["length"]>>;
1264
- static keys<const A extends ArrayLike<unknown>>(array: A): UnionToTuple<Range<0, A["length"]>>;
1265
- static keys<O extends PlainObject>(plainObject: O): `${Extract<keyof O, string | number>}`[];
1266
- static keys<O extends AnyObject>(anyObject: O): `${Extract<keyof O, string | number>}`[];
1267
- /**
1268
- * 返回对象可枚举属性的值的数组
1269
- *
1270
- * @param value 对象
1271
- * @returns 值数组
1272
- * @example
1273
- * ```ts
1274
- * // 重载 1: string
1275
- * ObjectUtil.values("abc"); // ["a", "b", "c"]
1276
- *
1277
- * // 重载 2: ArrayLike
1278
- * ObjectUtil.values([10, 20]); // [10, 20]
1279
- *
1280
- * // 重载 3: PlainObject
1281
- * ObjectUtil.values({ a: 1, b: 2 }); // [1, 2]
1282
- *
1283
- * // 重载 4: AnyObject
1284
- * const anyObj = { x: 1, y: 2 } as Record<string, unknown>;
1285
- * ObjectUtil.values(anyObj); // [1, 2]
1286
- * ```
1287
- */
1288
- static values<S extends string>(string: S): Split<S, "">;
1289
- static values<A extends ArrayLike<unknown>>(array: A): A;
1290
- static values<O extends PlainObject>(plainObject: O): O[keyof O][];
1291
- static values<O extends AnyObject>(anyObject: O): O[keyof O][];
1292
- /**
1293
- * 返回对象的可枚举属性的键/值数组
1294
- *
1295
- * @param value 对象
1296
- * @returns 键值对数组
1297
- * @example
1298
- * ```ts
1299
- * // 重载 1: string
1300
- * ObjectUtil.entries("ab"); // [["0", "a"], ["1", "b"]]
1301
- *
1302
- * // 重载 2: readonly array
1303
- * ObjectUtil.entries([10, 20] as const); // [["0", 10], ["1", 20]]
1304
- *
1305
- * // 重载 3: PlainObject
1306
- * ObjectUtil.entries({ a: 1 }); // [["a", 1]]
1307
- *
1308
- * // 重载 4: AnyObject
1309
- * const anyObj = { x: 1 } as Record<string, unknown>;
1310
- * ObjectUtil.entries(anyObj); // [["x", 1]]
1311
- * ```
1312
- */
1313
- static entries<const S extends string>(string: S): TupleToEntries<Split<S, "">>;
1314
- static entries<const A extends readonly unknown[]>(array: A): TupleToGroups<A>;
1315
- static entries<const O extends PlainObject>(plainObject: O): [`${keyof Except<O, symbol>}`, O[keyof Except<O, symbol>]][];
1316
- static entries<const O extends AnyObject>(anyObject: O): [`${keyof Except<O, symbol>}`, O[keyof Except<O, symbol>]][];
1317
- /**
1318
- * 映射对象条目
1319
- * - 将对象的键值对映射为新的键值对
1320
- *
1321
- * @param plainObject 对象
1322
- * @param toEntry 映射函数
1323
- * @returns 映射后的新对象
1324
- * @example
1325
- * ```ts
1326
- * const obj = { a: 1, b: 2 };
1327
- *
1328
- * ObjectUtil.entriesMap(obj, (k, v) => [k, v * 2]); // { a: 2, b: 4 }
1329
- *
1330
- * ObjectUtil.entriesMap(obj, (k, v) => [`prefix_${String(k)}`, `${v}x`]); // { prefix_a: "1x", prefix_b: "2x" }
1331
- * ```
1332
- */
1333
- static entriesMap<O extends PlainObject, NK extends PropertyKey, NV>(plainObject: O, toEntry: (key: keyof O, value: O[keyof O]) => [NK, NV]): PlainObject<NK, NV>;
1334
- /**
1335
- * 选取对象的指定属性
1336
- *
1337
- * @param plainObject 对象
1338
- * @param keys 要选取的属性键数组
1339
- * @returns 包含指定属性的新对象
1340
- * @example
1341
- * ```ts
1342
- * // 重载 1: PlainObject
1343
- * ObjectUtil.pick({ a: 1, b: 2 }, ["a"]); // { a: 1 }
1344
- *
1345
- * // 重载 2: AnyObject
1346
- * const anyObj = { x: 1, y: 2 } as Record<string, unknown>;
1347
- * ObjectUtil.pick(anyObj, ["x"]); // { x: 1 }
1348
- * ```
1349
- */
1350
- static pick<O extends PlainObject, K extends keyof O>(plainObject: O, keys: readonly K[]): Pick<O, K>;
1351
- static pick<O extends AnyObject, K extends keyof O>(anyObject: O, keys: readonly K[]): Pick<O, K>;
1352
- /**
1353
- * 排除对象的指定属性
1354
- *
1355
- * @param plainObject 对象
1356
- * @param keys 要排除的属性键数组
1357
- * @returns 排除指定属性后的新对象
1358
- * @example
1359
- * ```ts
1360
- * // 重载 1: PlainObject
1361
- * ObjectUtil.omit({ a: 1, b: 2 }, ["a"]); // { b: 2 }
1362
- *
1363
- * // 重载 2: AnyObject
1364
- * const anyObj = { x: 1, y: 2 } as Record<string, unknown>;
1365
- * ObjectUtil.omit(anyObj, ["x"]); // { y: 2 }
1366
- * ```
1367
- */
1368
- static omit<O extends PlainObject, K extends keyof O>(plainObject: O, keys: readonly K[]): Omit<O, K>;
1369
- static omit<O extends AnyObject, K extends keyof O>(anyObject: O, keys: readonly K[]): PlainObject;
1370
- /**
1371
- * 尽可能地交换对象的键和值
1372
- *
1373
- * @param obj 对象
1374
- * @returns 键值互换后的对象
1375
- * @example
1376
- * ```ts
1377
- * // 重载 1: Record<keyof O, PropertyKey>
1378
- * const obj = { a: "1", b: 2 };
1379
- * ObjectUtil.invert(obj); // { "1": "a", 2: "b" }
1380
- *
1381
- * // 重载 2: AnyObject
1382
- * const anyObj = { x: Symbol.for("s"), y: true } as Record<string, unknown>;
1383
- * ObjectUtil.invert(anyObj); // { [Symbol.for("s")]: "x" }
1384
- * ```
1385
- */
1386
- static invert<const O extends Record<keyof O, PropertyKey>>(plainObject: O): Invert<O>;
1387
- static invert<const O extends AnyObject>(anyObject: O): Invert<O>;
1388
- /**
1389
- * 压平对象
1390
- * - 将多层级的对象转换为单层级的对象,键名使用点号连接
1391
- *
1392
- * @param plainObject 平面对象
1393
- * @returns 压平后的对象
1394
- * @example
1395
- * ```ts
1396
- * // 重载 1: PlainObject
1397
- * const plainObj = { a: { b: 1 } };
1398
- * ObjectUtil.crush(plainObj); // { "a.b": 1 }
1399
- *
1400
- * // 重载 2: AnyObject
1401
- * const anyObj = { list: [{ id: 1 }] } as Record<string, unknown>;
1402
- * ObjectUtil.crush(anyObj); // { "list.0.id": 1 }
1403
- * ```
1404
- */
1405
- static crush<T extends PlainObject>(plainObject: T): Crush<T>;
1406
- static crush<T extends AnyObject>(anyObject: T): Crush<T>;
1407
- /**
1408
- * 获取所有枚举成员的键
1409
- *
1410
- * @param enumeration 枚举对象
1411
- * @returns 键数组
1412
- * @example
1413
- * ```ts
1414
- * // 重载 1: PlainObject
1415
- * enum StringEnum { A = "a", B = "b" }
1416
- * ObjectUtil.enumKeys(StringEnum); // ["A", "B"]
1417
- *
1418
- * // 重载 2: AnyObject
1419
- * enum NumberEnum { A, B }
1420
- * const anyEnum = NumberEnum as Record<string, unknown>;
1421
- * ObjectUtil.enumKeys(anyEnum); // ["A", "B"]
1422
- * ```
1423
- */
1424
- static enumKeys<E extends PlainObject>(enumeration: E): (keyof E)[];
1425
- static enumKeys<E extends AnyObject>(enumeration: E): (keyof E)[];
1426
- /**
1427
- * 获取所有枚举成员的值
1428
- *
1429
- * @param enumeration 枚举对象
1430
- * @returns 值数组
1431
- * @example
1432
- * ```ts
1433
- * // 重载 1: PlainObject
1434
- * enum StringEnum { A = "a", B = "b" }
1435
- * ObjectUtil.enumValues(StringEnum); // ["a", "b"]
1436
- *
1437
- * // 重载 2: AnyObject
1438
- * enum NumberEnum { A, B }
1439
- * const anyEnum = NumberEnum as Record<string, unknown>;
1440
- * ObjectUtil.enumValues(anyEnum); // [0, 1]
1441
- * ```
1442
- */
1443
- static enumValues<E extends PlainObject>(enumeration: E): UnionToTuple<ValueOf<E>>;
1444
- static enumValues<E extends AnyObject>(enumeration: E): UnionToTuple<ValueOf<E>>;
1445
- /**
1446
- * 获取所有枚举成员的键/值数组
1447
- *
1448
- * @param enumeration 枚举对象
1449
- * @returns 键值对数组
1450
- * @example
1451
- * ```ts
1452
- * // 重载 1: PlainObject
1453
- * enum StringEnum { A = "a", B = "b" }
1454
- * ObjectUtil.enumEntries(StringEnum); // [["A", "a"], ["B", "b"]]
1455
- *
1456
- * // 重载 2: AnyObject
1457
- * enum NumberEnum { A, B }
1458
- * const anyEnum = NumberEnum as Record<string, unknown>;
1459
- * ObjectUtil.enumEntries(anyEnum); // [["A", 0], ["B", 1]]
1460
- * ```
1461
- */
1462
- static enumEntries<E extends PlainObject>(enumeration: E): [keyof E, E[keyof E]][];
1463
- static enumEntries<E extends AnyObject>(enumeration: E): [keyof E, E[keyof E]][];
1464
- }
1465
- //#endregion
1466
- //#region src/string/stringUtil.d.ts
1467
- /**
1468
- * 字符串工具类
1469
- */
1470
- declare class StringUtil {
1471
- /**
1472
- * 将任意值转换为字符串
1473
- * - 当传入数值字面量时,返回对应的字符串字面量类型
1474
- *
1475
- * @param candidate 待转换的值
1476
- * @param checkNullish 是否检查空值(`null` / `undefined` / 空白字符串),默认为 `true`
1477
- * @param trim 是否去除结果首尾空白,默认为 `true`
1478
- * @returns 转换后的字符串
1479
- * @example
1480
- * ```ts
1481
- * // 重载 1: null / undefined + checkNullish = true (默认) → ""
1482
- * StringUtil.cast(null); // ""
1483
- * StringUtil.cast(undefined); // ""
1484
- * StringUtil.cast(""); // ""
1485
- * StringUtil.cast(" "); // ""
1486
- *
1487
- * // 重载 2: null / undefined + checkNullish = false → "null" / "undefined"
1488
- * StringUtil.cast(null, false); // "null" (类型为 "null")
1489
- * StringUtil.cast(undefined, false); // "undefined" (类型为 "undefined")
1490
- *
1491
- * // 重载 3: 原始类型 → Trim<`${T}`> 字面量类型(trim 默认 true)
1492
- * StringUtil.cast(123); // "123" (类型为 "123")
1493
- * StringUtil.cast("hello"); // "hello" (类型为 "hello")
1494
- * StringUtil.cast(true); // "true" (类型为 "true")
1495
- * StringUtil.cast(42n); // "42" (类型为 "42")
1496
- * // 默认去除结果首尾空白
1497
- * StringUtil.cast(" hello "); // "hello" (类型为 Trim<" hello "> = "hello")
1498
- * StringUtil.cast("\n abc \n"); // "abc" (类型为 "abc")
1499
- *
1500
- * // 重载 4: 原始类型 + trim = false → 保留字面量类型
1501
- * StringUtil.cast("\n abc \n", true, false); // "\n abc \n" (类型为 "\n abc \n")
1502
- * StringUtil.cast(123, undefined, false); // "123" (类型为 "123")
1503
- *
1504
- * // 重载 5: 其他类型 → string
1505
- * StringUtil.cast(Symbol("foo")); // "Symbol(foo)" (类型为 string)
1506
- * StringUtil.cast([1, 2, 3]); // "1,2,3" (类型为 string)
1507
- * StringUtil.cast({}); // "[object Object]" (类型为 string)
1508
- * ```
1509
- */
1510
- static cast<T extends null | undefined>(candidate: T, checkNullish?: true, trim?: boolean): "";
1511
- static cast<T extends null | undefined>(candidate: T, checkNullish: false, trim?: boolean): Trim<`${T}`>;
1512
- static cast<T extends string | number | bigint | boolean>(candidate: T, checkNullish?: boolean, trim?: true): Trim<`${T}`>;
1513
- static cast<T extends string | number | bigint | boolean>(candidate: T, checkNullish: boolean | undefined, trim: false): `${T}`;
1514
- static cast(candidate: unknown, checkNullish?: boolean, trim?: boolean): string;
1515
- /**
1516
- * 从字符串中提取数字字符串
1517
- * - 移除非数字字符,保留符号和小数点
1518
- *
1519
- * @param input 待处理字符串
1520
- * @returns 提取出的数字字符串
1521
- * @example
1522
- * ```ts
1523
- * StringUtil.toNumber("$1,234.56"); // "1234.56"
1524
- * StringUtil.toNumber("abc-123"); // "-123"
1525
- * ```
1526
- */
1527
- static toNumber(input: string): string;
1528
- /**
1529
- * 将字符串转换为小写
1530
- * - 将字符串字面量类型转换为其小写形式
1531
- * - 当输入无效时,返回空字符串
1532
- *
1533
- * @param input 待处理字符串
1534
- * @returns 转换后的小写字符串类型,如果输入无效则返回空字符串类型 ""
1535
- * @example
1536
- * ```ts
1537
- * // 重载 1: 输入 string
1538
- * StringUtil.toLowerCase("HELLO"); // "hello"
1539
- *
1540
- * // 重载 2: 输入 unknown
1541
- * StringUtil.toLowerCase(null); // ""
1542
- * ```
1543
- */
1544
- static toLowerCase<const T extends string>(input: T): Lowercase<T>;
1545
- static toLowerCase(input: unknown): "";
1546
- /**
1547
- * 将字符串转换为大写
1548
- * - 将字符串字面量类型转换为其大写形式
1549
- * - 当输入无效时,返回空字符串
1550
- *
1551
- * @param input 待处理字符串
1552
- * @returns 转换后的大写字符串,如果输入无效则返回空字符串
1553
- * @example
1554
- * ```ts
1555
- * // 重载 1: 输入 string
1556
- * StringUtil.toUpperCase("hello"); // "HELLO"
1557
- *
1558
- * // 重载 2: 输入 unknown
1559
- * StringUtil.toUpperCase(null); // ""
1560
- * ```
1561
- */
1562
- static toUpperCase<const T extends string>(input: T): Uppercase<T>;
1563
- static toUpperCase(input: unknown): "";
1564
- /**
1565
- * 调整大小写
1566
- * - 每个单词(`\S+`)独立处理
1567
- * - 包含非西欧字母字符(如 `.`、`,`、`'`、`-`)时,该词不处理
1568
- * - 纯字母且全大写时,不处理
1569
- * - 纯字母且非全大写时:`caseType` 为 `"lower"` 则首字母小写,`"upper"` 则首字母大写,其余字符保留
1570
- * - ⚠️ 缺省 `caseType` 时不产生任何转换(no-op),需显式传 `"lower"` / `"upper"`
1571
- *
1572
- * @param input 待处理字符串
1573
- * @param caseType 大小写类型(缺省时无操作)
1574
- * @returns 处理后的字符串
1575
- * @example
1576
- * ```ts
1577
- * // 重载 1: lower
1578
- * StringUtil.toInitialCase("Hello World", "lower"); // "hello world"
1579
- *
1580
- * // 重载 2: upper
1581
- * StringUtil.toInitialCase("hello world", "upper"); // "Hello World"
1582
- *
1583
- * // 缺省 caseType → no-op
1584
- * StringUtil.toInitialCase("Hello"); // "Hello"
1585
- * ```
1586
- */
1587
- static toInitialCase(input: string, caseType?: "lower" | "upper" | undefined): string;
1588
- /**
1589
- * 将路径转换为 POSIX 风格
1590
- * - 统一使用正斜杠 (/)
1591
- * - 可选移除 Windows 盘符 (如 C:)
1592
- * - 可选移除开头的斜杠
1593
- * - 规范化连续斜杠为单个斜杠
1594
- *
1595
- * @param input 待处理字符串
1596
- * @param removeLeadingSlash 是否移除开头斜杠,默认为 `false`。如果移除了盘符,路径通常会以 / 开头,此参数可控制是否保留该 /
1597
- * @returns 转换后的路径,如果输入无效则返回空字符串
1598
- *
1599
- * @example
1600
- * ```ts
1601
- * StringUtil.toPosix("C:\\Windows\\System32"); // 默认: "/Windows/System32" (移除了 C: 并标准化)
1602
- *
1603
- * StringUtil.toPosix("C:\\Windows\\System32", true); // 移除开头斜杠: "Windows/System32"
1604
- *
1605
- * StringUtil.toPosix("\\\\server\\share\\file.txt"); // UNC 路径: "/server/share/file.txt"
1606
- *
1607
- * StringUtil.toPosix("folder\\subfolder\\file.txt"); // 相对路径: "folder/subfolder/file.txt"
1608
- * ```
1609
- */
1610
- static toPosix(input: string | null | undefined, removeLeadingSlash?: boolean): string;
1611
- /**
1612
- * 处理 JSON 字符串
1613
- *
1614
- * @param input 待处理字符串
1615
- * @param fallback 回退值
1616
- * @returns 解析后的对象 或 回退值
1617
- * @example
1618
- * ```ts
1619
- * // 重载 1: 无 fallback
1620
- * StringUtil.toJson<{ a: number }>("{\"a\":1}"); // { a: 1 }
1621
- * StringUtil.toJson("invalid"); // undefined
1622
- *
1623
- * // 重载 2: 有 fallback
1624
- * StringUtil.toJson<{ a: number }>("invalid", { a: 0 }); // { a: 0 }
1625
- * ```
1626
- */
1627
- static toJson<D extends AnyObject = AnyObject>(input: string | null | undefined): D | undefined;
1628
- static toJson<D extends AnyObject = AnyObject>(input: string | null | undefined, fallback: D): D;
1629
- /**
1630
- * 字符串分割为数组
1631
- * - 按指定分隔符分割字符串,并转换类型
1632
- * - ⚠️ `valueType` 为 `"number"` 时,无法解析的片段会转为 `NaN`,**不进行过滤**
1633
- *
1634
- * @param input 待处理字符串
1635
- * @param valueType 数组中每一项的类型,默认为 "number"
1636
- * @param splitSymbol 分隔符,默认为 `,`
1637
- * @returns 分割后的数组
1638
- * @example
1639
- * ```ts
1640
- * // 重载 1: valueType = "number" (默认)
1641
- * StringUtil.toValues("1,2,3"); // [1, 2, 3]
1642
- *
1643
- * // 重载 2: valueType = "string"
1644
- * StringUtil.toValues("a-b-c", "string", "-"); // ["a", "b", "c"]
1645
- *
1646
- * // 无法解析的片段 → NaN 不被过滤
1647
- * StringUtil.toValues("1,abc,3"); // [1, NaN, 3]
1648
- * ```
1649
- */
1650
- static toValues(input: string | null | undefined, valueType?: "number" | undefined, splitSymbol?: string | undefined): number[];
1651
- static toValues(input: string | null | undefined, valueType: "string", splitSymbol?: string | undefined): string[];
1652
- /**
1653
- * 从字符串中裁切掉所有的前缀和后缀字符
1654
- *
1655
- * @param input 待处理字符串
1656
- * @param charsToTrim 裁切字符,默认为 `" "`
1657
- * @returns 裁切后的字符串
1658
- * @example
1659
- * ```ts
1660
- * StringUtil.trim(" hello "); // "hello"
1661
- * StringUtil.trim("__hello__", "_"); // "hello"
1662
- * ```
1663
- */
1664
- static trim(input: string | null | undefined, charsToTrim?: string): string;
1665
- /**
1666
- * 截取字符串
1667
- * - 支持自定义省略符,不会截断在汉字中间(因为JS字符串本身按字符处理)
1668
- *
1669
- * @param input 待处理字符串
1670
- * @param maxLength 最大长度 (包含省略符)
1671
- * @param ellipsis 省略符,默认为 `...`
1672
- * @returns 截取后的字符串
1673
- * @example
1674
- * ```ts
1675
- * StringUtil.truncate("hello world", 8); // "hello..."
1676
- * ```
1677
- */
1678
- static truncate(input: string, maxLength: number, ellipsis?: string): string;
1679
- /**
1680
- * 字符串模板替换
1681
- * - 使用对象的属性值替换字符串中的 {{key}} 模板
1682
- *
1683
- * @param input 待处理字符串
1684
- * @param template 模板对象
1685
- * @param regex 模板匹配正则 (默认: `\{\{(.+?)\}\}`)
1686
- * @returns 替换后的字符串
1687
- * @example
1688
- * ```ts
1689
- * StringUtil.template("Hello {{name}}", { name: "World" }); // "Hello World"
1690
- * ```
1691
- */
1692
- static template(input: string, template: PlainObject, regex?: RegExp): string;
1693
- /**
1694
- * 字符串替换
1695
- * - 替换第一个匹配项
1696
- *
1697
- * @param input 待处理字符串
1698
- * @param search 匹配项
1699
- * @param replacement 替换项
1700
- * @returns 替换后的字符串
1701
- * @example
1702
- * ```ts
1703
- * StringUtil.replace("hello world", "world", "context"); // "hello context"
1704
- * ```
1705
- */
1706
- static replace<I extends string, S extends string, R extends string>(input: I, search: S, replacement: R): Replace<I, S, R>;
1707
- }
1708
- //#endregion
1709
- //#region src/theme/themeUtil.d.ts
1710
- /**
1711
- * 主题工具类
1712
- */
1713
- declare class ThemeUtil {
1714
- /**
1715
- * 固定主题类型(仅亮色/暗色)
1716
- *
1717
- * @example
1718
- * ```ts
1719
- * ThemeUtil.THEME.LIGHT; // "light"
1720
- * ThemeUtil.THEME.DARK; // "dark"
1721
- * ```
1722
- */
1723
- static readonly THEME: {
1724
- readonly LIGHT: "light";
1725
- readonly DARK: "dark";
1726
- };
1727
- /**
1728
- * 主题模式(支持跟随系统)
1729
- *
1730
- * @example
1731
- * ```ts
1732
- * ThemeUtil.THEME_MODE.SYSTEM; // "system"
1733
- * ThemeUtil.THEME_MODE.DARK; // "dark"
1734
- * ```
1735
- */
1736
- static readonly THEME_MODE: {
1737
- readonly LIGHT: "light";
1738
- readonly DARK: "dark";
1739
- readonly SYSTEM: "system";
1740
- };
1741
- }
1742
- //#endregion
1743
- //#region src/theme/index.type.d.ts
1744
- type THEME_TYPE = ValueOf<typeof ThemeUtil.THEME>;
1745
- type THEME_MODE_TYPE = ValueOf<typeof ThemeUtil.THEME_MODE>;
1746
- //#endregion
1747
- //#region src/tree/index.type.d.ts
1748
- type RowKey = "id";
1749
- type ParentIdKey = "parentId";
1750
- type ChildrenKey = "children";
1751
- type Strategy = "pre" | "post" | "breadth";
1752
- interface BaseCallbackMeta<T> {
1753
- depth: number;
1754
- parents?: T[] | undefined;
1755
- }
1756
- interface BaseOptions<T, CK extends string> {
1757
- childrenKey?: CK;
1758
- strategy?: Strategy;
1759
- getChildrenKey?: ((row: T, meta: BaseCallbackMeta<T>) => CK) | undefined;
1760
- }
1761
- interface RowsToTreeOptions<RK extends string = RowKey, PK extends string = ParentIdKey, CK extends string = ChildrenKey> {
1762
- rowKey?: RK;
1763
- parentIdKey?: PK;
1764
- childrenKey?: CK;
1765
- }
1766
- type TreeToRowsOptions<T extends AnyObject$1, CK extends string = ChildrenKey> = TreeForeachOptions<T, CK>;
1767
- type TreeFindOptions<T extends AnyObject$1, CK extends string = ChildrenKey> = BaseOptions<T, CK>;
1768
- type TreeFindCallback<T extends AnyObject$1> = (row: T, meta: BaseCallbackMeta<T>) => boolean;
1769
- type TreeForeachOptions<T extends AnyObject$1, CK extends string = ChildrenKey> = BaseOptions<T, CK>;
1770
- type TreeForeachCallback<T extends AnyObject$1> = (row: T, meta: BaseCallbackMeta<T>) => void;
1771
- type TreeFilterOptions<T extends AnyObject$1, CK extends string = ChildrenKey> = BaseOptions<T, CK>;
1772
- type TreeFilterCallback<T extends AnyObject$1> = (row: T, meta: BaseCallbackMeta<T>) => boolean;
1773
- type TreeMapOptions<T extends AnyObject$1, CK extends string> = BaseOptions<T, CK>;
1774
- type TreeMapCallback<R extends AnyObject$1, T extends AnyObject$1> = (row: T, meta: BaseCallbackMeta<T>) => R;
1775
- //#endregion
1776
- //#region src/tree/treeUtil.d.ts
1777
- /**
1778
- * 树结构工具类
1779
- *
1780
- * 引用策略约定:
1781
- * - 转换类方法(`rowsToTree` / `treeToRows` / `filter` / `map`):不突变输入;输出的每个节点均为**新对象引用**(来源节点的浅拷贝,仅自有可枚举属性;非枚举属性、原型链、getter 及深层嵌套对象不保证)。
1782
- * - 查询类方法(`find` / `forEach`):按查询语义直接使用**原对象引用**。
1783
- */
1784
- declare class TreeUtil {
1785
- /**
1786
- * 行结构 转 树结构
1787
- * - 将平铺的数组转换为树形结构
1788
- * - 返回的树结构与输入行无共享节点(新对象引用),输入行不会被突变
1789
- * - 重复 id 的行只取首次出现;仅叶子/缺失父节点的 id 会作为根节点,且每个根节点只输出一次
1790
- *
1791
- * @param rows 行数据数组
1792
- * @param options 配置项
1793
- * @returns 树结构数组(所有节点均包含 children 数组)
1794
- * @example
1795
- * ```ts
1796
- * const rows = [
1797
- * { id: 1, parentId: null },
1798
- * { id: 2, parentId: 1 },
1799
- * ];
1800
- * TreeUtil.rowsToTree(rows); // [{ id: 1, parentId: null, children: [{ id: 2, parentId: 1, children: [] }] }]
1801
- * ```
1802
- */
1803
- static rowsToTree<T extends AnyObject = AnyObject, CK extends string = ChildrenKey, R extends AnyObject = TreeLike<T, CK>, RK extends string = RowKey, PK extends string = ParentIdKey>(rows: T[], options?: RowsToTreeOptions<RK, PK, CK> | undefined): R[];
1804
- /**
1805
- * 树结构 转 行结构
1806
- * - 将树形结构扁平化为数组
1807
- *
1808
- * @param tree 树结构数据 (单个节点或节点数组)
1809
- * @param options 配置项
1810
- * @returns 扁平化后的数组
1811
- * @example
1812
- * ```ts
1813
- * const tree = [{ id: 1, children: [{ id: 2 }] }];
1814
- * TreeUtil.treeToRows(tree); // [{ id: 1, children: undefined }, { id: 2, children: undefined }]
1815
- * ```
1816
- */
1817
- static treeToRows<T extends AnyObject, CK extends string = ChildrenKey, R extends AnyObject = TreeLikeOptionalChildren<T, CK>>(tree: T | T[], options?: TreeToRowsOptions<T, CK>): R[];
1818
- /**
1819
- * 遍历树节点
1820
- *
1821
- * @param tree 树结构数据
1822
- * @param callback 回调函数
1823
- * @param options 配置项
1824
- * @example
1825
- * ```ts
1826
- * const tree = [{ id: 1, children: [{ id: 2 }] }];
1827
- * const ids: number[] = [];
1828
- * TreeUtil.forEach(tree, (node) => ids.push(node.id)); // ids: [1, 2] (pre-order default)
1829
- * ```
1830
- */
1831
- static forEach<T extends AnyObject, CK extends string = ChildrenKey>(tree: T | T[], callback: TreeForeachCallback<T>, options?: TreeForeachOptions<T, CK>): void;
1832
- /**
1833
- * 查找树节点
1834
- * - 返回第一个回调返回 true 的节点
1835
- *
1836
- * @param tree 树结构数据
1837
- * @param callback 回调函数
1838
- * @param options 配置项
1839
- * @returns 找到的节点,未找到则返回 undefined
1840
- * @example
1841
- * ```ts
1842
- * const tree = [{ id: 1, children: [{ id: 2 }] }];
1843
- * TreeUtil.find(tree, (node) => node.id === 2); // { id: 2, ... }
1844
- * ```
1845
- */
1846
- static find<T extends AnyObject, CK extends string = ChildrenKey>(tree: T | T[], callback: TreeFindCallback<T>, options?: TreeFindOptions<T, CK>): T | undefined;
1847
- /**
1848
- * 过滤树节点
1849
- * - 返回新的树结构,包含所有回调返回 true 的节点
1850
- * - 如果父节点被过滤,则其子节点也会被过滤 (pre 策略下)
1851
- *
1852
- * @param tree 树结构数据
1853
- * @param callback 回调函数
1854
- * @param options 配置项 (childrenKey, strategy等)
1855
- * @returns 过滤后的树结构数组
1856
- * @example
1857
- * ```ts
1858
- * const tree = [{ id: 1, visible: true, children: [{ id: 2, visible: false }] }];
1859
- *
1860
- * // 重载 1: 传入树数组
1861
- * TreeUtil.filter(tree, (node) => node.visible); // [{ id: 1, visible: true, children: [] }]
1862
- *
1863
- * // 重载 2: 传入单个树节点
1864
- * TreeUtil.filter(tree[0], (node) => node.visible); // { id: 1, visible: true, children: [] }
1865
- * ```
1866
- */
1867
- static filter<T extends AnyObject, CK extends string = ChildrenKey>(tree: T[], callback: TreeFilterCallback<T>, options?: TreeFilterOptions<T, CK>): T[];
1868
- static filter<T extends AnyObject, CK extends string = ChildrenKey>(tree: T, callback: TreeFilterCallback<T>, options?: TreeFilterOptions<T, CK>): T;
1869
- /**
1870
- * 映射树节点
1871
- * - 返回新的树结构,保持层级关系
1872
- *
1873
- * @param tree 树结构数据
1874
- * @param callback 回调函数 (返回映射后的节点内容)
1875
- * @param options 配置项
1876
- * @returns 映射后的树结构数组
1877
- * @example
1878
- * ```ts
1879
- * const tree = [{ id: 1, val: 10, children: [{ id: 2, val: 20 }] }];
1880
- *
1881
- * // 重载 1: 传入树数组
1882
- * TreeUtil.map(tree, (node) => ({ ...node, val: node.val * 2 }));
1883
- * // [{ id: 1, val: 20, children: [{ id: 2, val: 40 }] }]
1884
- *
1885
- * // 重载 2: 传入单个树节点
1886
- * TreeUtil.map(tree[0], (node) => ({ ...node, val: node.val * 2 }));
1887
- * // { id: 1, val: 20, children: [{ id: 2, val: 40 }] }
1888
- * ```
1889
- */
1890
- static map<R extends AnyObject, T extends AnyObject, CK extends string = ChildrenKey>(tree: T[], callback: TreeMapCallback<R, T>, options?: TreeMapOptions<T, CK>): TreeLike<R, CK>[];
1891
- static map<R extends AnyObject, T extends AnyObject, CK extends string = ChildrenKey>(tree: T, callback: TreeMapCallback<R, T>, options?: TreeMapOptions<T, CK>): TreeLike<R, CK>;
1892
- }
1893
- //#endregion
1894
- //#region src/type/index.type.d.ts
1895
- interface Class<T, Arguments extends unknown[] = unknown[]> {
1896
- new (...arguments_: Arguments): T;
1897
- prototype: Pick<T, keyof T>;
1898
- }
1899
- //#endregion
1900
- //#region src/type/typeUtil.d.ts
1901
- /**
1902
- * 类型工具类
1903
- */
1904
- declare class TypeUtil {
1905
- private static readonly PROTOTYPE_TAGS;
1906
- private static readonly TYPED_ARRAY_TAGS;
1907
- /**
1908
- * 获取值的 [[Prototype]] 标签
1909
- *
1910
- * @param value - 任意 JavaScript 值
1911
- * @returns 标准化的类型标签字符串
1912
- */
1913
- private static getPrototypeString;
1914
- /**
1915
- * 检查 value 是否为 string 类型
1916
- * - 当 `checkNullish` 为 `true` 时,会先 trim 再判断是否为空
1917
- *
1918
- * @param value 待检查值
1919
- * @param checkNullish 是否检查空字符串(含空白字符串),默认为 `false`
1920
- * @returns 是否为字符串
1921
- * @example
1922
- * ```ts
1923
- * TypeUtil.isString("abc"); // true
1924
- * TypeUtil.isString(""); // true
1925
- * TypeUtil.isString("", true); // false
1926
- * TypeUtil.isString(" ", true); // false
1927
- * TypeUtil.isString(" a ", true); // true
1928
- * ```
1929
- */
1930
- static isString(value: unknown, checkNullish?: boolean): value is string;
1931
- /**
1932
- * 检查 value 是否为 number 类型
1933
- * - 默认会调用 `TypeUtil.isNaN`(内部基于 `Number.isNaN`)过滤掉 `NaN`
1934
- *
1935
- * @param value 待检查值
1936
- * @param checkNaN 是否检查 `NaN`,默认为 `true`
1937
- * @returns 是否为 number
1938
- * @example
1939
- * ```ts
1940
- * TypeUtil.isNumber(1); // true
1941
- * TypeUtil.isNumber(NaN); // false (default)
1942
- * TypeUtil.isNumber(NaN, false); // true
1943
- * ```
1944
- */
1945
- static isNumber(value: unknown, checkNaN?: boolean): value is number;
1946
- /**
1947
- * 检查 value 是否为 NaN
1948
- * - 禁止使用全局 `isNaN`,其会先进行隐式数字转换,可能导致误判(例如 `isNaN("foo") === true`)
1949
- * - 使用 `Number.isNaN` 仅在值本身就是 `NaN` 时返回 `true`,语义更严格且更安全
1950
- *
1951
- * @param value 待检查值
1952
- * @returns 是否为 NaN
1953
- * @example
1954
- * ```ts
1955
- * TypeUtil.isNaN(NaN); // true
1956
- * ```
1957
- */
1958
- static isNaN(value: unknown): value is number;
1959
- /**
1960
- * 检查 value 是否为整数
1961
- *
1962
- * @param value 待检查值
1963
- * @param checkSafe 是否附加安全整数检查
1964
- * @returns 是否为整数
1965
- * @example
1966
- * ```ts
1967
- * TypeUtil.isInteger(1); // true
1968
- * TypeUtil.isInteger(1.1); // false
1969
- * ```
1970
- */
1971
- static isInteger(value: unknown, checkSafe?: boolean): value is number;
1972
- /**
1973
- * 检查 value 是否为正整数
1974
- * - 此函数中 `0` 不被视为正整数
1975
- *
1976
- * @param value 待检查值
1977
- * @param checkSafe 是否附加安全整数检查
1978
- * @example
1979
- * ```ts
1980
- * TypeUtil.isPositiveInteger(1); // true
1981
- * TypeUtil.isPositiveInteger(0); // false
1982
- * ```
1983
- */
1984
- static isPositiveInteger(value: unknown, checkSafe?: boolean): value is number;
1985
- /**
1986
- * 检查 value 是否为负整数
1987
- * - 此函数中 `0` 不被视为负整数
1988
- *
1989
- * @param value 待检查值
1990
- * @param checkSafe 是否附加安全整数检查
1991
- * @example
1992
- * ```ts
1993
- * TypeUtil.isNegativeInteger(-1); // true
1994
- * TypeUtil.isNegativeInteger(0); // false
1995
- * ```
1996
- */
1997
- static isNegativeInteger(value: unknown, checkSafe?: boolean): value is number;
1998
- /**
1999
- * 检查 value 是否为 Infinity
2000
- * - 排除 `NaN`
2001
- *
2002
- * @param value 待检查值
2003
- * @example
2004
- * ```ts
2005
- * TypeUtil.isInfinity(Infinity); // true
2006
- * TypeUtil.isInfinity(1); // false
2007
- * ```
2008
- */
2009
- static isInfinity(value: unknown): value is number;
2010
- /**
2011
- * 检查 value 是否类似 Infinity
2012
- * - 排除 `NaN`
2013
- *
2014
- * @param value 待检查值
2015
- * @example
2016
- * ```ts
2017
- * TypeUtil.isInfinityLike("Infinity"); // true
2018
- * TypeUtil.isInfinityLike("123"); // false
2019
- * ```
2020
- */
2021
- static isInfinityLike(value: unknown): boolean;
2022
- /**
2023
- * 检查 value 是否为 Boolean
2024
- * @param value 待检查值
2025
- * @returns 是否为 Boolean
2026
- * @example
2027
- * ```ts
2028
- * TypeUtil.isBoolean(false); // true
2029
- * ```
2030
- */
2031
- static isBoolean(value: unknown): value is boolean;
2032
- /**
2033
- * 检查 value 是否为 BigInt
2034
- * @param value 待检查值
2035
- * @returns 是否为 BigInt
2036
- * @example
2037
- * ```ts
2038
- * TypeUtil.isBigInt(1n); // true
2039
- * ```
2040
- */
2041
- static isBigInt(value: unknown): value is bigint;
2042
- /**
2043
- * 检查 value 是否为 Symbol
2044
- * @param value 待检查值
2045
- * @returns 是否为 Symbol
2046
- * @example
2047
- * ```ts
2048
- * TypeUtil.isSymbol(Symbol("a")); // true
2049
- * ```
2050
- */
2051
- static isSymbol(value: unknown): value is symbol;
2052
- /**
2053
- * 检查 value 是否为 undefined
2054
- * @param value 待检查值
2055
- * @returns 是否为 undefined
2056
- * @example
2057
- * ```ts
2058
- * TypeUtil.isUndefined(undefined); // true
2059
- * ```
2060
- */
2061
- static isUndefined(value: unknown): value is undefined;
2062
- /**
2063
- * 检查 value 是否为 null
2064
- * @param value 待检查值
2065
- * @returns 是否为 null
2066
- * @example
2067
- * ```ts
2068
- * TypeUtil.isNull(null); // true
2069
- * ```
2070
- */
2071
- static isNull(value: unknown): value is null;
2072
- /**
2073
- * 检查 value 是否为 null 或 undefined
2074
- * @param value 待检查值
2075
- * @returns 是否为 Nullish
2076
- * @example
2077
- * ```ts
2078
- * TypeUtil.isNullish(null); // true
2079
- * TypeUtil.isNullish(undefined); // true
2080
- * ```
2081
- */
2082
- static isNullish(value: unknown): value is null | undefined;
2083
- /**
2084
- * 检查 value 是否为 Function
2085
- * @param value 待检查值
2086
- * @returns 是否为 Function
2087
- * @example
2088
- * ```ts
2089
- * TypeUtil.isFunction(() => {}); // true
2090
- * ```
2091
- */
2092
- static isFunction(value: unknown): value is AnyFunction;
2093
- /**
2094
- * 检查 value 是否为 AsyncFunction
2095
- * @param value 待检查值
2096
- * @returns 是否为 AsyncFunction
2097
- * @example
2098
- * ```ts
2099
- * TypeUtil.isAsyncFunction(async () => {}); // true
2100
- * ```
2101
- */
2102
- static isAsyncFunction(value: unknown): value is AnyAsyncFunction;
2103
- /**
2104
- * 检查 value 是否为 GeneratorFunction
2105
- * @param value 待检查值
2106
- * @returns 是否为 GeneratorFunction
2107
- * @example
2108
- * ```ts
2109
- * TypeUtil.isGeneratorFunction(function * a () {}); // true
2110
- * ```
2111
- */
2112
- static isGeneratorFunction(value: unknown): value is AnyGeneratorFunction;
2113
- /**
2114
- * 检查 value 是否为 AsyncGeneratorFunction
2115
- * @param value 待检查值
2116
- * @returns 是否为 AsyncGeneratorFunction
2117
- * @example
2118
- * ```ts
2119
- * TypeUtil.isAsyncGeneratorFunction(async function * a () {}); // true
2120
- * ```
2121
- */
2122
- static isAsyncGeneratorFunction(value: unknown): value is AnyAsyncGeneratorFunction;
2123
- /**
2124
- * 检查 value 是否为 Promise
2125
- * @param value 待检查值
2126
- * @returns 是否为 Promise
2127
- * @example
2128
- * ```ts
2129
- * TypeUtil.isPromise(Promise.resolve(1)); // true
2130
- * ```
2131
- */
2132
- static isPromise(value: unknown): value is Promise<unknown>;
2133
- /**
2134
- * 检查 value 是否为 PromiseLike
2135
- * - 可识别拥有 then 方法的非 Promise 对象
2136
- * @param value 待检查值
2137
- * @returns 是否为 PromiseLike
2138
- * @example
2139
- * ```ts
2140
- * TypeUtil.isPromiseLike({ then: () => {} }); // true
2141
- * ```
2142
- */
2143
- static isPromiseLike(value: unknown): value is PromiseLike<unknown>;
2144
- /**
2145
- * 判断是否为普通对象类型
2146
- * - 可选是否检查原型为 `Object.prototype`,防止原型链污染
2147
- *
2148
- * @param value 待检查值
2149
- * @param prototypeCheck 是否进行原型检查,默认 `true`
2150
- * @returns 是否为 Plain Object (当 prototypeCheck=true) 或 object
2151
- * @example
2152
- * ```ts
2153
- * TypeUtil.isPlainObject({}); // true
2154
- * TypeUtil.isPlainObject([]); // false
2155
- * TypeUtil.isPlainObject(new Date()); // false
2156
- * TypeUtil.isPlainObject(new (class {})()); // false
2157
- * TypeUtil.isPlainObject(new (class {})(), false); // true
2158
- * TypeUtil.isPlainObject(Object.create(null)) // false
2159
- * TypeUtil.isPlainObject(Object.create(null), false) // true
2160
- * ```
2161
- */
2162
- static isPlainObject(value: unknown, prototypeCheck?: boolean): value is Record<PropertyKey, unknown>;
2163
- /**
2164
- * 判断是否为广义对象类型
2165
- *
2166
- * @param value 待检查值
2167
- * @returns 是否为对象
2168
- * @example
2169
- * ```ts
2170
- * TypeUtil.isObject({}); // true
2171
- * TypeUtil.isObject([]); // true
2172
- * TypeUtil.isObject(new Date()); // true
2173
- * TypeUtil.isObject(null); // false
2174
- * TypeUtil.isObject("string"); // false
2175
- * ```
2176
- */
2177
- static isObject(value: unknown): value is object;
2178
- /**
2179
- * 判断一个对象是否为有效的枚举
2180
- * - 枚举成员不能为空
2181
- * - 枚举成员的键不能具有数值名
2182
- * - 枚举成员的值必须类型一致且为 `string` 或 `number` 类型
2183
- * - 枚举成员的值不能重复
2184
- * - 枚举成员的值必须全部为双向映射或非双向映射
2185
- *
2186
- * @param enumeration 待检查值
2187
- * @returns [是否为有效的枚举, 是否为双向枚举]
2188
- * @example
2189
- * ```ts
2190
- * enum A { X, Y }
2191
- * TypeUtil.isEnumeration(A); // [true, true]
2192
- * ```
2193
- */
2194
- static isEnumeration(enumeration: PlainObject): [boolean, boolean];
2195
- /**
2196
- * 检查 value 是否为 Class
2197
- *
2198
- * @param value 待检查值
2199
- * @returns 是否为 Class
2200
- * @example
2201
- * ```ts
2202
- * class A {}
2203
- * TypeUtil.isClass(A); // true
2204
- * TypeUtil.isClass(() => {}); // false
2205
- * ```
2206
- */
2207
- static isClass(value: unknown): value is Class<AnyObject>;
2208
- /**
2209
- * 检查 value 是否为数组
2210
- *
2211
- * @param value 待检查值
2212
- * @returns 是否为数组
2213
- * @example
2214
- * ```ts
2215
- * TypeUtil.isArray([]); // true
2216
- * ```
2217
- */
2218
- static isArray(value: unknown): value is unknown[];
2219
- /**
2220
- * 检查 value 是否为 TypedArray
2221
- *
2222
- * @param value 待检查值
2223
- * @returns 是否为 TypedArray
2224
- * @example
2225
- * ```ts
2226
- * TypeUtil.isTypedArray(new Int8Array()); // true
2227
- * ```
2228
- */
2229
- static isTypedArray(value: unknown): value is TypedArray;
2230
- /**
2231
- * 检查 value 是否为 Map
2232
- * @param value 待检查值
2233
- * @returns 是否为 Map
2234
- * @example
2235
- * ```ts
2236
- * TypeUtil.isMap(new Map()); // true
2237
- * ```
2238
- */
2239
- static isMap(value: unknown): value is Map<unknown, unknown>;
2240
- /**
2241
- * 检查 value 是否为 WeakMap
2242
- * @param value 待检查值
2243
- * @returns 是否为 WeakMap
2244
- * @example
2245
- * ```ts
2246
- * TypeUtil.isWeakMap(new WeakMap()); // true
2247
- * ```
2248
- */
2249
- static isWeakMap(value: unknown): value is WeakMap<AnyObject, unknown>;
2250
- /**
2251
- * 检查 value 是否为 Set
2252
- * @param value 待检查值
2253
- * @returns 是否为 Set
2254
- * @example
2255
- * ```ts
2256
- * TypeUtil.isSet(new Set()); // true
2257
- * ```
2258
- */
2259
- static isSet(value: unknown): value is Set<unknown>;
2260
- /**
2261
- * 检查 value 是否为 WeakSet
2262
- * @param value 待检查值
2263
- * @returns 是否为 WeakSet
2264
- * @example
2265
- * ```ts
2266
- * TypeUtil.isWeakSet(new WeakSet()); // true
2267
- * ```
2268
- */
2269
- static isWeakSet(value: unknown): value is WeakSet<AnyObject>;
2270
- /**
2271
- * 检查 value 是否为 Blob
2272
- * @param value 待检查值
2273
- * @returns 是否为 Blob
2274
- * @example
2275
- * ```ts
2276
- * TypeUtil.isBlob(new Blob(["a"])); // true
2277
- * ```
2278
- */
2279
- static isBlob(value: unknown): value is Blob;
2280
- /**
2281
- * 检查 value 是否为 File
2282
- * @param value 待检查值
2283
- * @returns 是否为 File
2284
- * @example
2285
- * ```ts
2286
- * TypeUtil.isFile(new File(["a"], "a.txt")); // true
2287
- * ```
2288
- */
2289
- static isFile(value: unknown): value is File;
2290
- /**
2291
- * 检查 value 是否为 ReadableStream
2292
- * - Uses `Object.prototype.toString` where supported (modern browsers, Node.js ≥18).
2293
- * - Falls back to duck-typing in older environments.
2294
- * - Resistant to basic forgery, but not 100% secure in all polyfill scenarios.
2295
- * - ⚠️ Note: In older Node.js (<18) or with non-compliant polyfills, this may return false positives or negatives.
2296
- *
2297
- * @param value 待检查值
2298
- * @returns 是否为 ReadableStream
2299
- * @example
2300
- * ```ts
2301
- * TypeUtil.isReadableStream(new ReadableStream()); // true
2302
- * ```
2303
- */
2304
- static isReadableStream(value: unknown): value is ReadableStream;
2305
- /**
2306
- * 检查 value 是否为 Window
2307
- * @param value 待检查值
2308
- * @returns 是否为 Window
2309
- * @example
2310
- * ```ts
2311
- * TypeUtil.isWindow(window); // true
2312
- * ```
2313
- */
2314
- static isWindow(value: unknown): value is Window;
2315
- /**
2316
- * 检查 value 是否为 HTMLIFrameElement
2317
- * @param value 待检查值
2318
- * @returns 是否为 HTMLIFrameElement
2319
- * @example
2320
- * ```ts
2321
- * TypeUtil.isIframe(document.createElement("iframe")); // true
2322
- * ```
2323
- */
2324
- static isIframe(value: unknown): value is HTMLIFrameElement;
2325
- /**
2326
- * 检查 value 是否为 Date 对象
2327
- *
2328
- * @param value 待检查值
2329
- * @param invalidCheck 是否要求日期有效(非 Invalid Date)。默认 true
2330
- * - true: 仅当是有效 Date 对象时返回 true(排除 new Date('invalid'))
2331
- * - false: 只要 [[Prototype]] 是 Date 即返回 true(包含 Invalid Date)
2332
- * @returns 是否为 Date 对象,根据 invalidCheck 返回不同语义的 Date 判定
2333
- *
2334
- * @example
2335
- * ```ts
2336
- * TypeUtil.isDate(new Date()); // true
2337
- * TypeUtil.isDate(new Date('invalid')); // false
2338
- * TypeUtil.isDate(new Date('invalid'), false); // true
2339
- * TypeUtil.isDate(null); // false
2340
- * TypeUtil.isDate({}); // false
2341
- * ```
2342
- */
2343
- static isDate(value: unknown, invalidCheck?: boolean): value is Date;
2344
- /**
2345
- * 检查 value 是否为 Error 对象
2346
- * @param value 待检查值
2347
- * @returns 是否为 Error
2348
- * @example
2349
- * ```ts
2350
- * TypeUtil.isError(new Error("x")); // true
2351
- * ```
2352
- */
2353
- static isError(value: unknown): value is Error;
2354
- /**
2355
- * 检查 value 是否为 RegExp
2356
- * @param value 待检查值
2357
- * @returns 是否为 RegExp
2358
- * @example
2359
- * ```ts
2360
- * TypeUtil.isRegExp(/a/); // true
2361
- * ```
2362
- */
2363
- static isRegExp(value: unknown): value is RegExp;
2364
- /**
2365
- * 检查 value 是否为 WebSocket
2366
- * @param value 待检查值
2367
- * @returns 是否为 WebSocket
2368
- * @example
2369
- * ```ts
2370
- * TypeUtil.isWebSocket(new WebSocket("wss://echo.websocket.events")); // true
2371
- * ```
2372
- */
2373
- static isWebSocket(value: unknown): value is WebSocket;
2374
- /**
2375
- * 检查 value 是否为 URLSearchParams
2376
- * @param value 待检查值
2377
- * @returns 是否为 URLSearchParams
2378
- * @example
2379
- * ```ts
2380
- * TypeUtil.isURLSearchParams(new URLSearchParams("a=1")); // true
2381
- * ```
2382
- */
2383
- static isURLSearchParams(value: unknown): value is URLSearchParams;
2384
- /**
2385
- * 检查 value 是否为 AbortSignal
2386
- * @param value 待检查值
2387
- * @returns 是否为 AbortSignal
2388
- * @example
2389
- * ```ts
2390
- * TypeUtil.isAbortSignal(new AbortController().signal); // true
2391
- * ```
2392
- */
2393
- static isAbortSignal(value: unknown): value is AbortSignal;
2394
- /**
2395
- * 检查 value 是否为可迭代对象 (Iterable)
2396
- * @param value 待检查值
2397
- * @returns 是否为 Iterable
2398
- * @example
2399
- * ```ts
2400
- * TypeUtil.isIterable([1, 2]); // true
2401
- * ```
2402
- */
2403
- static isIterable(value: unknown): value is {
2404
- [Symbol.iterator]: () => Iterator<unknown>;
2405
- };
2406
- /**
2407
- * 检查 value 是否为 Falsy 值 (false, 0, "", null, undefined, NaN, 0n)
2408
- * - 处理非字符串形式的 falsy;字符串形式(`"null"`、`"0"` 等)请使用 `isFalsyLike`
2409
- *
2410
- * @param value 待检查值
2411
- * @returns 是否为 Falsy
2412
- * @example
2413
- * ```ts
2414
- * TypeUtil.isFalsy(0); // true
2415
- * ```
2416
- */
2417
- static isFalsy(value: unknown): boolean;
2418
- /**
2419
- * 检查 value 是否为 FalsyLike 值
2420
- * - 包含字符串形式的 `"null"`、`"undefined"`、`"false"`、`"0"` 等
2421
- *
2422
- * @param value 待检查值
2423
- * @returns 是否为 FalsyLike
2424
- * @example
2425
- * ```ts
2426
- * TypeUtil.isFalsyLike("false"); // true
2427
- * TypeUtil.isFalsyLike("hello"); // false
2428
- * ```
2429
- */
2430
- static isFalsyLike(value: unknown): boolean;
2431
- }
2432
- //#endregion
2433
- //#region src/validate/validateUtil.d.ts
2434
- /**
2435
- * 验证工具类
2436
- */
2437
- declare class ValidateUtil {
2438
- static _phone: RegExp;
2439
- /**
2440
- * 验证是否为手机号码
2441
- * @example
2442
- * ```ts
2443
- * ValidateUtil.isPhone("13800138000"); // true
2444
- * ```
2445
- */
2446
- static isPhone(input: string): boolean;
2447
- static _telephone: RegExp;
2448
- /**
2449
- * 验证是否为固定电话
2450
- * @example
2451
- * ```ts
2452
- * ValidateUtil.isTelephone("010-12345678"); // true
2453
- * ```
2454
- */
2455
- static isTelephone(input: string): boolean;
2456
- static _IMEI: RegExp;
2457
- /**
2458
- * 验证是否为移动设备识别码
2459
- * @example
2460
- * ```ts
2461
- * ValidateUtil.isIMEI("490154203237518"); // true
2462
- * ```
2463
- */
2464
- static isIMEI(input: string): boolean;
2465
- static _email: RegExp;
2466
- /**
2467
- * 验证是否为电子邮箱
2468
- * @example
2469
- * ```ts
2470
- * ValidateUtil.isEmail("dev@example.com"); // true
2471
- * ```
2472
- */
2473
- static isEmail(input: string): boolean;
2474
- static _link: RegExp;
2475
- /**
2476
- * 验证是否为 http(s) 链接
2477
- * @example
2478
- * ```ts
2479
- * ValidateUtil.isHttpLink("https://example.com/path"); // true
2480
- * ```
2481
- */
2482
- static isHttpLink(input: string): boolean;
2483
- static _portLink: RegExp;
2484
- /**
2485
- * 验证是否为端口号链接
2486
- * @example
2487
- * ```ts
2488
- * ValidateUtil.isPortLink("http://example.com:8080"); // true
2489
- * ```
2490
- */
2491
- static isPortLink(input: string): boolean;
2492
- static _thunderLink: RegExp;
2493
- /**
2494
- * 验证是否为迅雷链接
2495
- * @example
2496
- * ```ts
2497
- * ValidateUtil.isThunderLink("thunder://QUFodHRwOi8vZXhhbXBsZS5jb20vZmlsZQ=="); // true
2498
- * ```
2499
- */
2500
- static isThunderLink(input: string): boolean;
2501
- static _uscc: RegExp;
2502
- /**
2503
- * 验证是否为统一社会信用代码(USCC / USCI / USCCS)
2504
- * - 固定 18 位:1 位登记管理部门码 + 1 位机构类别码 + 6 位行政区划码 + 9 位主体标识码 + 1 位校验码
2505
- * - 字符集:数字 0-9 + 大写英文字母(排除 I、O、Z、S、V,防视觉混淆)
2506
- * - 第 1-2 位允许字母(如登记管理部门码 `A`,代表"其他"),第 3-8 位行政区划码为纯数字
2507
- *
2508
- * @param input 待校验字符串
2509
- * @returns 是否为合法格式的统一社会信用代码
2510
- * @example
2511
- * ```ts
2512
- * ValidateUtil.isUSCC("91350100M000100Y43"); // true
2513
- * ValidateUtil.isUSCC("A1350100M000100Y43"); // true (A 开头"其他"部门码)
2514
- * ```
2515
- */
2516
- static isUSCC(input: string): boolean;
2517
- /**
2518
- * 验证是否为统一社会信用代码(同 `isUSCC`)
2519
- * - USCC / USCI / USCCS 均指统一社会信用代码,固定 18 位
2520
- * - 15 位旧税务登记号在 2015 年"三证合一"前使用,现已作废,视为无效
2521
- *
2522
- * @param input 待校验字符串
2523
- * @returns 是否为合法代码
2524
- * @example
2525
- * ```ts
2526
- * ValidateUtil.isUSCCS("91350100M000100Y43"); // true (18位)
2527
- * ValidateUtil.isUSCCS("91350100M000100"); // false (15位旧号,已作废)
2528
- * ```
2529
- */
2530
- static isUSCCS(input: string): boolean;
2531
- static _dirPathWindows: RegExp;
2532
- /**
2533
- * 验证是否为 Windows 系统文件夹路径
2534
- * @example
2535
- * ```ts
2536
- * ValidateUtil.isDirPathWindows("C:\\Users\\pawover\\"); // true
2537
- * ```
2538
- */
2539
- static isDirPathWindows(input: string): boolean;
2540
- static _filePathWindows: RegExp;
2541
- /**
2542
- * 验证是否为 Windows 系统文件路径
2543
- * @example
2544
- * ```ts
2545
- * ValidateUtil.isFilePathWindows("C:\\Users\\pawover\\a.txt"); // true
2546
- * ```
2547
- */
2548
- static isFilePathWindows(input: string): boolean;
2549
- static _dirPathLinux: RegExp;
2550
- /**
2551
- * 验证是否为 Linux 系统文件夹路径
2552
- * @example
2553
- * ```ts
2554
- * ValidateUtil.isDirPathLinux("/usr/local/"); // true
2555
- * ```
2556
- */
2557
- static isDirPathLinux(input: string): boolean;
2558
- static _filePathLinux: RegExp;
2559
- /**
2560
- * 验证是否为 Linux 系统文件路径
2561
- * @example
2562
- * ```ts
2563
- * ValidateUtil.isFilePathLinux("/usr/local/bin/node"); // true
2564
- * ```
2565
- */
2566
- static isFilePathLinux(input: string): boolean;
2567
- static _EVCarNumber: RegExp;
2568
- /**
2569
- * 验证是否为新能源车牌号
2570
- * @example
2571
- * ```ts
2572
- * ValidateUtil.isEVCarNumber("粤AD12345"); // true
2573
- * ```
2574
- */
2575
- static isEVCarNumber(input: string): boolean;
2576
- static _GVCarNumber: RegExp;
2577
- /**
2578
- * 验证是否为燃油车车牌号
2579
- * @example
2580
- * ```ts
2581
- * ValidateUtil.isGVCarNumber("粤B12345"); // true
2582
- * ```
2583
- */
2584
- static isGVCarNumber(input: string): boolean;
2585
- static _chineseName: RegExp;
2586
- /**
2587
- * 验证是否为中文姓名
2588
- * @example
2589
- * ```ts
2590
- * ValidateUtil.isChineseName("张三"); // true
2591
- * ```
2592
- */
2593
- static isChineseName(input: string): boolean;
2594
- static _chineseId: RegExp;
2595
- /**
2596
- * 验证是否为中国身份证号
2597
- * - ⚠️ 仅校验 18 位格式(含生日合法性),**不验证第 18 位校验位**,伪造码可通过校验
2598
- * @example
2599
- * ```ts
2600
- * ValidateUtil.isChineseID("11010519491231002X"); // true
2601
- * ```
2602
- */
2603
- static isChineseID(input: string): boolean;
2604
- static _chineseProvince: RegExp;
2605
- /**
2606
- * 验证是否为中国省份
2607
- * @example
2608
- * ```ts
2609
- * ValidateUtil.isChineseProvince("浙江"); // true
2610
- * ```
2611
- */
2612
- static isChineseProvince(input: string): boolean;
2613
- static _chineseNation: RegExp;
2614
- /**
2615
- * 验证是否为中华民族
2616
- * @example
2617
- * ```ts
2618
- * ValidateUtil.isChineseNation("汉族"); // true
2619
- * ```
2620
- */
2621
- static isChineseNation(input: string): boolean;
2622
- static _letter: RegExp;
2623
- /**
2624
- * 验证是否只包含字母
2625
- * @example
2626
- * ```ts
2627
- * ValidateUtil.isLetter("abcDEF"); // true
2628
- * ```
2629
- */
2630
- static isLetter(input: string): boolean;
2631
- static _letterLowercase: RegExp;
2632
- /**
2633
- * 验证是否只包含小写字母
2634
- * @example
2635
- * ```ts
2636
- * ValidateUtil.isLetterLowercase("abc"); // true
2637
- * ```
2638
- */
2639
- static isLetterLowercase(input: string): boolean;
2640
- static _letterUppercase: RegExp;
2641
- /**
2642
- * 验证是否只包含大写字母
2643
- * @example
2644
- * ```ts
2645
- * ValidateUtil.isLetterUppercase("ABC"); // true
2646
- * ```
2647
- */
2648
- static isLetterUppercase(input: string): boolean;
2649
- static _letterOmit: RegExp;
2650
- /**
2651
- * 验证是否不包含字母
2652
- * @example
2653
- * ```ts
2654
- * ValidateUtil.isLetterOmit("123_-"); // true
2655
- * ```
2656
- */
2657
- static isLetterOmit(input: string): boolean;
2658
- static _LetterAndNumber: RegExp;
2659
- /**
2660
- * 验证是否为数字和字母组合
2661
- * @example
2662
- * ```ts
2663
- * ValidateUtil.isLetterAndNumber("A1B2"); // true
2664
- * ```
2665
- */
2666
- static isLetterAndNumber(input: string): boolean;
2667
- static _signedFloat: RegExp;
2668
- /**
2669
- * 验证是否为有符号浮点数
2670
- * @example
2671
- * ```ts
2672
- * ValidateUtil.isSignedFloat("-12.34"); // true
2673
- * ```
2674
- */
2675
- static isSignedFloat(input: string): boolean;
2676
- static _unsignedFloat: RegExp;
2677
- /**
2678
- * 验证是否为无符号浮点数
2679
- * @example
2680
- * ```ts
2681
- * ValidateUtil.isUnsignedFloat("12.34"); // true
2682
- * ```
2683
- */
2684
- static isUnsignedFloat(input: string): boolean;
2685
- static _signedInteger: RegExp;
2686
- /**
2687
- * 验证是否为有符号整数
2688
- * @example
2689
- * ```ts
2690
- * ValidateUtil.isSignedInteger("-12"); // true
2691
- * ```
2692
- */
2693
- static isSignedInteger(input: string): boolean;
2694
- static _unsignedInteger: RegExp;
2695
- /**
2696
- * 验证是否为无符号整数
2697
- * @example
2698
- * ```ts
2699
- * ValidateUtil.isUnsignedInteger("12"); // true
2700
- * ```
2701
- */
2702
- static isUnsignedInteger(input: string): boolean;
2703
- static _spaceInclude: RegExp;
2704
- /**
2705
- * 验证是否包含空格
2706
- * @example
2707
- * ```ts
2708
- * ValidateUtil.isSpaceInclude("a b"); // true
2709
- * ```
2710
- */
2711
- static isSpaceInclude(input: string): boolean;
2712
- static _spaceStart: RegExp;
2713
- /**
2714
- * 验证是否以空格开头
2715
- * @example
2716
- * ```ts
2717
- * ValidateUtil.isSpaceStart(" abc"); // true
2718
- * ```
2719
- */
2720
- static isSpaceStart(input: string): boolean;
2721
- static _spaceEnd: RegExp;
2722
- /**
2723
- * 验证是否以空格结尾
2724
- * @example
2725
- * ```ts
2726
- * ValidateUtil.isSpaceEnd("abc "); // true
2727
- * ```
2728
- */
2729
- static isSpaceEnd(input: string): boolean;
2730
- /**
2731
- * 验证是否以空格开头或结尾
2732
- * @example
2733
- * ```ts
2734
- * ValidateUtil.isSpaceStartOrEnd(" abc"); // true
2735
- * ```
2736
- */
2737
- static isSpaceStartOrEnd(input: string): boolean;
2738
- }
2739
- //#endregion
2740
- export { ArrayUtil, type CurrencyCode, type CurrencyLocale, CurrencyUtil, DateTimeUtil, EnvUtil, type FormatterOptions, FunctionUtil, type MatchFunction, MimeUtil, NumberUtil, ObjectUtil, StringUtil, type THEME_MODE_TYPE, type THEME_TYPE, ThemeUtil, TreeUtil, TypeUtil, ValidateUtil, type ZipOptions };