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