@pawover/kit 0.0.0-beta.45 → 0.0.0-beta.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +52 -82
- package/{dist/hooks-alova.d.ts → packages/hooks/dist/alova.d.ts} +4 -5
- package/{dist/hooks-alova.js → packages/hooks/dist/alova.js} +3 -5
- package/packages/hooks/dist/index.d.ts +1 -0
- package/packages/hooks/dist/index.js +0 -0
- package/packages/hooks/dist/metadata.json +16 -0
- package/{dist/hooks-react.d.ts → packages/hooks/dist/react.d.ts} +76 -72
- package/packages/hooks/dist/react.js +4419 -0
- package/packages/utils/dist/index.d.ts +4293 -0
- package/packages/utils/dist/index.js +1527 -0
- package/packages/utils/dist/math.d.ts +54 -0
- package/packages/utils/dist/math.js +56 -0
- package/packages/utils/dist/metadata.json +14 -0
- package/packages/utils/dist/string-CESQdidv.js +793 -0
- package/packages/utils/dist/vite.d.ts +16 -0
- package/packages/utils/dist/vite.js +26 -0
- package/packages/zod/dist/index.d.ts +58 -0
- package/packages/zod/dist/index.js +61 -0
- package/dist/enums.d.ts +0 -2
- package/dist/enums.js +0 -145
- package/dist/enums.js.map +0 -1
- package/dist/except-6l9Qdmn1.d.ts +0 -986
- package/dist/except-6l9Qdmn1.d.ts.map +0 -1
- package/dist/hooks-alova.d.ts.map +0 -1
- package/dist/hooks-alova.js.map +0 -1
- package/dist/hooks-react.d.ts.map +0 -1
- package/dist/hooks-react.js +0 -166
- package/dist/hooks-react.js.map +0 -1
- package/dist/index-DsR_kNCf.d.ts +0 -18
- package/dist/index-DsR_kNCf.d.ts.map +0 -1
- package/dist/index-JKtXbRi8.d.ts +0 -149
- package/dist/index-JKtXbRi8.d.ts.map +0 -1
- package/dist/index.d.ts +0 -3736
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -2
- package/dist/patches-fetchEventSource.d.ts +0 -87
- package/dist/patches-fetchEventSource.d.ts.map +0 -1
- package/dist/patches-fetchEventSource.js +0 -200
- package/dist/patches-fetchEventSource.js.map +0 -1
- package/dist/utils-B7AhGrZp.js +0 -2042
- package/dist/utils-B7AhGrZp.js.map +0 -1
- package/dist/value-of-Dz22arsm.d.ts +0 -26
- package/dist/value-of-Dz22arsm.d.ts.map +0 -1
- package/dist/vite.d.ts +0 -12
- package/dist/vite.d.ts.map +0 -1
- package/dist/vite.js +0 -23
- package/dist/vite.js.map +0 -1
- package/dist/zod.d.ts +0 -112
- package/dist/zod.d.ts.map +0 -1
- package/dist/zod.js +0 -112
- package/dist/zod.js.map +0 -1
- package/metadata.json +0 -184
|
@@ -0,0 +1,4293 @@
|
|
|
1
|
+
//#region src/array/index.type.d.ts
|
|
2
|
+
type MatchFunction<T, R = unknown> = (row: T, index: number) => R;
|
|
3
|
+
//#endregion
|
|
4
|
+
//#region src/array/arrayUtil.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* 数组工具类
|
|
7
|
+
*/
|
|
8
|
+
declare class ArrayUtil {
|
|
9
|
+
/**
|
|
10
|
+
* 构造数组
|
|
11
|
+
* @param candidate 待构造项
|
|
12
|
+
* @param checkEmpty 是否检查 `undefined` 和 `null`,默认为 `true`
|
|
13
|
+
* @returns 构造后的数组
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* ArrayUtil.cast(1); // [1]
|
|
17
|
+
* ArrayUtil.cast([1, 2]); // [1, 2]
|
|
18
|
+
* ArrayUtil.cast(null); // []
|
|
19
|
+
* ArrayUtil.cast(undefined); // []
|
|
20
|
+
* ArrayUtil.cast(null, false); // [null]
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
static cast<T>(candidate: T | T[] | null | undefined, checkEmpty?: true): NonNullable<T>[];
|
|
24
|
+
static cast<T>(candidate: T | T[] | null | undefined, checkEmpty?: false): T[];
|
|
25
|
+
/**
|
|
26
|
+
* 获取数组第一项
|
|
27
|
+
*
|
|
28
|
+
* @param initialList 初始数组
|
|
29
|
+
* @param fallback 回退值
|
|
30
|
+
* @returns 数组第一项,如果为空则返回回退值
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* ArrayUtil.first([1, 2]); // 1
|
|
34
|
+
* ArrayUtil.first([], 0); // 0
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
static first<T>(initialList: readonly T[]): T | undefined;
|
|
38
|
+
static first<T>(initialList: readonly T[], fallback: T): T;
|
|
39
|
+
/**
|
|
40
|
+
* 获取数组最后一项
|
|
41
|
+
*
|
|
42
|
+
* @param initialList 初始数组
|
|
43
|
+
* @param fallback 回退值
|
|
44
|
+
* @returns 数组最后一项,如果为空则返回回退值
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* ArrayUtil.last([1, 2, 3]); // 3
|
|
48
|
+
* ArrayUtil.last([], 0); // 0
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
static last<T>(initialList: readonly T[]): T | undefined;
|
|
52
|
+
static last<T>(initialList: readonly T[], fallback: T): T;
|
|
53
|
+
/**
|
|
54
|
+
* 数组竞选
|
|
55
|
+
* - 返回在匹配函数的比较条件中获胜的最终项目,适用于更复杂的最小值/最大值计算
|
|
56
|
+
*
|
|
57
|
+
* @param initialList 数组
|
|
58
|
+
* @param match 匹配函数
|
|
59
|
+
* @returns 获胜的元素,如果数组为空或参数无效则返回 `null`
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* const list = [1, 10, 5];
|
|
63
|
+
* ArrayUtil.compete(list, (a, b) => (a > b ? a : b)); // 10
|
|
64
|
+
* ArrayUtil.compete(list, (a, b) => (a < b ? a : b)); // 1
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
static compete<T>(initialList: readonly T[], match: (a: T, b: T, index: number) => T): T | null;
|
|
68
|
+
/**
|
|
69
|
+
* 统计数组的项目出现次数
|
|
70
|
+
* - 通过给定的标识符匹配函数,返回一个对象,其中键是回调函数返回的 key 值,每个值是一个整数,表示该 key 出现的次数
|
|
71
|
+
*
|
|
72
|
+
* @param initialList 初始数组
|
|
73
|
+
* @param match 匹配函数
|
|
74
|
+
* @returns 统计对象
|
|
75
|
+
* @example
|
|
76
|
+
* ```ts
|
|
77
|
+
* const list = ["a", "b", "a", "c"];
|
|
78
|
+
* ArrayUtil.count(list, (x) => x); // { a: 2, b: 1, c: 1 }
|
|
79
|
+
*
|
|
80
|
+
* const users = [{ id: 1, group: "A" }, { id: 2, group: "B" }, { id: 3, group: "A" }];
|
|
81
|
+
* ArrayUtil.count(users, (u) => u.group); // { A: 2, B: 1 }
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
static count<T, K extends PropertyKey>(initialList: readonly T[], match: MatchFunction<T, K>): Record<string, number>;
|
|
85
|
+
/**
|
|
86
|
+
* 获取数组差集
|
|
87
|
+
* - 返回在 `initialList` 中存在,但在 `diffList` 中不存在的元素
|
|
88
|
+
*
|
|
89
|
+
* @param initialList 初始数组
|
|
90
|
+
* @param diffList 对比数组
|
|
91
|
+
* @param match 匹配函数
|
|
92
|
+
* @returns 差集数组
|
|
93
|
+
* @example
|
|
94
|
+
* ```ts
|
|
95
|
+
* ArrayUtil.difference([1, 2, 3], [2, 3, 4]); // [1]
|
|
96
|
+
* ArrayUtil.difference([{ id: 1 }, { id: 2 }], [{ id: 2 }], (x) => x.id); // [{ id: 1 }]
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
static difference<T>(initialList: readonly T[], diffList: readonly T[], match?: (row: T, index: number) => unknown): T[];
|
|
100
|
+
/**
|
|
101
|
+
* 获取数组交集
|
|
102
|
+
* - 返回在 `initialList` 和 `diffList` 中都存在的元素
|
|
103
|
+
*
|
|
104
|
+
* @param initialList 初始数组
|
|
105
|
+
* @param diffList 对比数组
|
|
106
|
+
* @param match 匹配函数
|
|
107
|
+
* @returns 交集数组
|
|
108
|
+
* @example
|
|
109
|
+
* ```ts
|
|
110
|
+
* ArrayUtil.intersection([1, 2], [2, 3]); // [2]
|
|
111
|
+
* ArrayUtil.intersection([{ id: 1 }, { id: 2 }], [{ id: 2 }], (x) => x.id); // [{ id: 2 }]
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
static intersection<T>(initialList: readonly T[], diffList: readonly T[]): T[];
|
|
115
|
+
static intersection<T, D = T>(initialList: readonly T[], diffList: readonly D[], match: MatchFunction<T>): T[];
|
|
116
|
+
/**
|
|
117
|
+
* 数组合并
|
|
118
|
+
* - 如果未提供 `match` 函数,则合并两个数组并去重(Union)
|
|
119
|
+
* - 如果提供了 `match` 函数,则仅更新 `initialList` 中匹配到的项(Left Join Update),不会追加 `mergeList` 中新增的项
|
|
120
|
+
*
|
|
121
|
+
* @param initialList 初始数组
|
|
122
|
+
* @param mergeList 待合并数组
|
|
123
|
+
* @param match 匹配函数
|
|
124
|
+
* @returns 合并后的数组
|
|
125
|
+
* @example
|
|
126
|
+
* ```ts
|
|
127
|
+
* // 基础合并去重
|
|
128
|
+
* ArrayUtil.merge([1, 2], [2, 3]); // [1, 2, 3]
|
|
129
|
+
* ArrayUtil.merge([], [1, 2, 3]); // [1, 2, 3]
|
|
130
|
+
*
|
|
131
|
+
* // 按条件更新
|
|
132
|
+
* const source = [{ id: 1, val: "a" }, { id: 2, val: "b" }];
|
|
133
|
+
* const update = [{ id: 2, val: "new" }, { id: 3, val: "c" }];
|
|
134
|
+
* ArrayUtil.merge(source, update, (x) => x.id); // [{ id: 1, val: "a" }, { id: 2, val: "new" }] -> id:3 被忽略
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
static merge<T>(initialList: readonly T[], mergeList: readonly T[]): T[];
|
|
138
|
+
static merge<T, D = T>(initialList: readonly T[], mergeList: readonly D[], match: MatchFunction<T>): T[];
|
|
139
|
+
/**
|
|
140
|
+
* 数组选择
|
|
141
|
+
* - 一次性应用 `filter` 和 `map` 操作
|
|
142
|
+
*
|
|
143
|
+
* @param initialList 初始数组
|
|
144
|
+
* @param filter filter 函数
|
|
145
|
+
* @param mapper map 函数
|
|
146
|
+
* @returns 处理后的新数组
|
|
147
|
+
* @example
|
|
148
|
+
* ```ts
|
|
149
|
+
* const list = [1, 2, 3, 4];
|
|
150
|
+
* ArrayUtil.pick(list, (n) => n % 2 === 0); // [2, 4]
|
|
151
|
+
* ArrayUtil.pick(list, (n) => n % 2 === 0, (n) => n * 2); // [4, 8]
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
static pick<const T>(initialList: readonly T[], filter: (row: T, index: number) => boolean): T[];
|
|
155
|
+
static pick<const T, K = T>(initialList: readonly T[], filter: (row: T, index: number) => boolean, mapper: (row: T, index: number) => K): K[];
|
|
156
|
+
/**
|
|
157
|
+
* 数组项替换
|
|
158
|
+
* - 在给定的数组中,替换符合匹配函数结果的项目
|
|
159
|
+
* - 只替换第一个匹配项
|
|
160
|
+
*
|
|
161
|
+
* @param initialList 初始数组
|
|
162
|
+
* @param newItem 替换项
|
|
163
|
+
* @param match 匹配函数
|
|
164
|
+
* @returns 替换后的新数组
|
|
165
|
+
* @example
|
|
166
|
+
* ```ts
|
|
167
|
+
* ArrayUtil.replace([1, 2, 3], 4, (n) => n === 2); // [1, 4, 3]
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
static replace<const T>(initialList: readonly T[], newItem: T, match: MatchFunction<T, boolean>): T[];
|
|
171
|
+
static replace<const T, K extends T>(initialList: readonly T[], newItem: K, match: MatchFunction<T, boolean>): T[];
|
|
172
|
+
static replace<const T, K>(initialList: readonly T[], newItem: K, match: MatchFunction<T, boolean>): (T | K)[];
|
|
173
|
+
/**
|
|
174
|
+
* 数组项替换并移动
|
|
175
|
+
* - 在给定的数组中,替换并移动符合匹配函数结果的项目
|
|
176
|
+
* - 只替换和移动第一个匹配项
|
|
177
|
+
* - 未匹配时,根据 `position` 在指定位置插入 `newItem`
|
|
178
|
+
*
|
|
179
|
+
* @param initialList 初始数组
|
|
180
|
+
* @param newItem 替换项
|
|
181
|
+
* @param match 匹配函数
|
|
182
|
+
* @param position 移动位置,可选 `start` | `end` | 索引位置, 默认为 `end`
|
|
183
|
+
* @returns
|
|
184
|
+
* @example
|
|
185
|
+
* ```ts
|
|
186
|
+
* ArrayUtil.replaceMove([1, 2, 3, 4], 5, (n) => n === 2, 0); // [5, 1, 3, 4]
|
|
187
|
+
* ArrayUtil.replaceMove([1, 2, 3, 4], 5, (n) => n === 2, 2); // [1, 3, 5, 4]
|
|
188
|
+
* ArrayUtil.replaceMove([1, 2, 3, 4], 5, (n) => n === 2, "start"); // [5, 1, 3, 4]
|
|
189
|
+
* ArrayUtil.replaceMove([1, 2, 3, 4], 5, (n) => n === 2); // [1, 3, 4, 5]
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
static replaceMove<const T>(initialList: readonly T[], newItem: T, match: MatchFunction<T, boolean>, position?: "start" | "end" | number): T[];
|
|
193
|
+
/**
|
|
194
|
+
* 数组切分
|
|
195
|
+
* - 将数组以指定的长度切分后,组合在高维数组中
|
|
196
|
+
*
|
|
197
|
+
* @param initialList 初始数组
|
|
198
|
+
* @param size 分割尺寸,默认 `10`
|
|
199
|
+
* @returns 切分后的二维数组
|
|
200
|
+
* @example
|
|
201
|
+
* ```ts
|
|
202
|
+
* ArrayUtil.split([1, 2, 3, 4, 5], 2); // [[1, 2], [3, 4], [5]]
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
205
|
+
static split<T>(initialList: readonly T[], size?: number): T[][];
|
|
206
|
+
/**
|
|
207
|
+
* 数组分组过滤
|
|
208
|
+
* - 给定一个数组和一个条件,返回一个由两个数组组成的元组,其中第一个数组包含所有满足条件的项,第二个数组包含所有不满足条件的项
|
|
209
|
+
*
|
|
210
|
+
* @param initialList 初始数组
|
|
211
|
+
* @param match 条件匹配函数
|
|
212
|
+
* @returns [满足条件的项[], 不满足条件的项[]]
|
|
213
|
+
* @example
|
|
214
|
+
* ```ts
|
|
215
|
+
* ArrayUtil.fork([1, 2, 3, 4], (n) => n % 2 === 0); // [[2, 4], [1, 3]]
|
|
216
|
+
* ```
|
|
217
|
+
*/
|
|
218
|
+
static fork<T>(initialList: readonly T[], match: MatchFunction<T, boolean>): [T[], T[]];
|
|
219
|
+
/**
|
|
220
|
+
* 数组解压
|
|
221
|
+
* - `ArrayUtil.zip` 的反向操作
|
|
222
|
+
*
|
|
223
|
+
* @param arrayList 压缩后的数组
|
|
224
|
+
* @returns 解压后的二维数组
|
|
225
|
+
* @example
|
|
226
|
+
* ```ts
|
|
227
|
+
* ArrayUtil.unzip([[1, "a"], [2, "b"]]); // [[1, 2], ["a", "b"]]
|
|
228
|
+
* ```
|
|
229
|
+
*/
|
|
230
|
+
static unzip<T>(arrayList: readonly (readonly T[])[]): T[][];
|
|
231
|
+
/**
|
|
232
|
+
* 数组压缩
|
|
233
|
+
* - 将多个数组的元素按索引组合成元组
|
|
234
|
+
*
|
|
235
|
+
* @param arrays 多个数组
|
|
236
|
+
* @returns 压缩后的元组数组
|
|
237
|
+
* @example
|
|
238
|
+
* ```ts
|
|
239
|
+
* ArrayUtil.zip([1, 2], ["a", "b"]); // [[1, "a"], [2, "b"]]
|
|
240
|
+
* ```
|
|
241
|
+
*/
|
|
242
|
+
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][];
|
|
243
|
+
static zip<T1, T2, T3, T4>(array1: readonly T1[], array2: readonly T2[], array3: readonly T3[], array4: readonly T4[]): [T1, T2, T3, T4][];
|
|
244
|
+
static zip<T1, T2, T3>(array1: readonly T1[], array2: readonly T2[], array3: readonly T3[]): [T1, T2, T3][];
|
|
245
|
+
static zip<T1, T2>(array1: readonly T1[], array2: readonly T2[]): [T1, T2][];
|
|
246
|
+
static zip(): [];
|
|
247
|
+
/**
|
|
248
|
+
* 数组压缩为对象
|
|
249
|
+
* - 将键数组和值(数组、函数或静态值)组合成对象
|
|
250
|
+
*
|
|
251
|
+
* @param keys 键数组
|
|
252
|
+
* @param values 值数组、生成值的函数或静态值
|
|
253
|
+
* @returns 生成的对象
|
|
254
|
+
* @example
|
|
255
|
+
* ```ts
|
|
256
|
+
* ArrayUtil.zipToObject(["a", "b"], [1, 2]); // { a: 1, b: 2 }
|
|
257
|
+
* ArrayUtil.zipToObject(["a", "b"], (k, i) => k + i); // { a: "a0", b: "b1" }
|
|
258
|
+
* ArrayUtil.zipToObject(["a", "b"], 1); // { a: 1, b: 1 }
|
|
259
|
+
* ```
|
|
260
|
+
*/
|
|
261
|
+
static zipToObject<const K extends PropertyKey, const V>(keys: readonly K[], array: readonly V[]): Record<K, V>;
|
|
262
|
+
static zipToObject<const K extends PropertyKey, const V>(keys: readonly K[], match: MatchFunction<K, V>): Record<K, V>;
|
|
263
|
+
static zipToObject<const K extends PropertyKey, const V>(keys: readonly K[], value: V): Record<K, V>;
|
|
264
|
+
}
|
|
265
|
+
//#endregion
|
|
266
|
+
//#region src/dateTime/dateTimeUtil.d.ts
|
|
267
|
+
/**
|
|
268
|
+
* 日期工具类
|
|
269
|
+
*/
|
|
270
|
+
declare class DateTimeUtil {
|
|
271
|
+
/**
|
|
272
|
+
* 每秒的毫秒数
|
|
273
|
+
*/
|
|
274
|
+
static readonly MILLISECONDS_PER_SECOND: number;
|
|
275
|
+
/**
|
|
276
|
+
* 每分钟的秒数
|
|
277
|
+
*/
|
|
278
|
+
static readonly SECOND_PER_MINUTE: number;
|
|
279
|
+
/**
|
|
280
|
+
* 每小时的分钟数
|
|
281
|
+
*/
|
|
282
|
+
static readonly MINUTE_PER_HOUR: number;
|
|
283
|
+
/**
|
|
284
|
+
* 每小时的秒数
|
|
285
|
+
*/
|
|
286
|
+
static readonly SECOND_PER_HOUR: number;
|
|
287
|
+
/**
|
|
288
|
+
* 每天小时数
|
|
289
|
+
*/
|
|
290
|
+
static readonly HOUR_PER_DAY: number;
|
|
291
|
+
/**
|
|
292
|
+
* 每天秒数
|
|
293
|
+
*/
|
|
294
|
+
static readonly SECOND_PER_DAY: number;
|
|
295
|
+
/**
|
|
296
|
+
* 每周天数
|
|
297
|
+
*/
|
|
298
|
+
static readonly DAY_PER_WEEK: number;
|
|
299
|
+
/**
|
|
300
|
+
* 每月天数
|
|
301
|
+
*/
|
|
302
|
+
static readonly DAY_PER_MONTH: number;
|
|
303
|
+
/**
|
|
304
|
+
* 每年天数
|
|
305
|
+
*/
|
|
306
|
+
static readonly DAY_PER_YEAR: number;
|
|
307
|
+
/**
|
|
308
|
+
* 每年月数
|
|
309
|
+
*/
|
|
310
|
+
static readonly MONTH_PER_YEAR: number;
|
|
311
|
+
/**
|
|
312
|
+
* 每年平均周
|
|
313
|
+
*/
|
|
314
|
+
static readonly WEEK_PER_YEAR: number;
|
|
315
|
+
/**
|
|
316
|
+
* 每月平均周
|
|
317
|
+
*/
|
|
318
|
+
static readonly WEEK_PER_MONTH: number;
|
|
319
|
+
static readonly FORMAT: {
|
|
320
|
+
readonly ISO_DATE: "yyyy-MM-dd";
|
|
321
|
+
readonly ISO_TIME: "HH:mm:ss";
|
|
322
|
+
readonly ISO_DATE_TIME: "yyyy-MM-dd HH:mm:ss";
|
|
323
|
+
readonly ISO_DATE_TIME_MS: "yyyy-MM-dd HH:mm:ss.SSS";
|
|
324
|
+
readonly ISO_DATETIME_TZ: "yyyy-MM-dd'T'HH:mm:ssXXX";
|
|
325
|
+
readonly ISO_DATETIME_TZ_MS: "yyyy-MM-dd'T'HH:mm:ss.SSSXXX";
|
|
326
|
+
readonly US_DATE: "MM/dd/yyyy";
|
|
327
|
+
readonly US_DATE_TIME: "MM/dd/yyyy HH:mm:ss";
|
|
328
|
+
readonly US_DATE_SHORT_YEAR: "MM/dd/yy";
|
|
329
|
+
readonly EU_DATE: "dd/MM/yyyy";
|
|
330
|
+
readonly EU_DATE_TIME: "dd/MM/yyyy HH:mm:ss";
|
|
331
|
+
readonly CN_DATE: "yyyy年MM月dd日";
|
|
332
|
+
readonly CN_DATE_TIME: "yyyy年MM月dd日 HH时mm分ss秒";
|
|
333
|
+
readonly CN_DATE_WEEKDAY: "yyyy年MM月dd日 EEE";
|
|
334
|
+
readonly CN_WEEKDAY_FULL: "EEEE";
|
|
335
|
+
readonly SHORT_DATE: "yy-MM-dd";
|
|
336
|
+
readonly SHORT_DATE_SLASH: "yy/MM/dd";
|
|
337
|
+
readonly MONTH_DAY: "MM-dd";
|
|
338
|
+
readonly MONTH_DAY_CN: "MM月dd日";
|
|
339
|
+
readonly DATE_WITH_WEEKDAY_SHORT: "yyyy-MM-dd (EEE)";
|
|
340
|
+
readonly DATE_WITH_WEEKDAY_FULL: "yyyy-MM-dd (EEEE)";
|
|
341
|
+
readonly TIME_24: "HH:mm:ss";
|
|
342
|
+
readonly TIME_24_NO_SEC: "HH:mm";
|
|
343
|
+
readonly TIME_12: "hh:mm:ss a";
|
|
344
|
+
readonly TIME_12_NO_SEC: "hh:mm a";
|
|
345
|
+
readonly TIMESTAMP: "yyyyMMddHHmmss";
|
|
346
|
+
readonly TIMESTAMP_MS: "yyyyMMddHHmmssSSS";
|
|
347
|
+
readonly RFC2822: "EEE, dd MMM yyyy HH:mm:ss xxx";
|
|
348
|
+
readonly READABLE_DATE: "MMM dd, yyyy";
|
|
349
|
+
readonly READABLE_DATE_TIME: "MMM dd, yyyy HH:mm";
|
|
350
|
+
readonly COMPACT_DATETIME: "yyyyMMdd_HHmmss";
|
|
351
|
+
};
|
|
352
|
+
/**
|
|
353
|
+
* 获取当前时区信息
|
|
354
|
+
*
|
|
355
|
+
* @returns 时区信息对象 (UTC偏移和时区名称)
|
|
356
|
+
* @example
|
|
357
|
+
* ```ts
|
|
358
|
+
* DateTimeUtil.getTimeZone(); // { UTC: "UTC+8", timeZone: "Asia/Shanghai" }
|
|
359
|
+
* ```
|
|
360
|
+
*/
|
|
361
|
+
static getTimeZone(): {
|
|
362
|
+
UTC: string;
|
|
363
|
+
timeZone: string;
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
//#endregion
|
|
367
|
+
//#region src/env/envUtil.d.ts
|
|
368
|
+
/**
|
|
369
|
+
* 环境检查工具类
|
|
370
|
+
*/
|
|
371
|
+
declare class EnvUtil {
|
|
372
|
+
private static readonly _isBrowser;
|
|
373
|
+
private static readonly _isWebWorker;
|
|
374
|
+
private static readonly _isReactNative;
|
|
375
|
+
static isBrowser(): boolean;
|
|
376
|
+
static isWebWorker(): boolean;
|
|
377
|
+
static isReactNative(): boolean;
|
|
378
|
+
/**
|
|
379
|
+
* 检查是否在 iframe 环境中
|
|
380
|
+
*/
|
|
381
|
+
static isIframe(): boolean;
|
|
382
|
+
/**
|
|
383
|
+
* 检测当前设备是否为桌面设备
|
|
384
|
+
*
|
|
385
|
+
* @param minWidth - 桌面设备最小宽度(默认 1200px)
|
|
386
|
+
* @param minScreenSize - 桌面设备最小屏幕尺寸(默认 10英寸)
|
|
387
|
+
* @param dpi - 标准 DPI 基准(默认 160)
|
|
388
|
+
* @returns 是否为桌面设备
|
|
389
|
+
* @example
|
|
390
|
+
* ```ts
|
|
391
|
+
* // 假设 window.innerWidth = 1920
|
|
392
|
+
* EnvUtil.isDesktop(); // true
|
|
393
|
+
*
|
|
394
|
+
* // 自定义阈值
|
|
395
|
+
* EnvUtil.isDesktop(1440, 13); // 更严格的桌面检测
|
|
396
|
+
* ```
|
|
397
|
+
*/
|
|
398
|
+
static isDesktop(minWidth?: number, minScreenSize?: number, dpi?: number): boolean;
|
|
399
|
+
/**
|
|
400
|
+
* 检测当前设备是否为 Windows 桌面设备
|
|
401
|
+
*
|
|
402
|
+
* @param minWidth - 桌面设备最小宽度(默认 1200px)
|
|
403
|
+
* @param minScreenSize - 桌面设备最小屏幕尺寸(默认 10英寸)
|
|
404
|
+
* @param dpi - 标准 DPI 基准(默认 160)
|
|
405
|
+
* @returns 是否为 Windows 桌面设备
|
|
406
|
+
* @example
|
|
407
|
+
* ```ts
|
|
408
|
+
* // UA contains Windows
|
|
409
|
+
* EnvUtil.isWindowsDesktop(); // true
|
|
410
|
+
* ```
|
|
411
|
+
*/
|
|
412
|
+
static isWindowsDesktop(minWidth?: number, minScreenSize?: number, dpi?: number): boolean;
|
|
413
|
+
/**
|
|
414
|
+
* 检测当前设备是否为 macOS 桌面设备
|
|
415
|
+
*
|
|
416
|
+
* @param minWidth - 桌面设备最小宽度(默认 1200px)
|
|
417
|
+
* @param minScreenSize - 桌面设备最小屏幕尺寸(默认 10英寸)
|
|
418
|
+
* @param dpi - 标准 DPI 基准(默认 160)
|
|
419
|
+
* @returns 是否为 macOS 桌面设备
|
|
420
|
+
* @example
|
|
421
|
+
* ```ts
|
|
422
|
+
* // UA contains Macintosh
|
|
423
|
+
* EnvUtil.isMacOSDesktop(); // true
|
|
424
|
+
* ```
|
|
425
|
+
*/
|
|
426
|
+
static isMacOSDesktop(minWidth?: number, minScreenSize?: number, dpi?: number): boolean;
|
|
427
|
+
/**
|
|
428
|
+
* 检测当前设备是否为移动设备
|
|
429
|
+
*
|
|
430
|
+
* @param maxWidth - 移动设备最大宽度(默认 768px)
|
|
431
|
+
* @param dpi - 标准 DPI 基准(默认 160)
|
|
432
|
+
* @returns 是否为移动设备
|
|
433
|
+
* @example
|
|
434
|
+
* ```ts
|
|
435
|
+
* // 假设 window.innerWidth = 500
|
|
436
|
+
* EnvUtil.isMobile(); // true
|
|
437
|
+
* ```
|
|
438
|
+
*/
|
|
439
|
+
static isMobile(maxWidth?: number, dpi?: number): boolean;
|
|
440
|
+
/**
|
|
441
|
+
* 检测当前设备是否为IOS移动设备
|
|
442
|
+
*
|
|
443
|
+
* @param maxWidth - 移动设备最大宽度(默认 768px)
|
|
444
|
+
* @param dpi - 标准 DPI 基准(默认 160)
|
|
445
|
+
* @returns 是否为 iOS 移动设备 (iPhone/iPod)
|
|
446
|
+
* @example
|
|
447
|
+
* ```ts
|
|
448
|
+
* // UA contains iPhone
|
|
449
|
+
* EnvUtil.isIOSMobile(); // true
|
|
450
|
+
* ```
|
|
451
|
+
*/
|
|
452
|
+
static isIOSMobile(maxWidth?: number, dpi?: number): boolean;
|
|
453
|
+
/**
|
|
454
|
+
* 检测当前设备是否为平板
|
|
455
|
+
*
|
|
456
|
+
* @param minWidth - 平板最小宽度(默认 768px)
|
|
457
|
+
* @param maxWidth - 平板最大宽度(默认 1200px)
|
|
458
|
+
* @param dpi - 标准 DPI 基准(默认 160)
|
|
459
|
+
* @returns 是否为平板设备
|
|
460
|
+
* @example
|
|
461
|
+
* ```ts
|
|
462
|
+
* // 假设 window.innerWidth = 1000
|
|
463
|
+
* EnvUtil.isTablet(); // true
|
|
464
|
+
* ```
|
|
465
|
+
*/
|
|
466
|
+
static isTablet(minWidth?: number, maxWidth?: number, dpi?: number): boolean;
|
|
467
|
+
}
|
|
468
|
+
//#endregion
|
|
469
|
+
//#region ../../node_modules/.pnpm/@pawover+types@0.0.1_@types+react@19.2.14_typescript@6.0.3/node_modules/@pawover/types/dist/index.d.ts
|
|
470
|
+
//#endregion
|
|
471
|
+
//#region src/index.d.ts
|
|
472
|
+
/** 任意对象类型 */
|
|
473
|
+
type AnyObject<K extends PropertyKey = PropertyKey, T = any> = Record<K, T>;
|
|
474
|
+
/** 普通对象类型 */
|
|
475
|
+
type PlainObject<K extends PropertyKey = PropertyKey, T = unknown> = Record<K, T>;
|
|
476
|
+
/** 描述树类型 */
|
|
477
|
+
type TreeLike<T extends AnyObject, CK extends string = "children"> = T & Record<CK, TreeLike<T, CK>[]>;
|
|
478
|
+
/** 描述函数类型 */
|
|
479
|
+
type AnyFunction<P extends any[] = any[], R = any> = (...arg: P) => R;
|
|
480
|
+
/** 描述异步函数类型 */
|
|
481
|
+
type AnyAsyncFunction<P extends any[] = any[], R = any> = (...args: P) => Promise<R>;
|
|
482
|
+
/** 描述生成器函数类型 */
|
|
483
|
+
type AnyGeneratorFunction<P extends any[] = any[], T = any, R = any, N = any> = (...args: P) => Generator<T, R, N>;
|
|
484
|
+
/** 描述异步生成器函数类型 */
|
|
485
|
+
type AnyAsyncGeneratorFunction<P extends any[] = any[], T = any, R = any, N = any> = (...args: P) => AsyncGenerator<T, R, N>; //#endregion
|
|
486
|
+
//#endregion
|
|
487
|
+
//#region src/function/functionUtil.d.ts
|
|
488
|
+
/**
|
|
489
|
+
* 函数工具类
|
|
490
|
+
*/
|
|
491
|
+
declare class FunctionUtil {
|
|
492
|
+
/**
|
|
493
|
+
*将 Promise 转换为 `[err, result]` 格式,方便 async/await 错误处理
|
|
494
|
+
*
|
|
495
|
+
* @param promise 待处理的 Promise
|
|
496
|
+
* @param errorExt 附加到 error 对象的扩展信息(注意:如果原 error 是 Error 实例,扩展属性可能会覆盖或无法正确合并非枚举属性)
|
|
497
|
+
* @returns `[err, null]` 或 `[null, data]`
|
|
498
|
+
* @example
|
|
499
|
+
* ```ts
|
|
500
|
+
* const [err, data] = await FunctionUtil.to(someAsyncFunc());
|
|
501
|
+
* ```
|
|
502
|
+
*/
|
|
503
|
+
static to<T, U = Error>(promise: Readonly<Promise<T>>, errorExt?: PlainObject): Promise<[U, undefined] | [null, T]>;
|
|
504
|
+
/**
|
|
505
|
+
* 将 Arguments 对象转换为数组
|
|
506
|
+
*
|
|
507
|
+
* ⚠️ 注意:TypeScript 官方推荐使用 rest parameters (...args) 替代 arguments
|
|
508
|
+
* 本函数仅用于处理遗留代码或特殊场景(如装饰器中需保留 this 绑定)
|
|
509
|
+
*
|
|
510
|
+
* @param args Arguments 对象(必须为类数组对象)
|
|
511
|
+
* @param start 起始索引(可选,默认为 0)
|
|
512
|
+
* @returns 转换后的数组,元素类型为 T
|
|
513
|
+
*
|
|
514
|
+
* @throws TypeError 如果 args 为 null 或 undefined
|
|
515
|
+
*
|
|
516
|
+
* @example
|
|
517
|
+
* // 遗留代码场景
|
|
518
|
+
* function legacyFn(a: number, b: string) {
|
|
519
|
+
* const argsArray = FunctionUtil.toArgs(arguments);
|
|
520
|
+
* // argsArray: unknown[]
|
|
521
|
+
* }
|
|
522
|
+
*
|
|
523
|
+
* // 现代替代方案(推荐)
|
|
524
|
+
* function modernFn(a: number, b: string, ...rest: unknown[]) {
|
|
525
|
+
* // rest 已经是数组,无需 toArgs
|
|
526
|
+
* }
|
|
527
|
+
*
|
|
528
|
+
* // 参数截取
|
|
529
|
+
* function skipFirst(...args: unknown[]) {
|
|
530
|
+
* const rest = FunctionUtil.toArgs(arguments, 1);
|
|
531
|
+
* // rest: unknown[],跳过第一个参数
|
|
532
|
+
* }
|
|
533
|
+
*/
|
|
534
|
+
static toArgs<T = unknown>(args: IArguments, start?: number | undefined): T[];
|
|
535
|
+
/**
|
|
536
|
+
* 将同步或异步函数统一包装为 Promise
|
|
537
|
+
* - 自动捕获同步异常
|
|
538
|
+
*
|
|
539
|
+
* @param fn 返回值可为同步值或 Promise 的函数
|
|
540
|
+
* @returns 标准化的 Promise
|
|
541
|
+
*
|
|
542
|
+
* @example
|
|
543
|
+
* // 同步函数
|
|
544
|
+
* FunctionUtil.toPromise(() => 42).then(v => console.log(v)); // 42
|
|
545
|
+
*
|
|
546
|
+
* // 异步函数
|
|
547
|
+
* FunctionUtil.toPromise(async () => await fetchData()).then(data => ...);
|
|
548
|
+
*
|
|
549
|
+
* // 异常处理
|
|
550
|
+
* FunctionUtil.toPromise(() => { throw new Error('fail'); }).catch(err => console.error(err)); // 捕获同步异常
|
|
551
|
+
*/
|
|
552
|
+
static toPromise<T>(fn: () => T | Promise<T>): Promise<T>;
|
|
553
|
+
}
|
|
554
|
+
//#endregion
|
|
555
|
+
//#region src/mime/mimeUtil.d.ts
|
|
556
|
+
/**
|
|
557
|
+
* MIME 工具类
|
|
558
|
+
*/
|
|
559
|
+
declare class MimeUtil {
|
|
560
|
+
/**
|
|
561
|
+
* 标准 MIME 类型常量,用于文件类型标识和 HTTP Content-Type 头部
|
|
562
|
+
* 基于 IANA 注册标准和浏览器兼容性验证
|
|
563
|
+
*/
|
|
564
|
+
static readonly MIME: {
|
|
565
|
+
/** 普通文本文件 */readonly TEXT: "text/plain"; /** 超文本标记语言文档 */
|
|
566
|
+
readonly HTML: "text/html"; /** 层叠样式表文件 */
|
|
567
|
+
readonly CSS: "text/css"; /** 逗号分隔值文件(表格数据) */
|
|
568
|
+
readonly CSV: "text/csv"; /** 制表符分隔值文件 */
|
|
569
|
+
readonly TSV: "text/tab-separated-values"; /** XML 文档 */
|
|
570
|
+
readonly XML: "text/xml"; /** XHTML 文档(XML 严格格式的 HTML) */
|
|
571
|
+
readonly XHTML: "application/xhtml+xml"; /** JavaScript 脚本文件(标准推荐) */
|
|
572
|
+
readonly JS: "text/javascript"; /** Markdown 格式文档 */
|
|
573
|
+
readonly MARKDOWN: "text/markdown"; /** 富文本格式文档(.rtf) */
|
|
574
|
+
readonly RTF: "application/rtf"; /** iCalendar 日历格式(.ics) */
|
|
575
|
+
readonly CALENDAR: "text/calendar"; /** JPEG 图像(.jpg/.jpeg) */
|
|
576
|
+
readonly JPEG: "image/jpeg"; /** PNG 图像(无损压缩,支持透明) */
|
|
577
|
+
readonly PNG: "image/png"; /** GIF 图像(支持动画) */
|
|
578
|
+
readonly GIF: "image/gif"; /** Windows 位图(.bmp) */
|
|
579
|
+
readonly BMP: "image/bmp"; /** SVG 向量图形(.svg) */
|
|
580
|
+
readonly SVG: "image/svg+xml"; /** APNG 动态图像(.apng) */
|
|
581
|
+
readonly APNG: "image/apng"; /** AVIF 图像(高效压缩) */
|
|
582
|
+
readonly AVIF: "image/avif"; /** 图标文件格式(.ico) */
|
|
583
|
+
readonly ICO: "image/vnd.microsoft.icon"; /** WebP 图像(高效压缩) */
|
|
584
|
+
readonly WEBP: "image/webp"; /** MP3 音频(.mp3) */
|
|
585
|
+
readonly MP3: "audio/mpeg"; /** AAC 音频(.aac) */
|
|
586
|
+
readonly AAC: "audio/aac"; /** MIDI 音乐文件(.mid/.midi) */
|
|
587
|
+
readonly MIDI: "audio/midi"; /** OGG 音频(.oga) */
|
|
588
|
+
readonly OGG_AUDIO: "audio/ogg"; /** Opus 音频(.opus) */
|
|
589
|
+
readonly OPUS: "audio/opus"; /** WAV 音频(.wav) */
|
|
590
|
+
readonly WAV: "audio/wav"; /** RealAudio 音频(.ra/.ram) */
|
|
591
|
+
readonly REAL_AUDIO: "audio/x-pn-realaudio"; /** MP4 视频(.mp4) */
|
|
592
|
+
readonly MP4: "video/mp4"; /** MPEG 视频(.mpeg/.mpg) */
|
|
593
|
+
readonly MPEG: "video/mpeg"; /** OGG 视频(.ogv) */
|
|
594
|
+
readonly OGG_VIDEO: "video/ogg"; /** AVI 视频(.avi) */
|
|
595
|
+
readonly AVI: "video/x-msvideo"; /** 3GPP 视频(.3gp) */
|
|
596
|
+
readonly THREE_GPP: "video/3gpp"; /** 3GPP2 视频(.3g2) */
|
|
597
|
+
readonly THREE_GPP2: "video/3gpp2"; /** WebM 视频(.webm) */
|
|
598
|
+
readonly WEBM: "video/webm"; /** PDF 文档 */
|
|
599
|
+
readonly PDF: "application/pdf"; /** Word 97-2003 文档(.doc) */
|
|
600
|
+
readonly DOC: "application/msword"; /** Word 2007+ 文档(.docx) */
|
|
601
|
+
readonly DOCX: "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; /** Excel 2007+ 工作簿(.xlsx) */
|
|
602
|
+
readonly XLSX: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; /** 启用宏的Excel工作簿(.xlsm) */
|
|
603
|
+
readonly XLSM: "application/vnd.ms-excel.sheet.macroEnabled.12"; /** Excel模板文件(.xltx) */
|
|
604
|
+
readonly XLTX: "application/vnd.openxmlformats-officedocument.spreadsheetml.template"; /** PowerPoint 2007+ 演示文稿(.pptx) */
|
|
605
|
+
readonly PPTX: "application/vnd.openxmlformats-officedocument.presentationml.presentation"; /** PowerPoint 97-2003 演示文稿(.ppt) */
|
|
606
|
+
readonly PPT: "application/vnd.ms-powerpoint"; /** OpenDocument 文本文档(.odt) */
|
|
607
|
+
readonly ODT: "application/vnd.oasis.opendocument.text"; /** OpenDocument 表格文档(.ods) */
|
|
608
|
+
readonly ODS: "application/vnd.oasis.opendocument.spreadsheet"; /** OpenDocument 演示文稿(.odp) */
|
|
609
|
+
readonly ODP: "application/vnd.oasis.opendocument.presentation"; /** EPUB 电子书(.epub) */
|
|
610
|
+
readonly EPUB: "application/epub+zip"; /** Kindle 电子书(.azw) */
|
|
611
|
+
readonly AZW: "application/vnd.amazon.ebook"; /** ZIP 压缩文件(.zip) */
|
|
612
|
+
readonly ZIP: "application/zip"; /** GZIP 压缩文件(.gz) */
|
|
613
|
+
readonly GZIP: "application/gzip"; /** GZIP 压缩文件(旧格式) */
|
|
614
|
+
readonly X_GZIP: "application/x-gzip"; /** TAR 归档文件(.tar) */
|
|
615
|
+
readonly TAR: "application/x-tar"; /** BZip 归档(.bz) */
|
|
616
|
+
readonly BZIP: "application/x-bzip"; /** BZip2 归档(.bz2) */
|
|
617
|
+
readonly BZIP2: "application/x-bzip2"; /** 7-Zip 压缩文件(.7z) */
|
|
618
|
+
readonly SEVEN_Z: "application/x-7z-compressed"; /** 通用二进制数据(默认类型) */
|
|
619
|
+
readonly OCTET_STREAM: "application/octet-stream"; /** JSON 数据格式(.json) */
|
|
620
|
+
readonly JSON: "application/json"; /** JSON-LD 格式(.jsonld) */
|
|
621
|
+
readonly LD_JSON: "application/ld+json"; /** Java 归档文件(.jar) */
|
|
622
|
+
readonly JAR: "application/java-archive"; /** MS 嵌入式 OpenType 字体(.eot) */
|
|
623
|
+
readonly EOT: "application/vnd.ms-fontobject"; /** OpenType 字体(.otf) */
|
|
624
|
+
readonly OTF: "font/otf"; /** Excel 97-2003 工作簿(.xls) */
|
|
625
|
+
readonly XLS: "application/vnd.ms-excel"; /** Microsoft XPS 文档(.xps) */
|
|
626
|
+
readonly XPS: "application/vnd.ms-xpsdocument"; /** Word 启用宏文档(.docm) */
|
|
627
|
+
readonly DOCM: "application/vnd.ms-word.document.macroEnabled.12";
|
|
628
|
+
};
|
|
629
|
+
}
|
|
630
|
+
//#endregion
|
|
631
|
+
//#region src/number/numberUtil.d.ts
|
|
632
|
+
/**
|
|
633
|
+
* 数字工具类
|
|
634
|
+
*/
|
|
635
|
+
declare class NumberUtil {
|
|
636
|
+
/**
|
|
637
|
+
* 数字区间检查函数
|
|
638
|
+
*
|
|
639
|
+
* @param input 待检查数字
|
|
640
|
+
* @param interval 由两个数字组成的元组 [left, right]
|
|
641
|
+
* @param includeLeft 是否包含左边界(默认 true)
|
|
642
|
+
* @param includeRight 是否包含右边界(默认 false)
|
|
643
|
+
* @returns 是否在区间内
|
|
644
|
+
* @example
|
|
645
|
+
* ```ts
|
|
646
|
+
* NumberUtil.within(5, [1, 10]); // true
|
|
647
|
+
* NumberUtil.within(1, [1, 10], false); // false
|
|
648
|
+
* ```
|
|
649
|
+
*/
|
|
650
|
+
static within(input: number, interval: [number, number], includeLeft?: boolean, includeRight?: boolean): boolean;
|
|
651
|
+
}
|
|
652
|
+
//#endregion
|
|
653
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/typed-array.d.ts
|
|
654
|
+
/**
|
|
655
|
+
Matches any [typed array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray), like `Uint8Array` or `Float64Array`.
|
|
656
|
+
|
|
657
|
+
@category Array
|
|
658
|
+
*/
|
|
659
|
+
type TypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array;
|
|
660
|
+
//#endregion
|
|
661
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/union-to-intersection.d.ts
|
|
662
|
+
/**
|
|
663
|
+
Convert a union type to an intersection type.
|
|
664
|
+
|
|
665
|
+
Inspired by [this Stack Overflow answer](https://stackoverflow.com/a/50375286/2172153).
|
|
666
|
+
|
|
667
|
+
@example
|
|
668
|
+
```
|
|
669
|
+
import type {UnionToIntersection} from 'type-fest';
|
|
670
|
+
|
|
671
|
+
type Union = {the(): void} | {great(arg: string): void} | {escape: boolean};
|
|
672
|
+
|
|
673
|
+
type Intersection = UnionToIntersection<Union>;
|
|
674
|
+
//=> {the(): void} & {great(arg: string): void} & {escape: boolean}
|
|
675
|
+
```
|
|
676
|
+
|
|
677
|
+
@category Type
|
|
678
|
+
*/
|
|
679
|
+
type UnionToIntersection<Union> = (// `extends unknown` is always going to be the case and is used to convert the
|
|
680
|
+
// `Union` into a [distributive conditional
|
|
681
|
+
// type](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types).
|
|
682
|
+
Union extends unknown // The union type is used as the only argument to a function since the union
|
|
683
|
+
// of function arguments is an intersection.
|
|
684
|
+
? (distributedUnion: Union) => void // This won't happen.
|
|
685
|
+
: never // Infer the `Intersection` type since TypeScript represents the positional
|
|
686
|
+
// arguments of unions of functions as an intersection of the union.
|
|
687
|
+
) extends ((mergedIntersection: infer Intersection) => void) // The `& Union` is to ensure result of `UnionToIntersection<A | B>` is always assignable to `A | B`
|
|
688
|
+
? Intersection & Union : never;
|
|
689
|
+
//#endregion
|
|
690
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/keys-of-union.d.ts
|
|
691
|
+
/**
|
|
692
|
+
Create a union of all keys from a given type, even those exclusive to specific union members.
|
|
693
|
+
|
|
694
|
+
Unlike the native `keyof` keyword, which returns keys present in **all** union members, this type returns keys from **any** member.
|
|
695
|
+
|
|
696
|
+
@link https://stackoverflow.com/a/49402091
|
|
697
|
+
|
|
698
|
+
@example
|
|
699
|
+
```
|
|
700
|
+
import type {KeysOfUnion} from 'type-fest';
|
|
701
|
+
|
|
702
|
+
type A = {
|
|
703
|
+
common: string;
|
|
704
|
+
a: number;
|
|
705
|
+
};
|
|
706
|
+
|
|
707
|
+
type B = {
|
|
708
|
+
common: string;
|
|
709
|
+
b: string;
|
|
710
|
+
};
|
|
711
|
+
|
|
712
|
+
type C = {
|
|
713
|
+
common: string;
|
|
714
|
+
c: boolean;
|
|
715
|
+
};
|
|
716
|
+
|
|
717
|
+
type Union = A | B | C;
|
|
718
|
+
|
|
719
|
+
type CommonKeys = keyof Union;
|
|
720
|
+
//=> 'common'
|
|
721
|
+
|
|
722
|
+
type AllKeys = KeysOfUnion<Union>;
|
|
723
|
+
//=> 'common' | 'a' | 'b' | 'c'
|
|
724
|
+
```
|
|
725
|
+
|
|
726
|
+
@category Object
|
|
727
|
+
*/
|
|
728
|
+
type KeysOfUnion<ObjectType> = // Hack to fix https://github.com/sindresorhus/type-fest/issues/1008
|
|
729
|
+
keyof UnionToIntersection<ObjectType extends unknown ? Record<keyof ObjectType, never> : never>;
|
|
730
|
+
//#endregion
|
|
731
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/is-any.d.ts
|
|
732
|
+
/**
|
|
733
|
+
Returns a boolean for whether the given type is `any`.
|
|
734
|
+
|
|
735
|
+
@link https://stackoverflow.com/a/49928360/1490091
|
|
736
|
+
|
|
737
|
+
Useful in type utilities, such as disallowing `any`s to be passed to a function.
|
|
738
|
+
|
|
739
|
+
@example
|
|
740
|
+
```
|
|
741
|
+
import type {IsAny} from 'type-fest';
|
|
742
|
+
|
|
743
|
+
const typedObject = {a: 1, b: 2} as const;
|
|
744
|
+
const anyObject: any = {a: 1, b: 2};
|
|
745
|
+
|
|
746
|
+
function get<O extends (IsAny<O> extends true ? {} : Record<string, number>), K extends keyof O = keyof O>(object: O, key: K) {
|
|
747
|
+
return object[key];
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
const typedA = get(typedObject, 'a');
|
|
751
|
+
//=> 1
|
|
752
|
+
|
|
753
|
+
const anyA = get(anyObject, 'a');
|
|
754
|
+
//=> any
|
|
755
|
+
```
|
|
756
|
+
|
|
757
|
+
@category Type Guard
|
|
758
|
+
@category Utilities
|
|
759
|
+
*/
|
|
760
|
+
type IsAny<T> = 0 extends 1 & NoInfer<T> ? true : false;
|
|
761
|
+
//#endregion
|
|
762
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/is-optional-key-of.d.ts
|
|
763
|
+
/**
|
|
764
|
+
Returns a boolean for whether the given key is an optional key of type.
|
|
765
|
+
|
|
766
|
+
This is useful when writing utility types or schema validators that need to differentiate `optional` keys.
|
|
767
|
+
|
|
768
|
+
@example
|
|
769
|
+
```
|
|
770
|
+
import type {IsOptionalKeyOf} from 'type-fest';
|
|
771
|
+
|
|
772
|
+
type User = {
|
|
773
|
+
name: string;
|
|
774
|
+
surname: string;
|
|
775
|
+
|
|
776
|
+
luckyNumber?: number;
|
|
777
|
+
};
|
|
778
|
+
|
|
779
|
+
type Admin = {
|
|
780
|
+
name: string;
|
|
781
|
+
surname?: string;
|
|
782
|
+
};
|
|
783
|
+
|
|
784
|
+
type T1 = IsOptionalKeyOf<User, 'luckyNumber'>;
|
|
785
|
+
//=> true
|
|
786
|
+
|
|
787
|
+
type T2 = IsOptionalKeyOf<User, 'name'>;
|
|
788
|
+
//=> false
|
|
789
|
+
|
|
790
|
+
type T3 = IsOptionalKeyOf<User, 'name' | 'luckyNumber'>;
|
|
791
|
+
//=> boolean
|
|
792
|
+
|
|
793
|
+
type T4 = IsOptionalKeyOf<User | Admin, 'name'>;
|
|
794
|
+
//=> false
|
|
795
|
+
|
|
796
|
+
type T5 = IsOptionalKeyOf<User | Admin, 'surname'>;
|
|
797
|
+
//=> boolean
|
|
798
|
+
```
|
|
799
|
+
|
|
800
|
+
@category Type Guard
|
|
801
|
+
@category Utilities
|
|
802
|
+
*/
|
|
803
|
+
type IsOptionalKeyOf<Type extends object, Key extends keyof Type> = IsAny<Type | Key> extends true ? never : Key extends keyof Type ? Type extends Record<Key, Type[Key]> ? false : true : false;
|
|
804
|
+
//#endregion
|
|
805
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/optional-keys-of.d.ts
|
|
806
|
+
/**
|
|
807
|
+
Extract all optional keys from the given type.
|
|
808
|
+
|
|
809
|
+
This is useful when you want to create a new type that contains different type values for the optional keys only.
|
|
810
|
+
|
|
811
|
+
@example
|
|
812
|
+
```
|
|
813
|
+
import type {OptionalKeysOf, Except} from 'type-fest';
|
|
814
|
+
|
|
815
|
+
type User = {
|
|
816
|
+
name: string;
|
|
817
|
+
surname: string;
|
|
818
|
+
|
|
819
|
+
luckyNumber?: number;
|
|
820
|
+
};
|
|
821
|
+
|
|
822
|
+
const REMOVE_FIELD = Symbol('remove field symbol');
|
|
823
|
+
type UpdateOperation<Entity extends object> = Except<Partial<Entity>, OptionalKeysOf<Entity>> & {
|
|
824
|
+
[Key in OptionalKeysOf<Entity>]?: Entity[Key] | typeof REMOVE_FIELD;
|
|
825
|
+
};
|
|
826
|
+
|
|
827
|
+
const update1: UpdateOperation<User> = {
|
|
828
|
+
name: 'Alice',
|
|
829
|
+
};
|
|
830
|
+
|
|
831
|
+
const update2: UpdateOperation<User> = {
|
|
832
|
+
name: 'Bob',
|
|
833
|
+
luckyNumber: REMOVE_FIELD,
|
|
834
|
+
};
|
|
835
|
+
```
|
|
836
|
+
|
|
837
|
+
@category Utilities
|
|
838
|
+
*/
|
|
839
|
+
type OptionalKeysOf<Type extends object> = Type extends unknown // For distributing `Type`
|
|
840
|
+
? (keyof { [Key in keyof Type as IsOptionalKeyOf<Type, Key> extends false ? never : Key]: never }) & keyof Type // Intersect with `keyof Type` to ensure result of `OptionalKeysOf<Type>` is always assignable to `keyof Type`
|
|
841
|
+
: never;
|
|
842
|
+
//#endregion
|
|
843
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/required-keys-of.d.ts
|
|
844
|
+
/**
|
|
845
|
+
Extract all required keys from the given type.
|
|
846
|
+
|
|
847
|
+
This is useful when you want to create a new type that contains different type values for the required keys only or use the list of keys for validation purposes, etc...
|
|
848
|
+
|
|
849
|
+
@example
|
|
850
|
+
```
|
|
851
|
+
import type {RequiredKeysOf} from 'type-fest';
|
|
852
|
+
|
|
853
|
+
declare function createValidation<
|
|
854
|
+
Entity extends object,
|
|
855
|
+
Key extends RequiredKeysOf<Entity> = RequiredKeysOf<Entity>,
|
|
856
|
+
>(field: Key, validator: (value: Entity[Key]) => boolean): (entity: Entity) => boolean;
|
|
857
|
+
|
|
858
|
+
type User = {
|
|
859
|
+
name: string;
|
|
860
|
+
surname: string;
|
|
861
|
+
luckyNumber?: number;
|
|
862
|
+
};
|
|
863
|
+
|
|
864
|
+
const validator1 = createValidation<User>('name', value => value.length < 25);
|
|
865
|
+
const validator2 = createValidation<User>('surname', value => value.length < 25);
|
|
866
|
+
|
|
867
|
+
// @ts-expect-error
|
|
868
|
+
const validator3 = createValidation<User>('luckyNumber', value => value > 0);
|
|
869
|
+
// Error: Argument of type '"luckyNumber"' is not assignable to parameter of type '"name" | "surname"'.
|
|
870
|
+
```
|
|
871
|
+
|
|
872
|
+
@category Utilities
|
|
873
|
+
*/
|
|
874
|
+
type RequiredKeysOf<Type extends object> = Type extends unknown // For distributing `Type`
|
|
875
|
+
? Exclude<keyof Type, OptionalKeysOf<Type>> : never;
|
|
876
|
+
//#endregion
|
|
877
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/is-never.d.ts
|
|
878
|
+
/**
|
|
879
|
+
Returns a boolean for whether the given type is `never`.
|
|
880
|
+
|
|
881
|
+
@link https://github.com/microsoft/TypeScript/issues/31751#issuecomment-498526919
|
|
882
|
+
@link https://stackoverflow.com/a/53984913/10292952
|
|
883
|
+
@link https://www.zhenghao.io/posts/ts-never
|
|
884
|
+
|
|
885
|
+
Useful in type utilities, such as checking if something does not occur.
|
|
886
|
+
|
|
887
|
+
@example
|
|
888
|
+
```
|
|
889
|
+
import type {IsNever, And} from 'type-fest';
|
|
890
|
+
|
|
891
|
+
type A = IsNever<never>;
|
|
892
|
+
//=> true
|
|
893
|
+
|
|
894
|
+
type B = IsNever<any>;
|
|
895
|
+
//=> false
|
|
896
|
+
|
|
897
|
+
type C = IsNever<unknown>;
|
|
898
|
+
//=> false
|
|
899
|
+
|
|
900
|
+
type D = IsNever<never[]>;
|
|
901
|
+
//=> false
|
|
902
|
+
|
|
903
|
+
type E = IsNever<object>;
|
|
904
|
+
//=> false
|
|
905
|
+
|
|
906
|
+
type F = IsNever<string>;
|
|
907
|
+
//=> false
|
|
908
|
+
```
|
|
909
|
+
|
|
910
|
+
@example
|
|
911
|
+
```
|
|
912
|
+
import type {IsNever} from 'type-fest';
|
|
913
|
+
|
|
914
|
+
type IsTrue<T> = T extends true ? true : false;
|
|
915
|
+
|
|
916
|
+
// When a distributive conditional is instantiated with `never`, the entire conditional results in `never`.
|
|
917
|
+
type A = IsTrue<never>;
|
|
918
|
+
//=> never
|
|
919
|
+
|
|
920
|
+
// If you don't want that behaviour, you can explicitly add an `IsNever` check before the distributive conditional.
|
|
921
|
+
type IsTrueFixed<T> =
|
|
922
|
+
IsNever<T> extends true ? false : T extends true ? true : false;
|
|
923
|
+
|
|
924
|
+
type B = IsTrueFixed<never>;
|
|
925
|
+
//=> false
|
|
926
|
+
```
|
|
927
|
+
|
|
928
|
+
@category Type Guard
|
|
929
|
+
@category Utilities
|
|
930
|
+
*/
|
|
931
|
+
type IsNever<T> = [T] extends [never] ? true : false;
|
|
932
|
+
//#endregion
|
|
933
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/if.d.ts
|
|
934
|
+
/**
|
|
935
|
+
An if-else-like type that resolves depending on whether the given `boolean` type is `true` or `false`.
|
|
936
|
+
|
|
937
|
+
Use-cases:
|
|
938
|
+
- You can use this in combination with `Is*` types to create an if-else-like experience. For example, `If<IsAny<any>, 'is any', 'not any'>`.
|
|
939
|
+
|
|
940
|
+
Note:
|
|
941
|
+
- Returns a union of if branch and else branch if the given type is `boolean` or `any`. For example, `If<boolean, 'Y', 'N'>` will return `'Y' | 'N'`.
|
|
942
|
+
- Returns the else branch if the given type is `never`. For example, `If<never, 'Y', 'N'>` will return `'N'`.
|
|
943
|
+
|
|
944
|
+
@example
|
|
945
|
+
```
|
|
946
|
+
import type {If} from 'type-fest';
|
|
947
|
+
|
|
948
|
+
type A = If<true, 'yes', 'no'>;
|
|
949
|
+
//=> 'yes'
|
|
950
|
+
|
|
951
|
+
type B = If<false, 'yes', 'no'>;
|
|
952
|
+
//=> 'no'
|
|
953
|
+
|
|
954
|
+
type C = If<boolean, 'yes', 'no'>;
|
|
955
|
+
//=> 'yes' | 'no'
|
|
956
|
+
|
|
957
|
+
type D = If<any, 'yes', 'no'>;
|
|
958
|
+
//=> 'yes' | 'no'
|
|
959
|
+
|
|
960
|
+
type E = If<never, 'yes', 'no'>;
|
|
961
|
+
//=> 'no'
|
|
962
|
+
```
|
|
963
|
+
|
|
964
|
+
@example
|
|
965
|
+
```
|
|
966
|
+
import type {If, IsAny, IsNever} from 'type-fest';
|
|
967
|
+
|
|
968
|
+
type A = If<IsAny<unknown>, 'is any', 'not any'>;
|
|
969
|
+
//=> 'not any'
|
|
970
|
+
|
|
971
|
+
type B = If<IsNever<never>, 'is never', 'not never'>;
|
|
972
|
+
//=> 'is never'
|
|
973
|
+
```
|
|
974
|
+
|
|
975
|
+
@example
|
|
976
|
+
```
|
|
977
|
+
import type {If, IsEqual} from 'type-fest';
|
|
978
|
+
|
|
979
|
+
type IfEqual<T, U, IfBranch, ElseBranch> = If<IsEqual<T, U>, IfBranch, ElseBranch>;
|
|
980
|
+
|
|
981
|
+
type A = IfEqual<string, string, 'equal', 'not equal'>;
|
|
982
|
+
//=> 'equal'
|
|
983
|
+
|
|
984
|
+
type B = IfEqual<string, number, 'equal', 'not equal'>;
|
|
985
|
+
//=> 'not equal'
|
|
986
|
+
```
|
|
987
|
+
|
|
988
|
+
Note: Sometimes using the `If` type can make an implementation non–tail-recursive, which can impact performance. In such cases, it’s better to use a conditional directly. Refer to the following example:
|
|
989
|
+
|
|
990
|
+
@example
|
|
991
|
+
```
|
|
992
|
+
import type {If, IsEqual, StringRepeat} from 'type-fest';
|
|
993
|
+
|
|
994
|
+
type HundredZeroes = StringRepeat<'0', 100>;
|
|
995
|
+
|
|
996
|
+
// The following implementation is not tail recursive
|
|
997
|
+
type Includes<S extends string, Char extends string> =
|
|
998
|
+
S extends `${infer First}${infer Rest}`
|
|
999
|
+
? If<IsEqual<First, Char>,
|
|
1000
|
+
'found',
|
|
1001
|
+
Includes<Rest, Char>>
|
|
1002
|
+
: 'not found';
|
|
1003
|
+
|
|
1004
|
+
// Hence, instantiations with long strings will fail
|
|
1005
|
+
// @ts-expect-error
|
|
1006
|
+
type Fails = Includes<HundredZeroes, '1'>;
|
|
1007
|
+
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
1008
|
+
// Error: Type instantiation is excessively deep and possibly infinite.
|
|
1009
|
+
|
|
1010
|
+
// However, if we use a simple conditional instead of `If`, the implementation becomes tail-recursive
|
|
1011
|
+
type IncludesWithoutIf<S extends string, Char extends string> =
|
|
1012
|
+
S extends `${infer First}${infer Rest}`
|
|
1013
|
+
? IsEqual<First, Char> extends true
|
|
1014
|
+
? 'found'
|
|
1015
|
+
: IncludesWithoutIf<Rest, Char>
|
|
1016
|
+
: 'not found';
|
|
1017
|
+
|
|
1018
|
+
// Now, instantiations with long strings will work
|
|
1019
|
+
type Works = IncludesWithoutIf<HundredZeroes, '1'>;
|
|
1020
|
+
//=> 'not found'
|
|
1021
|
+
```
|
|
1022
|
+
|
|
1023
|
+
@category Type Guard
|
|
1024
|
+
@category Utilities
|
|
1025
|
+
*/
|
|
1026
|
+
type If<Type extends boolean, IfBranch, ElseBranch> = IsNever<Type> extends true ? ElseBranch : Type extends true ? IfBranch : ElseBranch;
|
|
1027
|
+
//#endregion
|
|
1028
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/unknown-array.d.ts
|
|
1029
|
+
/**
|
|
1030
|
+
Represents an array with `unknown` value.
|
|
1031
|
+
|
|
1032
|
+
Use case: You want a type that all arrays can be assigned to, but you don't care about the value.
|
|
1033
|
+
|
|
1034
|
+
@example
|
|
1035
|
+
```
|
|
1036
|
+
import type {UnknownArray} from 'type-fest';
|
|
1037
|
+
|
|
1038
|
+
type IsArray<T> = T extends UnknownArray ? true : false;
|
|
1039
|
+
|
|
1040
|
+
type A = IsArray<['foo']>;
|
|
1041
|
+
//=> true
|
|
1042
|
+
|
|
1043
|
+
type B = IsArray<readonly number[]>;
|
|
1044
|
+
//=> true
|
|
1045
|
+
|
|
1046
|
+
type C = IsArray<string>;
|
|
1047
|
+
//=> false
|
|
1048
|
+
```
|
|
1049
|
+
|
|
1050
|
+
@category Type
|
|
1051
|
+
@category Array
|
|
1052
|
+
*/
|
|
1053
|
+
type UnknownArray = readonly unknown[];
|
|
1054
|
+
//#endregion
|
|
1055
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/internal/type.d.ts
|
|
1056
|
+
/**
|
|
1057
|
+
Returns a boolean for whether A is false.
|
|
1058
|
+
|
|
1059
|
+
@example
|
|
1060
|
+
```
|
|
1061
|
+
type A = Not<true>;
|
|
1062
|
+
//=> false
|
|
1063
|
+
|
|
1064
|
+
type B = Not<false>;
|
|
1065
|
+
//=> true
|
|
1066
|
+
```
|
|
1067
|
+
*/
|
|
1068
|
+
type Not<A extends boolean> = A extends true ? false : A extends false ? true : never;
|
|
1069
|
+
/**
|
|
1070
|
+
An if-else-like type that resolves depending on whether the given type is `any` or `never`.
|
|
1071
|
+
|
|
1072
|
+
@example
|
|
1073
|
+
```
|
|
1074
|
+
// When `T` is a NOT `any` or `never` (like `string`) => Returns `IfNotAnyOrNever` branch
|
|
1075
|
+
type A = IfNotAnyOrNever<string, 'VALID', 'IS_ANY', 'IS_NEVER'>;
|
|
1076
|
+
//=> 'VALID'
|
|
1077
|
+
|
|
1078
|
+
// When `T` is `any` => Returns `IfAny` branch
|
|
1079
|
+
type B = IfNotAnyOrNever<any, 'VALID', 'IS_ANY', 'IS_NEVER'>;
|
|
1080
|
+
//=> 'IS_ANY'
|
|
1081
|
+
|
|
1082
|
+
// When `T` is `never` => Returns `IfNever` branch
|
|
1083
|
+
type C = IfNotAnyOrNever<never, 'VALID', 'IS_ANY', 'IS_NEVER'>;
|
|
1084
|
+
//=> 'IS_NEVER'
|
|
1085
|
+
```
|
|
1086
|
+
|
|
1087
|
+
Note: Wrapping a tail-recursive type with `IfNotAnyOrNever` makes the implementation non-tail-recursive. To fix this, move the recursion into a helper type. Refer to the following example:
|
|
1088
|
+
|
|
1089
|
+
@example
|
|
1090
|
+
```ts
|
|
1091
|
+
import type {StringRepeat} from 'type-fest';
|
|
1092
|
+
|
|
1093
|
+
type NineHundredNinetyNineSpaces = StringRepeat<' ', 999>;
|
|
1094
|
+
|
|
1095
|
+
// The following implementation is not tail recursive
|
|
1096
|
+
type TrimLeft<S extends string> = IfNotAnyOrNever<S, S extends ` ${infer R}` ? TrimLeft<R> : S>;
|
|
1097
|
+
|
|
1098
|
+
// Hence, instantiations with long strings will fail
|
|
1099
|
+
// @ts-expect-error
|
|
1100
|
+
type T1 = TrimLeft<NineHundredNinetyNineSpaces>;
|
|
1101
|
+
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
1102
|
+
// Error: Type instantiation is excessively deep and possibly infinite.
|
|
1103
|
+
|
|
1104
|
+
// To fix this, move the recursion into a helper type
|
|
1105
|
+
type TrimLeftOptimised<S extends string> = IfNotAnyOrNever<S, _TrimLeftOptimised<S>>;
|
|
1106
|
+
|
|
1107
|
+
type _TrimLeftOptimised<S extends string> = S extends ` ${infer R}` ? _TrimLeftOptimised<R> : S;
|
|
1108
|
+
|
|
1109
|
+
type T2 = TrimLeftOptimised<NineHundredNinetyNineSpaces>;
|
|
1110
|
+
//=> ''
|
|
1111
|
+
```
|
|
1112
|
+
*/
|
|
1113
|
+
type IfNotAnyOrNever<T, IfNotAnyOrNever, IfAny = any, IfNever = never> = If<IsAny<T>, IfAny, If<IsNever<T>, IfNever, IfNotAnyOrNever>>;
|
|
1114
|
+
/**
|
|
1115
|
+
Indicates the value of `exactOptionalPropertyTypes` compiler option.
|
|
1116
|
+
*/
|
|
1117
|
+
type IsExactOptionalPropertyTypesEnabled = [(string | undefined)?] extends [string?] ? false : true;
|
|
1118
|
+
//#endregion
|
|
1119
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/internal/array.d.ts
|
|
1120
|
+
/**
|
|
1121
|
+
Transforms a tuple type by replacing it's rest element with a single element that has the same type as the rest element, while keeping all the non-rest elements intact.
|
|
1122
|
+
|
|
1123
|
+
@example
|
|
1124
|
+
```
|
|
1125
|
+
type A = CollapseRestElement<[string, string, ...number[]]>;
|
|
1126
|
+
//=> [string, string, number]
|
|
1127
|
+
|
|
1128
|
+
type B = CollapseRestElement<[...string[], number, number]>;
|
|
1129
|
+
//=> [string, number, number]
|
|
1130
|
+
|
|
1131
|
+
type C = CollapseRestElement<[string, string, ...Array<number | bigint>]>;
|
|
1132
|
+
//=> [string, string, number | bigint]
|
|
1133
|
+
|
|
1134
|
+
type D = CollapseRestElement<[string, number]>;
|
|
1135
|
+
//=> [string, number]
|
|
1136
|
+
```
|
|
1137
|
+
|
|
1138
|
+
Note: Optional modifiers (`?`) are removed from elements unless the `exactOptionalPropertyTypes` compiler option is disabled. When disabled, there's an additional `| undefined` for optional elements.
|
|
1139
|
+
|
|
1140
|
+
@example
|
|
1141
|
+
```
|
|
1142
|
+
// `exactOptionalPropertyTypes` enabled
|
|
1143
|
+
type A = CollapseRestElement<[string?, string?, ...number[]]>;
|
|
1144
|
+
//=> [string, string, number]
|
|
1145
|
+
|
|
1146
|
+
// `exactOptionalPropertyTypes` disabled
|
|
1147
|
+
type B = CollapseRestElement<[string?, string?, ...number[]]>;
|
|
1148
|
+
//=> [string | undefined, string | undefined, number]
|
|
1149
|
+
```
|
|
1150
|
+
*/
|
|
1151
|
+
type CollapseRestElement<TArray extends UnknownArray> = IfNotAnyOrNever<TArray, _CollapseRestElement<TArray>>;
|
|
1152
|
+
type _CollapseRestElement<TArray extends UnknownArray, ForwardAccumulator extends UnknownArray = [], BackwardAccumulator extends UnknownArray = []> = TArray extends UnknownArray // For distributing `TArray`
|
|
1153
|
+
? keyof TArray & `${number}` extends never // Enters this branch, if `TArray` is empty (e.g., []),
|
|
1154
|
+
// or `TArray` contains no non-rest elements preceding the rest element (e.g., `[...string[]]` or `[...string[], string]`).
|
|
1155
|
+
? TArray extends readonly [...infer Rest, infer Last] ? _CollapseRestElement<Rest, ForwardAccumulator, [Last, ...BackwardAccumulator]> // Accumulate elements that are present after the rest element.
|
|
1156
|
+
: TArray extends readonly [] ? [...ForwardAccumulator, ...BackwardAccumulator] : [...ForwardAccumulator, TArray[number], ...BackwardAccumulator] // Add the rest element between the accumulated elements.
|
|
1157
|
+
: TArray extends readonly [(infer First)?, ...infer Rest] ? _CollapseRestElement<Rest, [...ForwardAccumulator, '0' extends OptionalKeysOf<TArray> ? If<IsExactOptionalPropertyTypesEnabled, First, First | undefined> // Add `| undefined` for optional elements, if `exactOptionalPropertyTypes` is disabled.
|
|
1158
|
+
: First], BackwardAccumulator> : never // Should never happen, since `[(infer First)?, ...infer Rest]` is a top-type for arrays.
|
|
1159
|
+
: never; // Should never happen
|
|
1160
|
+
//#endregion
|
|
1161
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/numeric.d.ts
|
|
1162
|
+
type _Numeric = number | bigint;
|
|
1163
|
+
type Zero = 0 | 0n;
|
|
1164
|
+
/**
|
|
1165
|
+
Matches the hidden `Infinity` type.
|
|
1166
|
+
|
|
1167
|
+
Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/32277) if you want to have this type as a built-in in TypeScript.
|
|
1168
|
+
|
|
1169
|
+
@see {@link NegativeInfinity}
|
|
1170
|
+
|
|
1171
|
+
@category Numeric
|
|
1172
|
+
*/
|
|
1173
|
+
// See https://github.com/microsoft/TypeScript/issues/31752
|
|
1174
|
+
// eslint-disable-next-line no-loss-of-precision
|
|
1175
|
+
/**
|
|
1176
|
+
A negative `number`/`bigint` (`-∞ < x < 0`)
|
|
1177
|
+
|
|
1178
|
+
Use-case: Validating and documenting parameters.
|
|
1179
|
+
|
|
1180
|
+
@see {@link NegativeInteger}
|
|
1181
|
+
@see {@link NonNegative}
|
|
1182
|
+
|
|
1183
|
+
@category Numeric
|
|
1184
|
+
*/
|
|
1185
|
+
type Negative<T extends _Numeric> = T extends Zero ? never : `${T}` extends `-${string}` ? T : never;
|
|
1186
|
+
/**
|
|
1187
|
+
Returns a boolean for whether the given number is a negative number.
|
|
1188
|
+
|
|
1189
|
+
@see {@link Negative}
|
|
1190
|
+
|
|
1191
|
+
@example
|
|
1192
|
+
```
|
|
1193
|
+
import type {IsNegative} from 'type-fest';
|
|
1194
|
+
|
|
1195
|
+
type ShouldBeFalse = IsNegative<1>;
|
|
1196
|
+
type ShouldBeTrue = IsNegative<-1>;
|
|
1197
|
+
```
|
|
1198
|
+
|
|
1199
|
+
@category Numeric
|
|
1200
|
+
*/
|
|
1201
|
+
type IsNegative<T extends _Numeric> = T extends Negative<T> ? true : false;
|
|
1202
|
+
//#endregion
|
|
1203
|
+
//#region ../../node_modules/.pnpm/tagged-tag@1.0.0/node_modules/tagged-tag/index.d.ts
|
|
1204
|
+
declare const tag: unique symbol;
|
|
1205
|
+
//#endregion
|
|
1206
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/tagged.d.ts
|
|
1207
|
+
// eslint-disable-next-line type-fest/require-exported-types
|
|
1208
|
+
type TagContainer<Token> = {
|
|
1209
|
+
readonly [tag]: Token;
|
|
1210
|
+
};
|
|
1211
|
+
type Tag<Token extends PropertyKey, TagMetadata> = TagContainer<{ [K in Token]: TagMetadata }>;
|
|
1212
|
+
/**
|
|
1213
|
+
Create a [tagged type](https://medium.com/@KevinBGreene/surviving-the-typescript-ecosystem-branding-and-type-tagging-6cf6e516523d) that can support [multiple tags](https://github.com/sindresorhus/type-fest/issues/665) and [per-tag metadata](https://medium.com/@ethanresnick/advanced-typescript-tagged-types-improved-with-type-level-metadata-5072fc125fcf).
|
|
1214
|
+
|
|
1215
|
+
A type returned by `Tagged` can be passed to `Tagged` again, to create a type with multiple tags.
|
|
1216
|
+
|
|
1217
|
+
A tag's name is usually a string (and must be a string, number, or symbol), but each application of a tag can also contain an arbitrary type as its "metadata". See {@link GetTagMetadata} for examples and explanation.
|
|
1218
|
+
|
|
1219
|
+
A type `A` returned by `Tagged` is assignable to another type `B` returned by `Tagged` if and only if:
|
|
1220
|
+
- the underlying (untagged) type of `A` is assignable to the underlying type of `B`;
|
|
1221
|
+
- `A` contains at least all the tags `B` has;
|
|
1222
|
+
- and the metadata type for each of `A`'s tags is assignable to the metadata type of `B`'s corresponding tag.
|
|
1223
|
+
|
|
1224
|
+
There have been several discussions about adding similar features to TypeScript. Unfortunately, nothing has (yet) moved forward:
|
|
1225
|
+
- [Microsoft/TypeScript#202](https://github.com/microsoft/TypeScript/issues/202)
|
|
1226
|
+
- [Microsoft/TypeScript#4895](https://github.com/microsoft/TypeScript/issues/4895)
|
|
1227
|
+
- [Microsoft/TypeScript#33290](https://github.com/microsoft/TypeScript/pull/33290)
|
|
1228
|
+
|
|
1229
|
+
@example
|
|
1230
|
+
```
|
|
1231
|
+
import type {Tagged} from 'type-fest';
|
|
1232
|
+
|
|
1233
|
+
type AccountNumber = Tagged<number, 'AccountNumber'>;
|
|
1234
|
+
type AccountBalance = Tagged<number, 'AccountBalance'>;
|
|
1235
|
+
|
|
1236
|
+
function createAccountNumber(): AccountNumber {
|
|
1237
|
+
// As you can see, casting from a `number` (the underlying type being tagged) is allowed.
|
|
1238
|
+
return 2 as AccountNumber;
|
|
1239
|
+
}
|
|
1240
|
+
|
|
1241
|
+
declare function getMoneyForAccount(accountNumber: AccountNumber): AccountBalance;
|
|
1242
|
+
|
|
1243
|
+
// This will compile successfully.
|
|
1244
|
+
getMoneyForAccount(createAccountNumber());
|
|
1245
|
+
|
|
1246
|
+
// But this won't, because it has to be explicitly passed as an `AccountNumber` type!
|
|
1247
|
+
// Critically, you could not accidentally use an `AccountBalance` as an `AccountNumber`.
|
|
1248
|
+
// @ts-expect-error
|
|
1249
|
+
getMoneyForAccount(2);
|
|
1250
|
+
|
|
1251
|
+
// You can also use tagged values like their underlying, untagged type.
|
|
1252
|
+
// I.e., this will compile successfully because an `AccountNumber` can be used as a regular `number`.
|
|
1253
|
+
// In this sense, the underlying base type is not hidden, which differentiates tagged types from opaque types in other languages.
|
|
1254
|
+
const accountNumber = createAccountNumber() + 2;
|
|
1255
|
+
```
|
|
1256
|
+
|
|
1257
|
+
@example
|
|
1258
|
+
```
|
|
1259
|
+
import type {Tagged} from 'type-fest';
|
|
1260
|
+
|
|
1261
|
+
// You can apply multiple tags to a type by using `Tagged` repeatedly.
|
|
1262
|
+
type Url = Tagged<string, 'URL'>;
|
|
1263
|
+
type SpecialCacheKey = Tagged<Url, 'SpecialCacheKey'>;
|
|
1264
|
+
|
|
1265
|
+
// You can also pass a union of tag names, so this is equivalent to the above, although it doesn't give you the ability to assign distinct metadata to each tag.
|
|
1266
|
+
type SpecialCacheKey2 = Tagged<string, 'URL' | 'SpecialCacheKey'>;
|
|
1267
|
+
```
|
|
1268
|
+
|
|
1269
|
+
@category Type
|
|
1270
|
+
*/
|
|
1271
|
+
type Tagged<Type, TagName extends PropertyKey, TagMetadata = never> = Type & Tag<TagName, TagMetadata>;
|
|
1272
|
+
/**
|
|
1273
|
+
Get the untagged portion of a tagged type created with `Tagged`.
|
|
1274
|
+
|
|
1275
|
+
Why is this necessary?
|
|
1276
|
+
|
|
1277
|
+
1. Use a `Tagged` type as object keys
|
|
1278
|
+
2. Prevent TS4058 error: "Return type of exported function has or is using name X from external module Y but cannot be named"
|
|
1279
|
+
|
|
1280
|
+
@example
|
|
1281
|
+
```
|
|
1282
|
+
import type {Tagged, UnwrapTagged} from 'type-fest';
|
|
1283
|
+
|
|
1284
|
+
type AccountType = Tagged<'SAVINGS' | 'CHECKING', 'AccountType'>;
|
|
1285
|
+
|
|
1286
|
+
const moneyByAccountType: Record<UnwrapTagged<AccountType>, number> = {
|
|
1287
|
+
SAVINGS: 99,
|
|
1288
|
+
CHECKING: 0.1,
|
|
1289
|
+
};
|
|
1290
|
+
|
|
1291
|
+
// Without UnwrapTagged, the following expression would throw a type error.
|
|
1292
|
+
const money = moneyByAccountType.SAVINGS; // TS error: Property 'SAVINGS' does not exist
|
|
1293
|
+
|
|
1294
|
+
// Attempting to pass a non-Tagged type to UnwrapTagged will raise a type error.
|
|
1295
|
+
// @ts-expect-error
|
|
1296
|
+
type WontWork = UnwrapTagged<string>;
|
|
1297
|
+
```
|
|
1298
|
+
|
|
1299
|
+
@category Type
|
|
1300
|
+
*/
|
|
1301
|
+
type UnwrapTagged<TaggedType extends Tag<PropertyKey, any>> = RemoveAllTags<TaggedType>;
|
|
1302
|
+
type RemoveAllTags<T> = T extends Tag<PropertyKey, any> ? { [ThisTag in keyof T[typeof tag]]: T extends Tagged<infer Type, ThisTag, T[typeof tag][ThisTag]> ? RemoveAllTags<Type> : never }[keyof T[typeof tag]] : T;
|
|
1303
|
+
/**
|
|
1304
|
+
Note: The `Opaque` type is deprecated in favor of `Tagged`.
|
|
1305
|
+
|
|
1306
|
+
Attach a "tag" to an arbitrary type. This allows you to create distinct types, that aren't assignable to one another, for runtime values that would otherwise have the same type. (See examples.)
|
|
1307
|
+
|
|
1308
|
+
The generic type parameters can be anything.
|
|
1309
|
+
|
|
1310
|
+
Note that `Opaque` is somewhat of a misnomer here, in that, unlike [some alternative implementations](https://github.com/microsoft/TypeScript/issues/4895#issuecomment-425132582), the original, untagged type is not actually hidden. (E.g., functions that accept the untagged type can still be called with the "opaque" version -- but not vice-versa.)
|
|
1311
|
+
|
|
1312
|
+
Also note that this implementation is limited to a single tag. If you want to allow multiple tags, use `Tagged` instead.
|
|
1313
|
+
|
|
1314
|
+
[Read more about tagged types.](https://medium.com/@KevinBGreene/surviving-the-typescript-ecosystem-branding-and-type-tagging-6cf6e516523d)
|
|
1315
|
+
|
|
1316
|
+
There have been several discussions about adding similar features to TypeScript. Unfortunately, nothing has (yet) moved forward:
|
|
1317
|
+
- [Microsoft/TypeScript#202](https://github.com/microsoft/TypeScript/issues/202)
|
|
1318
|
+
- [Microsoft/TypeScript#15408](https://github.com/Microsoft/TypeScript/issues/15408)
|
|
1319
|
+
- [Microsoft/TypeScript#15807](https://github.com/Microsoft/TypeScript/issues/15807)
|
|
1320
|
+
|
|
1321
|
+
@example
|
|
1322
|
+
```
|
|
1323
|
+
import type {Opaque} from 'type-fest';
|
|
1324
|
+
|
|
1325
|
+
type AccountNumber = Opaque<number, 'AccountNumber'>;
|
|
1326
|
+
type AccountBalance = Opaque<number, 'AccountBalance'>;
|
|
1327
|
+
|
|
1328
|
+
// The `Token` parameter allows the compiler to differentiate between types, whereas "unknown" will not. For example, consider the following structures:
|
|
1329
|
+
type ThingOne = Opaque<string>;
|
|
1330
|
+
type ThingTwo = Opaque<string>;
|
|
1331
|
+
|
|
1332
|
+
// To the compiler, these types are allowed to be cast to each other as they have the same underlying type. They are both `string & { __opaque__: unknown }`.
|
|
1333
|
+
// To avoid this behaviour, you would instead pass the "Token" parameter, like so.
|
|
1334
|
+
type NewThingOne = Opaque<string, 'ThingOne'>;
|
|
1335
|
+
type NewThingTwo = Opaque<string, 'ThingTwo'>;
|
|
1336
|
+
|
|
1337
|
+
// Now they're completely separate types, so the following will fail to compile.
|
|
1338
|
+
function createNewThingOne(): NewThingOne {
|
|
1339
|
+
// As you can see, casting from a string is still allowed. However, you may not cast NewThingOne to NewThingTwo, and vice versa.
|
|
1340
|
+
return 'new thing one' as NewThingOne;
|
|
1341
|
+
}
|
|
1342
|
+
|
|
1343
|
+
// This will fail to compile, as they are fundamentally different types.
|
|
1344
|
+
// @ts-expect-error
|
|
1345
|
+
const thingTwo = createNewThingOne() as NewThingTwo;
|
|
1346
|
+
|
|
1347
|
+
// Here's another example of opaque typing.
|
|
1348
|
+
function createAccountNumber(): AccountNumber {
|
|
1349
|
+
return 2 as AccountNumber;
|
|
1350
|
+
}
|
|
1351
|
+
|
|
1352
|
+
declare function getMoneyForAccount(accountNumber: AccountNumber): AccountBalance;
|
|
1353
|
+
|
|
1354
|
+
// This will compile successfully.
|
|
1355
|
+
getMoneyForAccount(createAccountNumber());
|
|
1356
|
+
|
|
1357
|
+
// But this won't, because it has to be explicitly passed as an `AccountNumber` type.
|
|
1358
|
+
// @ts-expect-error
|
|
1359
|
+
getMoneyForAccount(2);
|
|
1360
|
+
|
|
1361
|
+
// You can use opaque values like they aren't opaque too.
|
|
1362
|
+
const accountNumber = createAccountNumber();
|
|
1363
|
+
|
|
1364
|
+
// This will compile successfully.
|
|
1365
|
+
const newAccountNumber = accountNumber + 2;
|
|
1366
|
+
|
|
1367
|
+
// As a side note, you can (and should) use recursive types for your opaque types to make them stronger and hopefully easier to type.
|
|
1368
|
+
type Person = {
|
|
1369
|
+
id: Opaque<number, Person>;
|
|
1370
|
+
name: string;
|
|
1371
|
+
};
|
|
1372
|
+
```
|
|
1373
|
+
|
|
1374
|
+
@category Type
|
|
1375
|
+
@deprecated Use {@link Tagged} instead
|
|
1376
|
+
*/
|
|
1377
|
+
//#endregion
|
|
1378
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/is-literal.d.ts
|
|
1379
|
+
/**
|
|
1380
|
+
Returns a boolean for whether the given type is a `string` [literal type](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#literal-types).
|
|
1381
|
+
|
|
1382
|
+
Useful for:
|
|
1383
|
+
- providing strongly-typed string manipulation functions
|
|
1384
|
+
- constraining strings to be a string literal
|
|
1385
|
+
- type utilities, such as when constructing parsers and ASTs
|
|
1386
|
+
|
|
1387
|
+
The implementation of this type is inspired by the trick mentioned in this [StackOverflow answer](https://stackoverflow.com/a/68261113/420747).
|
|
1388
|
+
|
|
1389
|
+
@example
|
|
1390
|
+
```
|
|
1391
|
+
import type {IsStringLiteral} from 'type-fest';
|
|
1392
|
+
|
|
1393
|
+
type CapitalizedString<T extends string> = IsStringLiteral<T> extends true ? Capitalize<T> : string;
|
|
1394
|
+
|
|
1395
|
+
// https://github.com/yankeeinlondon/native-dash/blob/master/src/capitalize.ts
|
|
1396
|
+
function capitalize<T extends Readonly<string>>(input: T): CapitalizedString<T> {
|
|
1397
|
+
return (input.slice(0, 1).toUpperCase() + input.slice(1)) as CapitalizedString<T>;
|
|
1398
|
+
}
|
|
1399
|
+
|
|
1400
|
+
const output = capitalize('hello, world!');
|
|
1401
|
+
//=> 'Hello, world!'
|
|
1402
|
+
```
|
|
1403
|
+
|
|
1404
|
+
@example
|
|
1405
|
+
```
|
|
1406
|
+
// String types with infinite set of possible values return `false`.
|
|
1407
|
+
|
|
1408
|
+
import type {IsStringLiteral} from 'type-fest';
|
|
1409
|
+
|
|
1410
|
+
type AllUppercaseStrings = IsStringLiteral<Uppercase<string>>;
|
|
1411
|
+
//=> false
|
|
1412
|
+
|
|
1413
|
+
type StringsStartingWithOn = IsStringLiteral<`on${string}`>;
|
|
1414
|
+
//=> false
|
|
1415
|
+
|
|
1416
|
+
// This behaviour is particularly useful in string manipulation utilities, as infinite string types often require separate handling.
|
|
1417
|
+
|
|
1418
|
+
type Length<S extends string, Counter extends never[] = []> =
|
|
1419
|
+
IsStringLiteral<S> extends false
|
|
1420
|
+
? number // return `number` for infinite string types
|
|
1421
|
+
: S extends `${string}${infer Tail}`
|
|
1422
|
+
? Length<Tail, [...Counter, never]>
|
|
1423
|
+
: Counter['length'];
|
|
1424
|
+
|
|
1425
|
+
type L1 = Length<Lowercase<string>>;
|
|
1426
|
+
//=> number
|
|
1427
|
+
|
|
1428
|
+
type L2 = Length<`${number}`>;
|
|
1429
|
+
//=> number
|
|
1430
|
+
```
|
|
1431
|
+
|
|
1432
|
+
@category Type Guard
|
|
1433
|
+
@category Utilities
|
|
1434
|
+
*/
|
|
1435
|
+
type IsStringLiteral<S> = IfNotAnyOrNever<S, _IsStringLiteral<CollapseLiterals<S extends TagContainer<any> ? UnwrapTagged<S> : S>>, false, false>;
|
|
1436
|
+
type _IsStringLiteral<S> = // If `T` is an infinite string type (e.g., `on${string}`), `Record<T, never>` produces an index signature,
|
|
1437
|
+
// and since `{}` extends index signatures, the result becomes `false`.
|
|
1438
|
+
S extends string ? {} extends Record<S, never> ? false : true : false;
|
|
1439
|
+
//#endregion
|
|
1440
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/tuple-of.d.ts
|
|
1441
|
+
/**
|
|
1442
|
+
Create a tuple type of the specified length with elements of the specified type.
|
|
1443
|
+
|
|
1444
|
+
@example
|
|
1445
|
+
```
|
|
1446
|
+
import type {TupleOf} from 'type-fest';
|
|
1447
|
+
|
|
1448
|
+
type RGB = TupleOf<3, number>;
|
|
1449
|
+
//=> [number, number, number]
|
|
1450
|
+
|
|
1451
|
+
type Line = TupleOf<2, {x: number; y: number}>;
|
|
1452
|
+
//=> [{x: number; y: number}, {x: number; y: number}]
|
|
1453
|
+
|
|
1454
|
+
type TicTacToeBoard = TupleOf<3, TupleOf<3, 'X' | 'O' | null>>;
|
|
1455
|
+
//=> [['X' | 'O' | null, 'X' | 'O' | null, 'X' | 'O' | null], ['X' | 'O' | null, 'X' | 'O' | null, 'X' | 'O' | null], ['X' | 'O' | null, 'X' | 'O' | null, 'X' | 'O' | null]]
|
|
1456
|
+
```
|
|
1457
|
+
|
|
1458
|
+
@example
|
|
1459
|
+
```
|
|
1460
|
+
import type {TupleOf} from 'type-fest';
|
|
1461
|
+
|
|
1462
|
+
type Range<Start extends number, End extends number> = Exclude<keyof TupleOf<End>, keyof TupleOf<Start>>;
|
|
1463
|
+
|
|
1464
|
+
type ZeroToFour = Range<0, 5>;
|
|
1465
|
+
//=> '0' | '1' | '2' | '3' | '4'
|
|
1466
|
+
|
|
1467
|
+
type ThreeToEight = Range<3, 9>;
|
|
1468
|
+
//=> '5' | '3' | '4' | '6' | '7' | '8'
|
|
1469
|
+
```
|
|
1470
|
+
|
|
1471
|
+
Note: If the specified length is the non-literal `number` type, the result will not be a tuple but a regular array.
|
|
1472
|
+
|
|
1473
|
+
@example
|
|
1474
|
+
```
|
|
1475
|
+
import type {TupleOf} from 'type-fest';
|
|
1476
|
+
|
|
1477
|
+
type StringArray = TupleOf<number, string>;
|
|
1478
|
+
//=> string[]
|
|
1479
|
+
```
|
|
1480
|
+
|
|
1481
|
+
Note: If the type for elements is not specified, it will default to `unknown`.
|
|
1482
|
+
|
|
1483
|
+
@example
|
|
1484
|
+
```
|
|
1485
|
+
import type {TupleOf} from 'type-fest';
|
|
1486
|
+
|
|
1487
|
+
type UnknownTriplet = TupleOf<3>;
|
|
1488
|
+
//=> [unknown, unknown, unknown]
|
|
1489
|
+
```
|
|
1490
|
+
|
|
1491
|
+
Note: If the specified length is negative, the result will be an empty tuple.
|
|
1492
|
+
|
|
1493
|
+
@example
|
|
1494
|
+
```
|
|
1495
|
+
import type {TupleOf} from 'type-fest';
|
|
1496
|
+
|
|
1497
|
+
type EmptyTuple = TupleOf<-3, string>;
|
|
1498
|
+
//=> []
|
|
1499
|
+
```
|
|
1500
|
+
|
|
1501
|
+
Note: If you need a readonly tuple, simply wrap this type with `Readonly`, for example, to create `readonly [number, number, number]` use `Readonly<TupleOf<3, number>>`.
|
|
1502
|
+
|
|
1503
|
+
@category Array
|
|
1504
|
+
*/
|
|
1505
|
+
type TupleOf<Length extends number, Fill = unknown> = IfNotAnyOrNever<Length, _TupleOf<If<IsNegative<Length>, 0, Length>, Fill, []>, Fill[], []>;
|
|
1506
|
+
type _TupleOf<L extends number, Fill, Accumulator extends UnknownArray> = number extends L ? Fill[] : L extends Accumulator['length'] ? Accumulator : _TupleOf<L, Fill, [...Accumulator, Fill]>;
|
|
1507
|
+
//#endregion
|
|
1508
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/simplify.d.ts
|
|
1509
|
+
/**
|
|
1510
|
+
Useful to flatten the type output to improve type hints shown in editors. And also to transform an interface into a type to aide with assignability.
|
|
1511
|
+
|
|
1512
|
+
@example
|
|
1513
|
+
```
|
|
1514
|
+
import type {Simplify} from 'type-fest';
|
|
1515
|
+
|
|
1516
|
+
type PositionProps = {
|
|
1517
|
+
top: number;
|
|
1518
|
+
left: number;
|
|
1519
|
+
};
|
|
1520
|
+
|
|
1521
|
+
type SizeProps = {
|
|
1522
|
+
width: number;
|
|
1523
|
+
height: number;
|
|
1524
|
+
};
|
|
1525
|
+
|
|
1526
|
+
// In your editor, hovering over `Props` will show a flattened object with all the properties.
|
|
1527
|
+
type Props = Simplify<PositionProps & SizeProps>;
|
|
1528
|
+
```
|
|
1529
|
+
|
|
1530
|
+
Sometimes it is desired to pass a value as a function argument that has a different type. At first inspection it may seem assignable, and then you discover it is not because the `value`'s type definition was defined as an interface. In the following example, `fn` requires an argument of type `Record<string, unknown>`. If the value is defined as a literal, then it is assignable. And if the `value` is defined as type using the `Simplify` utility the value is assignable. But if the `value` is defined as an interface, it is not assignable because the interface is not sealed and elsewhere a non-string property could be added to the interface.
|
|
1531
|
+
|
|
1532
|
+
If the type definition must be an interface (perhaps it was defined in a third-party npm package), then the `value` can be defined as `const value: Simplify<SomeInterface> = ...`. Then `value` will be assignable to the `fn` argument. Or the `value` can be cast as `Simplify<SomeInterface>` if you can't re-declare the `value`.
|
|
1533
|
+
|
|
1534
|
+
@example
|
|
1535
|
+
```
|
|
1536
|
+
import type {Simplify} from 'type-fest';
|
|
1537
|
+
|
|
1538
|
+
interface SomeInterface {
|
|
1539
|
+
foo: number;
|
|
1540
|
+
bar?: string;
|
|
1541
|
+
baz: number | undefined;
|
|
1542
|
+
}
|
|
1543
|
+
|
|
1544
|
+
type SomeType = {
|
|
1545
|
+
foo: number;
|
|
1546
|
+
bar?: string;
|
|
1547
|
+
baz: number | undefined;
|
|
1548
|
+
};
|
|
1549
|
+
|
|
1550
|
+
const literal = {foo: 123, bar: 'hello', baz: 456};
|
|
1551
|
+
const someType: SomeType = literal;
|
|
1552
|
+
const someInterface: SomeInterface = literal;
|
|
1553
|
+
|
|
1554
|
+
declare function fn(object: Record<string, unknown>): void;
|
|
1555
|
+
|
|
1556
|
+
fn(literal); // Good: literal object type is sealed
|
|
1557
|
+
fn(someType); // Good: type is sealed
|
|
1558
|
+
// @ts-expect-error
|
|
1559
|
+
fn(someInterface); // Error: Index signature for type 'string' is missing in type 'someInterface'. Because `interface` can be re-opened
|
|
1560
|
+
fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface` into a `type`
|
|
1561
|
+
```
|
|
1562
|
+
|
|
1563
|
+
@link https://github.com/microsoft/TypeScript/issues/15300
|
|
1564
|
+
@see {@link SimplifyDeep}
|
|
1565
|
+
@category Object
|
|
1566
|
+
*/
|
|
1567
|
+
type Simplify<T> = { [KeyType in keyof T]: T[KeyType] } & {};
|
|
1568
|
+
//#endregion
|
|
1569
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/is-equal.d.ts
|
|
1570
|
+
/**
|
|
1571
|
+
Returns a boolean for whether the two given types are equal.
|
|
1572
|
+
|
|
1573
|
+
@link https://github.com/microsoft/TypeScript/issues/27024#issuecomment-421529650
|
|
1574
|
+
@link https://stackoverflow.com/questions/68961864/how-does-the-equals-work-in-typescript/68963796#68963796
|
|
1575
|
+
|
|
1576
|
+
Use-cases:
|
|
1577
|
+
- If you want to make a conditional branch based on the result of a comparison of two types.
|
|
1578
|
+
|
|
1579
|
+
@example
|
|
1580
|
+
```
|
|
1581
|
+
import type {IsEqual} from 'type-fest';
|
|
1582
|
+
|
|
1583
|
+
// This type returns a boolean for whether the given array includes the given item.
|
|
1584
|
+
// `IsEqual` is used to compare the given array at position 0 and the given item and then return true if they are equal.
|
|
1585
|
+
type Includes<Value extends readonly any[], Item> =
|
|
1586
|
+
Value extends readonly [Value[0], ...infer rest]
|
|
1587
|
+
? IsEqual<Value[0], Item> extends true
|
|
1588
|
+
? true
|
|
1589
|
+
: Includes<rest, Item>
|
|
1590
|
+
: false;
|
|
1591
|
+
```
|
|
1592
|
+
|
|
1593
|
+
@category Type Guard
|
|
1594
|
+
@category Utilities
|
|
1595
|
+
*/
|
|
1596
|
+
type IsEqual<A, B> = [A] extends [B] ? [B] extends [A] ? _IsEqual<A, B> : false : false;
|
|
1597
|
+
// This version fails the `equalWrappedTupleIntersectionToBeNeverAndNeverExpanded` test in `test-d/is-equal.ts`.
|
|
1598
|
+
type _IsEqual<A, B> = (<G>() => G extends A & G | G ? 1 : 2) extends (<G>() => G extends B & G | G ? 1 : 2) ? true : false;
|
|
1599
|
+
//#endregion
|
|
1600
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/omit-index-signature.d.ts
|
|
1601
|
+
/**
|
|
1602
|
+
Omit any index signatures from the given object type, leaving only explicitly defined properties.
|
|
1603
|
+
|
|
1604
|
+
This is the counterpart of `PickIndexSignature`.
|
|
1605
|
+
|
|
1606
|
+
Use-cases:
|
|
1607
|
+
- Remove overly permissive signatures from third-party types.
|
|
1608
|
+
|
|
1609
|
+
This type was taken from this [StackOverflow answer](https://stackoverflow.com/a/68261113/420747).
|
|
1610
|
+
|
|
1611
|
+
It relies on the fact that an empty object (`{}`) is assignable to an object with just an index signature, like `Record<string, unknown>`, but not to an object with explicitly defined keys, like `Record<'foo' | 'bar', unknown>`.
|
|
1612
|
+
|
|
1613
|
+
(The actual value type, `unknown`, is irrelevant and could be any type. Only the key type matters.)
|
|
1614
|
+
|
|
1615
|
+
```
|
|
1616
|
+
const indexed: Record<string, unknown> = {}; // Allowed
|
|
1617
|
+
|
|
1618
|
+
// @ts-expect-error
|
|
1619
|
+
const keyed: Record<'foo', unknown> = {}; // Error
|
|
1620
|
+
// TS2739: Type '{}' is missing the following properties from type 'Record<"foo" | "bar", unknown>': foo, bar
|
|
1621
|
+
```
|
|
1622
|
+
|
|
1623
|
+
Instead of causing a type error like the above, you can also use a [conditional type](https://www.typescriptlang.org/docs/handbook/2/conditional-types.html) to test whether a type is assignable to another:
|
|
1624
|
+
|
|
1625
|
+
```
|
|
1626
|
+
type Indexed = {} extends Record<string, unknown>
|
|
1627
|
+
? '✅ `{}` is assignable to `Record<string, unknown>`'
|
|
1628
|
+
: '❌ `{}` is NOT assignable to `Record<string, unknown>`';
|
|
1629
|
+
|
|
1630
|
+
type IndexedResult = Indexed;
|
|
1631
|
+
//=> '✅ `{}` is assignable to `Record<string, unknown>`'
|
|
1632
|
+
|
|
1633
|
+
type Keyed = {} extends Record<'foo' | 'bar', unknown>
|
|
1634
|
+
? '✅ `{}` is assignable to `Record<\'foo\' | \'bar\', unknown>`'
|
|
1635
|
+
: '❌ `{}` is NOT assignable to `Record<\'foo\' | \'bar\', unknown>`';
|
|
1636
|
+
|
|
1637
|
+
type KeyedResult = Keyed;
|
|
1638
|
+
//=> '❌ `{}` is NOT assignable to `Record<\'foo\' | \'bar\', unknown>`'
|
|
1639
|
+
```
|
|
1640
|
+
|
|
1641
|
+
Using a [mapped type](https://www.typescriptlang.org/docs/handbook/2/mapped-types.html#further-exploration), you can then check for each `KeyType` of `ObjectType`...
|
|
1642
|
+
|
|
1643
|
+
```
|
|
1644
|
+
type OmitIndexSignature<ObjectType> = {
|
|
1645
|
+
[KeyType in keyof ObjectType // Map each key of `ObjectType`...
|
|
1646
|
+
]: ObjectType[KeyType]; // ...to its original value, i.e. `OmitIndexSignature<Foo> == Foo`.
|
|
1647
|
+
};
|
|
1648
|
+
```
|
|
1649
|
+
|
|
1650
|
+
...whether an empty object (`{}`) would be assignable to an object with that `KeyType` (`Record<KeyType, unknown>`)...
|
|
1651
|
+
|
|
1652
|
+
```
|
|
1653
|
+
type OmitIndexSignature<ObjectType> = {
|
|
1654
|
+
[KeyType in keyof ObjectType
|
|
1655
|
+
// Is `{}` assignable to `Record<KeyType, unknown>`?
|
|
1656
|
+
as {} extends Record<KeyType, unknown>
|
|
1657
|
+
? never // ✅ `{}` is assignable to `Record<KeyType, unknown>`
|
|
1658
|
+
: KeyType // ❌ `{}` is NOT assignable to `Record<KeyType, unknown>`
|
|
1659
|
+
]: ObjectType[KeyType];
|
|
1660
|
+
};
|
|
1661
|
+
```
|
|
1662
|
+
|
|
1663
|
+
If `{}` is assignable, it means that `KeyType` is an index signature and we want to remove it. If it is not assignable, `KeyType` is a "real" key and we want to keep it.
|
|
1664
|
+
|
|
1665
|
+
@example
|
|
1666
|
+
```
|
|
1667
|
+
import type {OmitIndexSignature} from 'type-fest';
|
|
1668
|
+
|
|
1669
|
+
type Example = {
|
|
1670
|
+
// These index signatures will be removed.
|
|
1671
|
+
[x: string]: any;
|
|
1672
|
+
[x: number]: any;
|
|
1673
|
+
[x: symbol]: any;
|
|
1674
|
+
[x: `head-${string}`]: string;
|
|
1675
|
+
[x: `${string}-tail`]: string;
|
|
1676
|
+
[x: `head-${string}-tail`]: string;
|
|
1677
|
+
[x: `${bigint}`]: string;
|
|
1678
|
+
[x: `embedded-${number}`]: string;
|
|
1679
|
+
|
|
1680
|
+
// These explicitly defined keys will remain.
|
|
1681
|
+
foo: 'bar';
|
|
1682
|
+
qux?: 'baz';
|
|
1683
|
+
};
|
|
1684
|
+
|
|
1685
|
+
type ExampleWithoutIndexSignatures = OmitIndexSignature<Example>;
|
|
1686
|
+
//=> {foo: 'bar'; qux?: 'baz'}
|
|
1687
|
+
```
|
|
1688
|
+
|
|
1689
|
+
@see {@link PickIndexSignature}
|
|
1690
|
+
@category Object
|
|
1691
|
+
*/
|
|
1692
|
+
type OmitIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? never : KeyType]: ObjectType[KeyType] };
|
|
1693
|
+
//#endregion
|
|
1694
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/pick-index-signature.d.ts
|
|
1695
|
+
/**
|
|
1696
|
+
Pick only index signatures from the given object type, leaving out all explicitly defined properties.
|
|
1697
|
+
|
|
1698
|
+
This is the counterpart of `OmitIndexSignature`.
|
|
1699
|
+
|
|
1700
|
+
@example
|
|
1701
|
+
```
|
|
1702
|
+
import type {PickIndexSignature} from 'type-fest';
|
|
1703
|
+
|
|
1704
|
+
declare const symbolKey: unique symbol;
|
|
1705
|
+
|
|
1706
|
+
type Example = {
|
|
1707
|
+
// These index signatures will remain.
|
|
1708
|
+
[x: string]: unknown;
|
|
1709
|
+
[x: number]: unknown;
|
|
1710
|
+
[x: symbol]: unknown;
|
|
1711
|
+
[x: `head-${string}`]: string;
|
|
1712
|
+
[x: `${string}-tail`]: string;
|
|
1713
|
+
[x: `head-${string}-tail`]: string;
|
|
1714
|
+
[x: `${bigint}`]: string;
|
|
1715
|
+
[x: `embedded-${number}`]: string;
|
|
1716
|
+
|
|
1717
|
+
// These explicitly defined keys will be removed.
|
|
1718
|
+
['kebab-case-key']: string;
|
|
1719
|
+
[symbolKey]: string;
|
|
1720
|
+
foo: 'bar';
|
|
1721
|
+
qux?: 'baz';
|
|
1722
|
+
};
|
|
1723
|
+
|
|
1724
|
+
type ExampleIndexSignature = PickIndexSignature<Example>;
|
|
1725
|
+
// {
|
|
1726
|
+
// [x: string]: unknown;
|
|
1727
|
+
// [x: number]: unknown;
|
|
1728
|
+
// [x: symbol]: unknown;
|
|
1729
|
+
// [x: `head-${string}`]: string;
|
|
1730
|
+
// [x: `${string}-tail`]: string;
|
|
1731
|
+
// [x: `head-${string}-tail`]: string;
|
|
1732
|
+
// [x: `${bigint}`]: string;
|
|
1733
|
+
// [x: `embedded-${number}`]: string;
|
|
1734
|
+
// }
|
|
1735
|
+
```
|
|
1736
|
+
|
|
1737
|
+
@see {@link OmitIndexSignature}
|
|
1738
|
+
@category Object
|
|
1739
|
+
*/
|
|
1740
|
+
type PickIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? KeyType : never]: ObjectType[KeyType] };
|
|
1741
|
+
//#endregion
|
|
1742
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/merge.d.ts
|
|
1743
|
+
// Merges two objects without worrying about index signatures.
|
|
1744
|
+
type SimpleMerge<Destination, Source> = Simplify<{ [Key in keyof Destination as Key extends keyof Source ? never : Key]: Destination[Key] } & Source>;
|
|
1745
|
+
/**
|
|
1746
|
+
Merge two types into a new type. Keys of the second type overrides keys of the first type.
|
|
1747
|
+
|
|
1748
|
+
This is different from the TypeScript `&` (intersection) operator. With `&`, conflicting property types are intersected, which often results in `never`. For example, `{a: string} & {a: number}` makes `a` become `string & number`, which resolves to `never`. With `Merge`, the second type's keys cleanly override the first, so `Merge<{a: string}, {a: number}>` gives `{a: number}` as expected. `Merge` also produces a flattened type (via `Simplify`), making it more readable in IDE tooltips compared to `A & B`.
|
|
1749
|
+
|
|
1750
|
+
@example
|
|
1751
|
+
```
|
|
1752
|
+
import type {Merge} from 'type-fest';
|
|
1753
|
+
|
|
1754
|
+
type Foo = {
|
|
1755
|
+
a: string;
|
|
1756
|
+
b: number;
|
|
1757
|
+
};
|
|
1758
|
+
|
|
1759
|
+
type Bar = {
|
|
1760
|
+
a: number; // Conflicts with Foo['a']
|
|
1761
|
+
c: boolean;
|
|
1762
|
+
};
|
|
1763
|
+
|
|
1764
|
+
// With `&`, `a` becomes `string & number` which is `never`. Not what you want.
|
|
1765
|
+
type WithIntersection = (Foo & Bar)['a'];
|
|
1766
|
+
//=> never
|
|
1767
|
+
|
|
1768
|
+
// With `Merge`, `a` is cleanly overridden to `number`.
|
|
1769
|
+
type WithMerge = Merge<Foo, Bar>['a'];
|
|
1770
|
+
//=> number
|
|
1771
|
+
```
|
|
1772
|
+
|
|
1773
|
+
@example
|
|
1774
|
+
```
|
|
1775
|
+
import type {Merge} from 'type-fest';
|
|
1776
|
+
|
|
1777
|
+
type Foo = {
|
|
1778
|
+
[x: string]: unknown;
|
|
1779
|
+
[x: number]: unknown;
|
|
1780
|
+
foo: string;
|
|
1781
|
+
bar: symbol;
|
|
1782
|
+
};
|
|
1783
|
+
|
|
1784
|
+
type Bar = {
|
|
1785
|
+
[x: number]: number;
|
|
1786
|
+
[x: symbol]: unknown;
|
|
1787
|
+
bar: Date;
|
|
1788
|
+
baz: boolean;
|
|
1789
|
+
};
|
|
1790
|
+
|
|
1791
|
+
export type FooBar = Merge<Foo, Bar>;
|
|
1792
|
+
//=> {
|
|
1793
|
+
// [x: string]: unknown;
|
|
1794
|
+
// [x: number]: number;
|
|
1795
|
+
// [x: symbol]: unknown;
|
|
1796
|
+
// foo: string;
|
|
1797
|
+
// bar: Date;
|
|
1798
|
+
// baz: boolean;
|
|
1799
|
+
// }
|
|
1800
|
+
```
|
|
1801
|
+
|
|
1802
|
+
Note: If you want a merge type that more accurately reflects the runtime behavior of object spread or `Object.assign`, refer to the {@link ObjectMerge} type.
|
|
1803
|
+
|
|
1804
|
+
@see {@link ObjectMerge}
|
|
1805
|
+
@category Object
|
|
1806
|
+
*/
|
|
1807
|
+
type Merge<Destination, Source> = Destination extends unknown // For distributing `Destination`
|
|
1808
|
+
? Source extends unknown // For distributing `Source`
|
|
1809
|
+
? If<IsEqual<Destination, Source>, Destination, _Merge<Destination, Source>> : never // Should never happen
|
|
1810
|
+
: never;
|
|
1811
|
+
// Should never happen
|
|
1812
|
+
type _Merge<Destination, Source> = Simplify<SimpleMerge<PickIndexSignature<Destination>, PickIndexSignature<Source>> & SimpleMerge<OmitIndexSignature<Destination>, OmitIndexSignature<Source>>>;
|
|
1813
|
+
//#endregion
|
|
1814
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/internal/object.d.ts
|
|
1815
|
+
/**
|
|
1816
|
+
Works similar to the built-in `Pick` utility type, except for the following differences:
|
|
1817
|
+
- Distributes over union types and allows picking keys from any member of the union type.
|
|
1818
|
+
- Primitives types are returned as-is.
|
|
1819
|
+
- Picks all keys if `Keys` is `any`.
|
|
1820
|
+
- Doesn't pick `number` from a `string` index signature.
|
|
1821
|
+
|
|
1822
|
+
@example
|
|
1823
|
+
```
|
|
1824
|
+
type ImageUpload = {
|
|
1825
|
+
url: string;
|
|
1826
|
+
size: number;
|
|
1827
|
+
thumbnailUrl: string;
|
|
1828
|
+
};
|
|
1829
|
+
|
|
1830
|
+
type VideoUpload = {
|
|
1831
|
+
url: string;
|
|
1832
|
+
duration: number;
|
|
1833
|
+
encodingFormat: string;
|
|
1834
|
+
};
|
|
1835
|
+
|
|
1836
|
+
// Distributes over union types and allows picking keys from any member of the union type
|
|
1837
|
+
type MediaDisplay = HomomorphicPick<ImageUpload | VideoUpload, "url" | "size" | "duration">;
|
|
1838
|
+
//=> {url: string; size: number} | {url: string; duration: number}
|
|
1839
|
+
|
|
1840
|
+
// Primitive types are returned as-is
|
|
1841
|
+
type Primitive = HomomorphicPick<string | number, 'toUpperCase' | 'toString'>;
|
|
1842
|
+
//=> string | number
|
|
1843
|
+
|
|
1844
|
+
// Picks all keys if `Keys` is `any`
|
|
1845
|
+
type Any = HomomorphicPick<{a: 1; b: 2} | {c: 3}, any>;
|
|
1846
|
+
//=> {a: 1; b: 2} | {c: 3}
|
|
1847
|
+
|
|
1848
|
+
// Doesn't pick `number` from a `string` index signature
|
|
1849
|
+
type IndexSignature = HomomorphicPick<{[k: string]: unknown}, number>;
|
|
1850
|
+
//=> {}
|
|
1851
|
+
*/
|
|
1852
|
+
type HomomorphicPick<T, Keys extends KeysOfUnion<T>> = { [P in keyof T as Extract<P, Keys>]: T[P] };
|
|
1853
|
+
/**
|
|
1854
|
+
Merges user specified options with default options.
|
|
1855
|
+
|
|
1856
|
+
@example
|
|
1857
|
+
```
|
|
1858
|
+
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
1859
|
+
type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
|
|
1860
|
+
type SpecifiedOptions = {leavesOnly: true};
|
|
1861
|
+
|
|
1862
|
+
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
1863
|
+
//=> {maxRecursionDepth: 10; leavesOnly: true}
|
|
1864
|
+
```
|
|
1865
|
+
|
|
1866
|
+
@example
|
|
1867
|
+
```
|
|
1868
|
+
// Complains if default values are not provided for optional options
|
|
1869
|
+
|
|
1870
|
+
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
1871
|
+
type DefaultPathsOptions = {maxRecursionDepth: 10};
|
|
1872
|
+
type SpecifiedOptions = {};
|
|
1873
|
+
|
|
1874
|
+
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
1875
|
+
// ~~~~~~~~~~~~~~~~~~~
|
|
1876
|
+
// Property 'leavesOnly' is missing in type 'DefaultPathsOptions' but required in type '{ maxRecursionDepth: number; leavesOnly: boolean; }'.
|
|
1877
|
+
```
|
|
1878
|
+
|
|
1879
|
+
@example
|
|
1880
|
+
```
|
|
1881
|
+
// Complains if an option's default type does not conform to the expected type
|
|
1882
|
+
|
|
1883
|
+
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
1884
|
+
type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: 'no'};
|
|
1885
|
+
type SpecifiedOptions = {};
|
|
1886
|
+
|
|
1887
|
+
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
1888
|
+
// ~~~~~~~~~~~~~~~~~~~
|
|
1889
|
+
// Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
|
|
1890
|
+
```
|
|
1891
|
+
|
|
1892
|
+
@example
|
|
1893
|
+
```
|
|
1894
|
+
// Complains if an option's specified type does not conform to the expected type
|
|
1895
|
+
|
|
1896
|
+
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
1897
|
+
type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
|
|
1898
|
+
type SpecifiedOptions = {leavesOnly: 'yes'};
|
|
1899
|
+
|
|
1900
|
+
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
1901
|
+
// ~~~~~~~~~~~~~~~~
|
|
1902
|
+
// Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
|
|
1903
|
+
```
|
|
1904
|
+
*/
|
|
1905
|
+
type ApplyDefaultOptions<Options extends object, Defaults extends Simplify<Omit<Required<Options>, RequiredKeysOf<Options>> & Partial<Record<RequiredKeysOf<Options>, never>>>, SpecifiedOptions extends Options> = If<IsAny<SpecifiedOptions>, Defaults, If<IsNever<SpecifiedOptions>, Defaults, Simplify<Merge<Defaults, { [Key in keyof SpecifiedOptions as Key extends OptionalKeysOf<Options> ? undefined extends SpecifiedOptions[Key] ? never : Key : Key]: SpecifiedOptions[Key] }> & Required<Options>>>>;
|
|
1906
|
+
// `& Required<Options>` ensures that `ApplyDefaultOptions<SomeOption, ...>` is always assignable to `Required<SomeOption>`
|
|
1907
|
+
/**
|
|
1908
|
+
Collapses literal types in a union into their corresponding primitive types, when possible. For example, `CollapseLiterals<'foo' | 'bar' | (string & {})>` returns `string`.
|
|
1909
|
+
|
|
1910
|
+
Note: This doesn't collapse literals within tagged types. For example, `CollapseLiterals<Tagged<'foo' | (string & {}), 'Tag'>>` returns `("foo" & Tag<"Tag", never>) | (string & Tag<"Tag", never>)` and not `string & Tag<"Tag", never>`.
|
|
1911
|
+
|
|
1912
|
+
Use-case: For collapsing unions created using {@link LiteralUnion}.
|
|
1913
|
+
|
|
1914
|
+
@example
|
|
1915
|
+
```
|
|
1916
|
+
import type {LiteralUnion} from 'type-fest';
|
|
1917
|
+
|
|
1918
|
+
type A = CollapseLiterals<'foo' | 'bar' | (string & {})>;
|
|
1919
|
+
//=> string
|
|
1920
|
+
|
|
1921
|
+
type B = CollapseLiterals<LiteralUnion<1 | 2 | 3, number>>;
|
|
1922
|
+
//=> number
|
|
1923
|
+
|
|
1924
|
+
type C = CollapseLiterals<LiteralUnion<'onClick' | 'onChange', `on${string}`>>;
|
|
1925
|
+
//=> `on${string}`
|
|
1926
|
+
|
|
1927
|
+
type D = CollapseLiterals<'click' | 'change' | (`on${string}` & {})>;
|
|
1928
|
+
//=> 'click' | 'change' | `on${string}`
|
|
1929
|
+
|
|
1930
|
+
type E = CollapseLiterals<LiteralUnion<'foo' | 'bar', string> | null | undefined>;
|
|
1931
|
+
//=> string | null | undefined
|
|
1932
|
+
```
|
|
1933
|
+
*/
|
|
1934
|
+
type CollapseLiterals<T> = {} extends T ? T : T extends infer U & {} ? U : T;
|
|
1935
|
+
//#endregion
|
|
1936
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/some-extend.d.ts
|
|
1937
|
+
/**
|
|
1938
|
+
@see {@link SomeExtend}
|
|
1939
|
+
*/
|
|
1940
|
+
type SomeExtendOptions = {
|
|
1941
|
+
/**
|
|
1942
|
+
Consider `never` elements to match the target type only if the target type itself is `never` (or `any`).
|
|
1943
|
+
- When set to `true` (default), `never` is _not_ treated as a bottom type, instead, it is treated as a type that matches only itself (or `any`).
|
|
1944
|
+
- When set to `false`, `never` is treated as a bottom type, and behaves as it normally would.
|
|
1945
|
+
@default true
|
|
1946
|
+
@example
|
|
1947
|
+
```
|
|
1948
|
+
import type {SomeExtend} from 'type-fest';
|
|
1949
|
+
type A = SomeExtend<[1, 2, never], string, {strictNever: true}>;
|
|
1950
|
+
//=> false
|
|
1951
|
+
type B = SomeExtend<[1, 2, never], string, {strictNever: false}>;
|
|
1952
|
+
//=> true
|
|
1953
|
+
type C = SomeExtend<[1, never], never, {strictNever: true}>;
|
|
1954
|
+
//=> true
|
|
1955
|
+
type D = SomeExtend<[1, never], never, {strictNever: false}>;
|
|
1956
|
+
//=> true
|
|
1957
|
+
type E = SomeExtend<[never], any, {strictNever: true}>;
|
|
1958
|
+
//=> true
|
|
1959
|
+
type F = SomeExtend<[never], any, {strictNever: false}>;
|
|
1960
|
+
//=> true
|
|
1961
|
+
```
|
|
1962
|
+
*/
|
|
1963
|
+
strictNever?: boolean;
|
|
1964
|
+
};
|
|
1965
|
+
type DefaultSomeExtendOptions = {
|
|
1966
|
+
strictNever: true;
|
|
1967
|
+
};
|
|
1968
|
+
/**
|
|
1969
|
+
Returns a boolean for whether some element in an array type extends another type.
|
|
1970
|
+
|
|
1971
|
+
@example
|
|
1972
|
+
```
|
|
1973
|
+
import type {SomeExtend} from 'type-fest';
|
|
1974
|
+
|
|
1975
|
+
type A = SomeExtend<['1', '2', 3], number>;
|
|
1976
|
+
//=> true
|
|
1977
|
+
|
|
1978
|
+
type B = SomeExtend<[1, 2, 3], string>;
|
|
1979
|
+
//=> false
|
|
1980
|
+
|
|
1981
|
+
type C = SomeExtend<[string, number | string], number>;
|
|
1982
|
+
//=> boolean
|
|
1983
|
+
|
|
1984
|
+
type D = SomeExtend<[true, boolean, true], false>;
|
|
1985
|
+
//=> boolean
|
|
1986
|
+
```
|
|
1987
|
+
|
|
1988
|
+
Note: Behaviour of optional elements depend on the `exactOptionalPropertyTypes` compiler option. When the option is disabled, the target type must include `undefined` for a successful match.
|
|
1989
|
+
|
|
1990
|
+
```
|
|
1991
|
+
// @exactOptionalPropertyTypes: true
|
|
1992
|
+
import type {SomeExtend} from 'type-fest';
|
|
1993
|
+
|
|
1994
|
+
type A = SomeExtend<[1?, 2?, '3'?], string>;
|
|
1995
|
+
//=> true
|
|
1996
|
+
```
|
|
1997
|
+
|
|
1998
|
+
```
|
|
1999
|
+
// @exactOptionalPropertyTypes: false
|
|
2000
|
+
import type {SomeExtend} from 'type-fest';
|
|
2001
|
+
|
|
2002
|
+
type A = SomeExtend<[1?, 2?, '3'?], string>;
|
|
2003
|
+
//=> boolean
|
|
2004
|
+
|
|
2005
|
+
type B = SomeExtend<[1?, 2?, '3'?], string | undefined>;
|
|
2006
|
+
//=> true
|
|
2007
|
+
```
|
|
2008
|
+
|
|
2009
|
+
@see {@link SomeExtendOptions}
|
|
2010
|
+
|
|
2011
|
+
@category Utilities
|
|
2012
|
+
@category Array
|
|
2013
|
+
*/
|
|
2014
|
+
type SomeExtend<TArray extends UnknownArray, Type, Options extends SomeExtendOptions = {}> = _SomeExtend<CollapseRestElement<TArray>, Type, ApplyDefaultOptions<SomeExtendOptions, DefaultSomeExtendOptions, Options>>;
|
|
2015
|
+
type _SomeExtend<TArray extends UnknownArray, Type, Options extends Required<SomeExtendOptions>> = IfNotAnyOrNever<TArray, TArray extends readonly [infer First, ...infer Rest] ? IsNever<First> extends true ? Or<Or<IsNever<Type>, IsAny<Type>>, Not<Options['strictNever']>> extends true // If target `Type` is also `never`, or is `any`, or `strictNever` is disabled, return `true`.
|
|
2016
|
+
? true : _SomeExtend<Rest, Type, Options> : First extends Type ? true : _SomeExtend<Rest, Type, Options> : false, false, false>;
|
|
2017
|
+
//#endregion
|
|
2018
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/or-all.d.ts
|
|
2019
|
+
/**
|
|
2020
|
+
Returns a boolean for whether any of the given elements is `true`.
|
|
2021
|
+
|
|
2022
|
+
Use-cases:
|
|
2023
|
+
- Check if at least one condition in a list of booleans is met.
|
|
2024
|
+
|
|
2025
|
+
@example
|
|
2026
|
+
```
|
|
2027
|
+
import type {OrAll} from 'type-fest';
|
|
2028
|
+
|
|
2029
|
+
type FFT = OrAll<[false, false, true]>;
|
|
2030
|
+
//=> true
|
|
2031
|
+
|
|
2032
|
+
type FFF = OrAll<[false, false, false]>;
|
|
2033
|
+
//=> false
|
|
2034
|
+
```
|
|
2035
|
+
|
|
2036
|
+
Note: When `boolean` is passed as an element, it is distributed into separate cases, and the final result is a union of those cases.
|
|
2037
|
+
For example, `OrAll<[false, boolean]>` expands to `OrAll<[false, true]> | OrAll<[false, false]>`, which simplifies to `true | false` (i.e., `boolean`).
|
|
2038
|
+
|
|
2039
|
+
@example
|
|
2040
|
+
```
|
|
2041
|
+
import type {OrAll} from 'type-fest';
|
|
2042
|
+
|
|
2043
|
+
type A = OrAll<[false, boolean]>;
|
|
2044
|
+
//=> boolean
|
|
2045
|
+
|
|
2046
|
+
type B = OrAll<[true, boolean]>;
|
|
2047
|
+
//=> true
|
|
2048
|
+
```
|
|
2049
|
+
|
|
2050
|
+
Note: If `never` is passed as an element, it is treated as `false` and the result is computed accordingly.
|
|
2051
|
+
|
|
2052
|
+
@example
|
|
2053
|
+
```
|
|
2054
|
+
import type {OrAll} from 'type-fest';
|
|
2055
|
+
|
|
2056
|
+
type A = OrAll<[never, never, true]>;
|
|
2057
|
+
//=> true
|
|
2058
|
+
|
|
2059
|
+
type B = OrAll<[never, never, false]>;
|
|
2060
|
+
//=> false
|
|
2061
|
+
|
|
2062
|
+
type C = OrAll<[never, never, never]>;
|
|
2063
|
+
//=> false
|
|
2064
|
+
|
|
2065
|
+
type D = OrAll<[never, never, boolean]>;
|
|
2066
|
+
//=> boolean
|
|
2067
|
+
```
|
|
2068
|
+
|
|
2069
|
+
Note: If `any` is passed as an element, it is treated as `boolean` and the result is computed accordingly.
|
|
2070
|
+
|
|
2071
|
+
@example
|
|
2072
|
+
```
|
|
2073
|
+
import type {OrAll} from 'type-fest';
|
|
2074
|
+
|
|
2075
|
+
type A = OrAll<[false, any]>;
|
|
2076
|
+
//=> boolean
|
|
2077
|
+
|
|
2078
|
+
type B = OrAll<[true, any]>;
|
|
2079
|
+
//=> true
|
|
2080
|
+
```
|
|
2081
|
+
|
|
2082
|
+
Note: `OrAll<[]>` evaluates to `false` because there are no `true` elements in an empty tuple. See [Wikipedia: Clause (logic) > Empty clauses](https://en.wikipedia.org/wiki/Clause_(logic)#Empty_clauses:~:text=The%20truth%20evaluation%20of%20an%20empty%20disjunctive%20clause%20is%20always%20false.).
|
|
2083
|
+
|
|
2084
|
+
@see {@link Or}
|
|
2085
|
+
@see {@link AndAll}
|
|
2086
|
+
*/
|
|
2087
|
+
type OrAll<T extends readonly boolean[]> = SomeExtend<T, true>;
|
|
2088
|
+
//#endregion
|
|
2089
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/or.d.ts
|
|
2090
|
+
/**
|
|
2091
|
+
Returns a boolean for whether either of two given types is `true`.
|
|
2092
|
+
|
|
2093
|
+
Use-case: Constructing complex conditional types where at least one condition must be satisfied.
|
|
2094
|
+
|
|
2095
|
+
@example
|
|
2096
|
+
```
|
|
2097
|
+
import type {Or} from 'type-fest';
|
|
2098
|
+
|
|
2099
|
+
type TT = Or<true, true>;
|
|
2100
|
+
//=> true
|
|
2101
|
+
|
|
2102
|
+
type TF = Or<true, false>;
|
|
2103
|
+
//=> true
|
|
2104
|
+
|
|
2105
|
+
type FT = Or<false, true>;
|
|
2106
|
+
//=> true
|
|
2107
|
+
|
|
2108
|
+
type FF = Or<false, false>;
|
|
2109
|
+
//=> false
|
|
2110
|
+
```
|
|
2111
|
+
|
|
2112
|
+
Note: When `boolean` is passed as an argument, it is distributed into separate cases, and the final result is a union of those cases.
|
|
2113
|
+
For example, `Or<false, boolean>` expands to `Or<false, true> | Or<false, false>`, which simplifies to `true | false` (i.e., `boolean`).
|
|
2114
|
+
|
|
2115
|
+
@example
|
|
2116
|
+
```
|
|
2117
|
+
import type {Or} from 'type-fest';
|
|
2118
|
+
|
|
2119
|
+
type A = Or<false, boolean>;
|
|
2120
|
+
//=> boolean
|
|
2121
|
+
|
|
2122
|
+
type B = Or<boolean, false>;
|
|
2123
|
+
//=> boolean
|
|
2124
|
+
|
|
2125
|
+
type C = Or<true, boolean>;
|
|
2126
|
+
//=> true
|
|
2127
|
+
|
|
2128
|
+
type D = Or<boolean, true>;
|
|
2129
|
+
//=> true
|
|
2130
|
+
|
|
2131
|
+
type E = Or<boolean, boolean>;
|
|
2132
|
+
//=> boolean
|
|
2133
|
+
```
|
|
2134
|
+
|
|
2135
|
+
Note: If `never` is passed as an argument, it is treated as `false` and the result is computed accordingly.
|
|
2136
|
+
|
|
2137
|
+
@example
|
|
2138
|
+
```
|
|
2139
|
+
import type {Or} from 'type-fest';
|
|
2140
|
+
|
|
2141
|
+
type A = Or<true, never>;
|
|
2142
|
+
//=> true
|
|
2143
|
+
|
|
2144
|
+
type B = Or<never, true>;
|
|
2145
|
+
//=> true
|
|
2146
|
+
|
|
2147
|
+
type C = Or<false, never>;
|
|
2148
|
+
//=> false
|
|
2149
|
+
|
|
2150
|
+
type D = Or<never, false>;
|
|
2151
|
+
//=> false
|
|
2152
|
+
|
|
2153
|
+
type E = Or<boolean, never>;
|
|
2154
|
+
//=> boolean
|
|
2155
|
+
|
|
2156
|
+
type F = Or<never, boolean>;
|
|
2157
|
+
//=> boolean
|
|
2158
|
+
|
|
2159
|
+
type G = Or<never, never>;
|
|
2160
|
+
//=> false
|
|
2161
|
+
```
|
|
2162
|
+
|
|
2163
|
+
@see {@link OrAll}
|
|
2164
|
+
@see {@link And}
|
|
2165
|
+
@see {@link Xor}
|
|
2166
|
+
*/
|
|
2167
|
+
type Or<A extends boolean, B extends boolean> = OrAll<[A, B]>;
|
|
2168
|
+
//#endregion
|
|
2169
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/all-extend.d.ts
|
|
2170
|
+
/**
|
|
2171
|
+
@see {@link AllExtend}
|
|
2172
|
+
*/
|
|
2173
|
+
type AllExtendOptions = {
|
|
2174
|
+
/**
|
|
2175
|
+
Consider `never` elements to match the target type only if the target type itself is `never` (or `any`).
|
|
2176
|
+
- When set to `true` (default), `never` is _not_ treated as a bottom type, instead, it is treated as a type that matches only itself (or `any`).
|
|
2177
|
+
- When set to `false`, `never` is treated as a bottom type, and behaves as it normally would.
|
|
2178
|
+
@default true
|
|
2179
|
+
@example
|
|
2180
|
+
```
|
|
2181
|
+
import type {AllExtend} from 'type-fest';
|
|
2182
|
+
type A = AllExtend<[1, 2, never], number, {strictNever: true}>;
|
|
2183
|
+
//=> false
|
|
2184
|
+
type B = AllExtend<[1, 2, never], number, {strictNever: false}>;
|
|
2185
|
+
//=> true
|
|
2186
|
+
type C = AllExtend<[never, never], never, {strictNever: true}>;
|
|
2187
|
+
//=> true
|
|
2188
|
+
type D = AllExtend<[never, never], never, {strictNever: false}>;
|
|
2189
|
+
//=> true
|
|
2190
|
+
type E = AllExtend<['a', 'b', never], any, {strictNever: true}>;
|
|
2191
|
+
//=> true
|
|
2192
|
+
type F = AllExtend<['a', 'b', never], any, {strictNever: false}>;
|
|
2193
|
+
//=> true
|
|
2194
|
+
type G = AllExtend<[never, 1], never, {strictNever: true}>;
|
|
2195
|
+
//=> false
|
|
2196
|
+
type H = AllExtend<[never, 1], never, {strictNever: false}>;
|
|
2197
|
+
//=> false
|
|
2198
|
+
```
|
|
2199
|
+
*/
|
|
2200
|
+
strictNever?: boolean;
|
|
2201
|
+
};
|
|
2202
|
+
type DefaultAllExtendOptions = {
|
|
2203
|
+
strictNever: true;
|
|
2204
|
+
};
|
|
2205
|
+
/**
|
|
2206
|
+
Returns a boolean for whether every element in an array type extends another type.
|
|
2207
|
+
|
|
2208
|
+
@example
|
|
2209
|
+
```
|
|
2210
|
+
import type {AllExtend} from 'type-fest';
|
|
2211
|
+
|
|
2212
|
+
type A = AllExtend<[1, 2, 3], number>;
|
|
2213
|
+
//=> true
|
|
2214
|
+
|
|
2215
|
+
type B = AllExtend<[1, 2, '3'], number>;
|
|
2216
|
+
//=> false
|
|
2217
|
+
|
|
2218
|
+
type C = AllExtend<[number, number | string], number>;
|
|
2219
|
+
//=> boolean
|
|
2220
|
+
|
|
2221
|
+
type D = AllExtend<[true, boolean, true], true>;
|
|
2222
|
+
//=> boolean
|
|
2223
|
+
```
|
|
2224
|
+
|
|
2225
|
+
Note: Behaviour of optional elements depend on the `exactOptionalPropertyTypes` compiler option. When the option is disabled, the target type must include `undefined` for a successful match.
|
|
2226
|
+
|
|
2227
|
+
```
|
|
2228
|
+
// @exactOptionalPropertyTypes: true
|
|
2229
|
+
import type {AllExtend} from 'type-fest';
|
|
2230
|
+
|
|
2231
|
+
type A = AllExtend<[1?, 2?, 3?], number>;
|
|
2232
|
+
//=> true
|
|
2233
|
+
```
|
|
2234
|
+
|
|
2235
|
+
```
|
|
2236
|
+
// @exactOptionalPropertyTypes: false
|
|
2237
|
+
import type {AllExtend} from 'type-fest';
|
|
2238
|
+
|
|
2239
|
+
type A = AllExtend<[1?, 2?, 3?], number>;
|
|
2240
|
+
//=> boolean
|
|
2241
|
+
|
|
2242
|
+
type B = AllExtend<[1?, 2?, 3?], number | undefined>;
|
|
2243
|
+
//=> true
|
|
2244
|
+
```
|
|
2245
|
+
|
|
2246
|
+
@see {@link AllExtendOptions}
|
|
2247
|
+
|
|
2248
|
+
@category Utilities
|
|
2249
|
+
@category Array
|
|
2250
|
+
*/
|
|
2251
|
+
type AllExtend<TArray extends UnknownArray, Type, Options extends AllExtendOptions = {}> = _AllExtend<CollapseRestElement<TArray>, Type, ApplyDefaultOptions<AllExtendOptions, DefaultAllExtendOptions, Options>>;
|
|
2252
|
+
type _AllExtend<TArray extends UnknownArray, Type, Options extends Required<AllExtendOptions>> = IfNotAnyOrNever<TArray, TArray extends readonly [infer First, ...infer Rest] ? IsNever<First> extends true ? Or<Or<IsNever<Type>, IsAny<Type>>, Not<Options['strictNever']>> extends true // If target `Type` is also `never`, or is `any`, or `strictNever` is disabled, recurse further.
|
|
2253
|
+
? _AllExtend<Rest, Type, Options> : false : First extends Type ? _AllExtend<Rest, Type, Options> : false : true, false, false>;
|
|
2254
|
+
//#endregion
|
|
2255
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/and-all.d.ts
|
|
2256
|
+
/**
|
|
2257
|
+
Returns a boolean for whether all of the given elements are `true`.
|
|
2258
|
+
|
|
2259
|
+
Use-cases:
|
|
2260
|
+
- Check if all conditions in a list of booleans are met.
|
|
2261
|
+
|
|
2262
|
+
@example
|
|
2263
|
+
```
|
|
2264
|
+
import type {AndAll} from 'type-fest';
|
|
2265
|
+
|
|
2266
|
+
type TTT = AndAll<[true, true, true]>;
|
|
2267
|
+
//=> true
|
|
2268
|
+
|
|
2269
|
+
type TTF = AndAll<[true, true, false]>;
|
|
2270
|
+
//=> false
|
|
2271
|
+
|
|
2272
|
+
type TFT = AndAll<[true, false, true]>;
|
|
2273
|
+
//=> false
|
|
2274
|
+
```
|
|
2275
|
+
|
|
2276
|
+
Note: When `boolean` is passed as an element, it is distributed into separate cases, and the final result is a union of those cases.
|
|
2277
|
+
For example, `AndAll<[true, boolean]>` expands to `AndAll<[true, true]> | AndAll<[true, false]>`, which simplifies to `true | false` (i.e., `boolean`).
|
|
2278
|
+
|
|
2279
|
+
@example
|
|
2280
|
+
```
|
|
2281
|
+
import type {AndAll} from 'type-fest';
|
|
2282
|
+
|
|
2283
|
+
type A = AndAll<[true, boolean]>;
|
|
2284
|
+
//=> boolean
|
|
2285
|
+
|
|
2286
|
+
type B = AndAll<[false, boolean]>;
|
|
2287
|
+
//=> false
|
|
2288
|
+
```
|
|
2289
|
+
|
|
2290
|
+
Note: If any of the elements is `never`, the result becomes `false`.
|
|
2291
|
+
|
|
2292
|
+
@example
|
|
2293
|
+
```
|
|
2294
|
+
import type {AndAll} from 'type-fest';
|
|
2295
|
+
|
|
2296
|
+
type A = AndAll<[true, true, never]>;
|
|
2297
|
+
//=> false
|
|
2298
|
+
|
|
2299
|
+
type B = AndAll<[false, never, never]>;
|
|
2300
|
+
//=> false
|
|
2301
|
+
|
|
2302
|
+
type C = AndAll<[never, never, never]>;
|
|
2303
|
+
//=> false
|
|
2304
|
+
|
|
2305
|
+
type D = AndAll<[boolean, true, never]>;
|
|
2306
|
+
//=> false
|
|
2307
|
+
```
|
|
2308
|
+
|
|
2309
|
+
Note: If `any` is passed as an element, it is treated as `boolean` and the result is computed accordingly.
|
|
2310
|
+
|
|
2311
|
+
@example
|
|
2312
|
+
```
|
|
2313
|
+
import type {AndAll} from 'type-fest';
|
|
2314
|
+
|
|
2315
|
+
type A = AndAll<[false, any]>;
|
|
2316
|
+
//=> false
|
|
2317
|
+
|
|
2318
|
+
type B = AndAll<[true, any]>;
|
|
2319
|
+
//=> boolean
|
|
2320
|
+
```
|
|
2321
|
+
|
|
2322
|
+
Note: `AndAll<[]>` evaluates to `true` due to the concept of [vacuous truth](https://en.wikipedia.org/wiki/Logical_conjunction#:~:text=In%20keeping%20with%20the%20concept%20of%20vacuous%20truth%2C%20when%20conjunction%20is%20defined%20as%20an%20operator%20or%20function%20of%20arbitrary%20arity%2C%20the%20empty%20conjunction%20(AND%2Ding%20over%20an%20empty%20set%20of%20operands)%20is%20often%20defined%20as%20having%20the%20result%20true.), i.e., there are no `false` elements in an empty tuple.
|
|
2323
|
+
|
|
2324
|
+
@see {@link And}
|
|
2325
|
+
@see {@link OrAll}
|
|
2326
|
+
*/
|
|
2327
|
+
type AndAll<T extends readonly boolean[]> = AllExtend<T, true>;
|
|
2328
|
+
//#endregion
|
|
2329
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/and.d.ts
|
|
2330
|
+
/**
|
|
2331
|
+
Returns a boolean for whether two given types are both `true`.
|
|
2332
|
+
|
|
2333
|
+
Use-case: Constructing complex conditional types where multiple conditions must be satisfied.
|
|
2334
|
+
|
|
2335
|
+
@example
|
|
2336
|
+
```
|
|
2337
|
+
import type {And} from 'type-fest';
|
|
2338
|
+
|
|
2339
|
+
type TT = And<true, true>;
|
|
2340
|
+
//=> true
|
|
2341
|
+
|
|
2342
|
+
type TF = And<true, false>;
|
|
2343
|
+
//=> false
|
|
2344
|
+
|
|
2345
|
+
type FT = And<false, true>;
|
|
2346
|
+
//=> false
|
|
2347
|
+
|
|
2348
|
+
type FF = And<false, false>;
|
|
2349
|
+
//=> false
|
|
2350
|
+
```
|
|
2351
|
+
|
|
2352
|
+
Note: When `boolean` is passed as an argument, it is distributed into separate cases, and the final result is a union of those cases.
|
|
2353
|
+
For example, `And<true, boolean>` expands to `And<true, true> | And<true, false>`, which simplifies to `true | false` (i.e., `boolean`).
|
|
2354
|
+
|
|
2355
|
+
@example
|
|
2356
|
+
```
|
|
2357
|
+
import type {And} from 'type-fest';
|
|
2358
|
+
|
|
2359
|
+
type A = And<true, boolean>;
|
|
2360
|
+
//=> boolean
|
|
2361
|
+
|
|
2362
|
+
type B = And<boolean, true>;
|
|
2363
|
+
//=> boolean
|
|
2364
|
+
|
|
2365
|
+
type C = And<false, boolean>;
|
|
2366
|
+
//=> false
|
|
2367
|
+
|
|
2368
|
+
type D = And<boolean, false>;
|
|
2369
|
+
//=> false
|
|
2370
|
+
|
|
2371
|
+
type E = And<boolean, boolean>;
|
|
2372
|
+
//=> boolean
|
|
2373
|
+
```
|
|
2374
|
+
|
|
2375
|
+
Note: If either of the types is `never`, the result becomes `false`.
|
|
2376
|
+
|
|
2377
|
+
@example
|
|
2378
|
+
```
|
|
2379
|
+
import type {And} from 'type-fest';
|
|
2380
|
+
|
|
2381
|
+
type A = And<true, never>;
|
|
2382
|
+
//=> false
|
|
2383
|
+
|
|
2384
|
+
type B = And<never, true>;
|
|
2385
|
+
//=> false
|
|
2386
|
+
|
|
2387
|
+
type C = And<false, never>;
|
|
2388
|
+
//=> false
|
|
2389
|
+
|
|
2390
|
+
type D = And<never, false>;
|
|
2391
|
+
//=> false
|
|
2392
|
+
|
|
2393
|
+
type E = And<boolean, never>;
|
|
2394
|
+
//=> false
|
|
2395
|
+
|
|
2396
|
+
type F = And<never, boolean>;
|
|
2397
|
+
//=> false
|
|
2398
|
+
|
|
2399
|
+
type G = And<never, never>;
|
|
2400
|
+
//=> false
|
|
2401
|
+
```
|
|
2402
|
+
|
|
2403
|
+
@see {@link AndAll}
|
|
2404
|
+
@see {@link Or}
|
|
2405
|
+
@see {@link Xor}
|
|
2406
|
+
*/
|
|
2407
|
+
type And<A extends boolean, B extends boolean> = AndAll<[A, B]>;
|
|
2408
|
+
//#endregion
|
|
2409
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/except.d.ts
|
|
2410
|
+
/**
|
|
2411
|
+
Filter out keys from an object.
|
|
2412
|
+
|
|
2413
|
+
Returns `never` if `Exclude` is strictly equal to `Key`.
|
|
2414
|
+
Returns `never` if `Key` extends `Exclude`.
|
|
2415
|
+
Returns `Key` otherwise.
|
|
2416
|
+
|
|
2417
|
+
@example
|
|
2418
|
+
```
|
|
2419
|
+
type Filtered = Filter<'foo', 'foo'>;
|
|
2420
|
+
//=> never
|
|
2421
|
+
```
|
|
2422
|
+
|
|
2423
|
+
@example
|
|
2424
|
+
```
|
|
2425
|
+
type Filtered = Filter<'bar', string>;
|
|
2426
|
+
//=> never
|
|
2427
|
+
```
|
|
2428
|
+
|
|
2429
|
+
@example
|
|
2430
|
+
```
|
|
2431
|
+
type Filtered = Filter<'bar', 'foo'>;
|
|
2432
|
+
//=> 'bar'
|
|
2433
|
+
```
|
|
2434
|
+
|
|
2435
|
+
@see {Except}
|
|
2436
|
+
*/
|
|
2437
|
+
type Filter<KeyType, ExcludeType> = IsEqual<KeyType, ExcludeType> extends true ? never : (KeyType extends ExcludeType ? never : KeyType);
|
|
2438
|
+
type ExceptOptions = {
|
|
2439
|
+
/**
|
|
2440
|
+
Disallow assigning non-specified properties.
|
|
2441
|
+
Note that any omitted properties in the resulting type will be present in autocomplete as `undefined`.
|
|
2442
|
+
@default false
|
|
2443
|
+
*/
|
|
2444
|
+
requireExactProps?: boolean;
|
|
2445
|
+
};
|
|
2446
|
+
type DefaultExceptOptions = {
|
|
2447
|
+
requireExactProps: false;
|
|
2448
|
+
};
|
|
2449
|
+
/**
|
|
2450
|
+
Create a type from an object type without certain keys.
|
|
2451
|
+
|
|
2452
|
+
We recommend setting the `requireExactProps` option to `true`.
|
|
2453
|
+
|
|
2454
|
+
This type is a stricter version of [`Omit`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-5.html#the-omit-helper-type). The `Omit` type does not restrict the omitted keys to be keys present on the given type, while `Except` does. The benefits of a stricter type are avoiding typos and allowing the compiler to pick up on rename refactors automatically.
|
|
2455
|
+
|
|
2456
|
+
This type was proposed to the TypeScript team, which declined it, saying they prefer that libraries implement stricter versions of the built-in types ([microsoft/TypeScript#30825](https://github.com/microsoft/TypeScript/issues/30825#issuecomment-523668235)).
|
|
2457
|
+
|
|
2458
|
+
@example
|
|
2459
|
+
```
|
|
2460
|
+
import type {Except} from 'type-fest';
|
|
2461
|
+
|
|
2462
|
+
type Foo = {
|
|
2463
|
+
a: number;
|
|
2464
|
+
b: string;
|
|
2465
|
+
};
|
|
2466
|
+
|
|
2467
|
+
type FooWithoutA = Except<Foo, 'a'>;
|
|
2468
|
+
//=> {b: string}
|
|
2469
|
+
|
|
2470
|
+
// @ts-expect-error
|
|
2471
|
+
const fooWithoutA: FooWithoutA = {a: 1, b: '2'};
|
|
2472
|
+
// errors: 'a' does not exist in type '{ b: string; }'
|
|
2473
|
+
|
|
2474
|
+
type FooWithoutB = Except<Foo, 'b', {requireExactProps: true}>;
|
|
2475
|
+
//=> {a: number} & Partial<Record<'b', never>>
|
|
2476
|
+
|
|
2477
|
+
// @ts-expect-error
|
|
2478
|
+
const fooWithoutB: FooWithoutB = {a: 1, b: '2'};
|
|
2479
|
+
// errors at 'b': Type 'string' is not assignable to type 'undefined'.
|
|
2480
|
+
|
|
2481
|
+
// The `Omit` utility type doesn't work when omitting specific keys from objects containing index signatures.
|
|
2482
|
+
|
|
2483
|
+
// Consider the following example:
|
|
2484
|
+
|
|
2485
|
+
type UserData = {
|
|
2486
|
+
[metadata: string]: string;
|
|
2487
|
+
email: string;
|
|
2488
|
+
name: string;
|
|
2489
|
+
role: 'admin' | 'user';
|
|
2490
|
+
};
|
|
2491
|
+
|
|
2492
|
+
// `Omit` clearly doesn't behave as expected in this case:
|
|
2493
|
+
type PostPayload = Omit<UserData, 'email'>;
|
|
2494
|
+
//=> {[x: string]: string; [x: number]: string}
|
|
2495
|
+
|
|
2496
|
+
// In situations like this, `Except` works better.
|
|
2497
|
+
// It simply removes the `email` key while preserving all the other keys.
|
|
2498
|
+
type PostPayloadFixed = Except<UserData, 'email'>;
|
|
2499
|
+
//=> {[x: string]: string; name: string; role: 'admin' | 'user'}
|
|
2500
|
+
```
|
|
2501
|
+
|
|
2502
|
+
@category Object
|
|
2503
|
+
*/
|
|
2504
|
+
type Except<ObjectType, KeysType extends keyof ObjectType, Options extends ExceptOptions = {}> = _Except<ObjectType, KeysType, ApplyDefaultOptions<ExceptOptions, DefaultExceptOptions, Options>>;
|
|
2505
|
+
type _Except<ObjectType, KeysType extends keyof ObjectType, Options extends Required<ExceptOptions>> = { [KeyType in keyof ObjectType as Filter<KeyType, KeysType>]: ObjectType[KeyType] } & (Options['requireExactProps'] extends true ? Partial<Record<KeysType, never>> : {});
|
|
2506
|
+
//#endregion
|
|
2507
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/exclude-exactly.d.ts
|
|
2508
|
+
/**
|
|
2509
|
+
A stricter version of `Exclude<T, U>` that excludes types only when they are exactly identical.
|
|
2510
|
+
|
|
2511
|
+
@example
|
|
2512
|
+
```
|
|
2513
|
+
import type {ExcludeExactly} from 'type-fest';
|
|
2514
|
+
|
|
2515
|
+
type TestExclude1 = Exclude<'a' | 'b' | 'c' | 1 | 2 | 3, string>;
|
|
2516
|
+
//=> 1 | 2 | 3
|
|
2517
|
+
|
|
2518
|
+
type TestExcludeExactly1 = ExcludeExactly<'a' | 'b' | 'c' | 1 | 2 | 3, string>;
|
|
2519
|
+
//=> 'a' | 'b' | 'c' | 1 | 2 | 3
|
|
2520
|
+
|
|
2521
|
+
type TestExclude2 = Exclude<'a' | 'b' | 'c' | 1 | 2 | 3, any>;
|
|
2522
|
+
//=> never
|
|
2523
|
+
|
|
2524
|
+
type TestExcludeExactly2 = ExcludeExactly<'a' | 'b' | 'c' | 1 | 2 | 3, any>;
|
|
2525
|
+
//=> 'a' | 'b' | 'c' | 1 | 2 | 3
|
|
2526
|
+
|
|
2527
|
+
type TestExclude3 = Exclude<{a: string} | {a: string; b: string}, {a: string}>;
|
|
2528
|
+
//=> never
|
|
2529
|
+
|
|
2530
|
+
type TestExcludeExactly3 = ExcludeExactly<{a: string} | {a: string; b: string}, {a: string}>;
|
|
2531
|
+
//=> {a: string; b: string}
|
|
2532
|
+
```
|
|
2533
|
+
|
|
2534
|
+
@category Improved Built-in
|
|
2535
|
+
*/
|
|
2536
|
+
type ExcludeExactly<Union, Delete> = IfNotAnyOrNever<Union, _ExcludeExactly<Union, Delete>, // If `Union` is `any`, then if `Delete` is `any`, return `never`, else return `Union`.
|
|
2537
|
+
If<IsAny<Delete>, never, Union>, // If `Union` is `never`, then if `Delete` is `never`, return `never`, else return `Union`.
|
|
2538
|
+
If<IsNever<Delete>, never, Union>>;
|
|
2539
|
+
type _ExcludeExactly<Union, Delete> = IfNotAnyOrNever<Delete, Union extends unknown // For distributing `Union`
|
|
2540
|
+
? [Delete extends unknown // For distributing `Delete`
|
|
2541
|
+
? If<IsEqual<Union, Delete>, true, never> : never] extends [never] ? Union : never : never, // If `Delete` is `any` or `never`, then return `Union`,
|
|
2542
|
+
// because `Union` cannot be `any` or `never` here.
|
|
2543
|
+
Union, Union>;
|
|
2544
|
+
//#endregion
|
|
2545
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/union-member.d.ts
|
|
2546
|
+
/**
|
|
2547
|
+
Returns an arbitrary member of a union type.
|
|
2548
|
+
|
|
2549
|
+
Use-cases:
|
|
2550
|
+
- Implementing recursive type functions that accept a union type.
|
|
2551
|
+
|
|
2552
|
+
@example
|
|
2553
|
+
```
|
|
2554
|
+
import type {UnionMember, IsNever} from 'type-fest';
|
|
2555
|
+
|
|
2556
|
+
type UnionLength<T, Acc extends any[] = []> =
|
|
2557
|
+
UnionMember<T> extends infer Member
|
|
2558
|
+
? IsNever<Member> extends false
|
|
2559
|
+
? UnionLength<Exclude<T, Member>, [...Acc, Member]>
|
|
2560
|
+
: Acc['length']
|
|
2561
|
+
: never;
|
|
2562
|
+
|
|
2563
|
+
type T1 = UnionLength<'foo' | 'bar' | 'baz'>;
|
|
2564
|
+
//=> 3
|
|
2565
|
+
|
|
2566
|
+
type T2 = UnionLength<{a: string}>;
|
|
2567
|
+
//=> 1
|
|
2568
|
+
```
|
|
2569
|
+
|
|
2570
|
+
- Picking an arbitrary member from a union
|
|
2571
|
+
|
|
2572
|
+
@example
|
|
2573
|
+
```
|
|
2574
|
+
import type {UnionMember, Primitive, LiteralToPrimitive} from 'type-fest';
|
|
2575
|
+
|
|
2576
|
+
type IsHomogenous<T extends Primitive> = [T] extends [LiteralToPrimitive<UnionMember<T>>] ? true : false;
|
|
2577
|
+
|
|
2578
|
+
type T1 = IsHomogenous<1 | 2 | 3 | 4>;
|
|
2579
|
+
//=> true
|
|
2580
|
+
|
|
2581
|
+
type T2 = IsHomogenous<'foo' | 'bar'>;
|
|
2582
|
+
//=> true
|
|
2583
|
+
|
|
2584
|
+
type T3 = IsHomogenous<'foo' | 'bar' | 1>;
|
|
2585
|
+
//=> false
|
|
2586
|
+
```
|
|
2587
|
+
|
|
2588
|
+
Returns `never` when the input is `never`.
|
|
2589
|
+
|
|
2590
|
+
@example
|
|
2591
|
+
```
|
|
2592
|
+
import type {UnionMember} from 'type-fest';
|
|
2593
|
+
|
|
2594
|
+
type LastNever = UnionMember<never>;
|
|
2595
|
+
//=> never
|
|
2596
|
+
```
|
|
2597
|
+
|
|
2598
|
+
@category Type
|
|
2599
|
+
*/
|
|
2600
|
+
type UnionMember<T> = IsNever<T> extends true ? never : UnionToIntersection<T extends any ? () => T : never> extends (() => (infer R)) ? R : never;
|
|
2601
|
+
//#endregion
|
|
2602
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/union-to-tuple.d.ts
|
|
2603
|
+
/**
|
|
2604
|
+
Convert a union type into an unordered tuple type of its elements.
|
|
2605
|
+
|
|
2606
|
+
"Unordered" means the elements of the tuple are not guaranteed to be in the same order as in the union type. The arrangement can appear random and may change at any time.
|
|
2607
|
+
|
|
2608
|
+
This can be useful when you have objects with a finite set of keys and want a type defining only the allowed keys, but do not want to repeat yourself.
|
|
2609
|
+
|
|
2610
|
+
@example
|
|
2611
|
+
```
|
|
2612
|
+
import type {UnionToTuple} from 'type-fest';
|
|
2613
|
+
|
|
2614
|
+
type Numbers = 1 | 2 | 3;
|
|
2615
|
+
type NumbersTuple = UnionToTuple<Numbers>;
|
|
2616
|
+
//=> [1, 2, 3]
|
|
2617
|
+
```
|
|
2618
|
+
|
|
2619
|
+
@example
|
|
2620
|
+
```
|
|
2621
|
+
import type {UnionToTuple} from 'type-fest';
|
|
2622
|
+
|
|
2623
|
+
const pets = {
|
|
2624
|
+
dog: '🐶',
|
|
2625
|
+
cat: '🐱',
|
|
2626
|
+
snake: '🐍',
|
|
2627
|
+
};
|
|
2628
|
+
|
|
2629
|
+
type Pet = keyof typeof pets;
|
|
2630
|
+
//=> 'dog' | 'cat' | 'snake'
|
|
2631
|
+
|
|
2632
|
+
const petList = Object.keys(pets) as UnionToTuple<Pet>;
|
|
2633
|
+
//=> ['dog', 'cat', 'snake']
|
|
2634
|
+
```
|
|
2635
|
+
|
|
2636
|
+
@category Array
|
|
2637
|
+
*/
|
|
2638
|
+
type UnionToTuple<Union> = _UnionToTuple<Union> extends infer Result extends UnknownArray ? Result : never;
|
|
2639
|
+
// Nudges the compiler that `UnionToTuple` always yields an array.
|
|
2640
|
+
type _UnionToTuple<Union, Accumulator extends UnknownArray = [], Member = UnionMember<Union>> = IsNever<Union> extends true ? Accumulator : _UnionToTuple<ExcludeExactly<Union, Member>, [Member, ...Accumulator]>;
|
|
2641
|
+
//#endregion
|
|
2642
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/set-optional.d.ts
|
|
2643
|
+
/**
|
|
2644
|
+
Create a type that makes the given keys optional, while keeping the remaining keys as is.
|
|
2645
|
+
|
|
2646
|
+
Use-case: You want to define a single model where the only thing that changes is whether or not some of the keys are optional.
|
|
2647
|
+
|
|
2648
|
+
@example
|
|
2649
|
+
```
|
|
2650
|
+
import type {SetOptional} from 'type-fest';
|
|
2651
|
+
|
|
2652
|
+
type Foo = {
|
|
2653
|
+
a: number;
|
|
2654
|
+
b?: string;
|
|
2655
|
+
c: boolean;
|
|
2656
|
+
};
|
|
2657
|
+
|
|
2658
|
+
type SomeOptional = SetOptional<Foo, 'b' | 'c'>;
|
|
2659
|
+
//=> {a: number; b?: string; c?: boolean}
|
|
2660
|
+
```
|
|
2661
|
+
|
|
2662
|
+
@category Object
|
|
2663
|
+
*/
|
|
2664
|
+
type SetOptional<BaseType, Keys extends keyof BaseType> = (BaseType extends ((...arguments_: never) => any) ? (...arguments_: Parameters<BaseType>) => ReturnType<BaseType> : unknown) & _SetOptional<BaseType, Keys>;
|
|
2665
|
+
type _SetOptional<BaseType, Keys extends keyof BaseType> = BaseType extends unknown // To distribute `BaseType` when it's a union type.
|
|
2666
|
+
? Simplify< // Pick just the keys that are readonly from the base type.
|
|
2667
|
+
Except<BaseType, Keys> // Pick the keys that should be mutable from the base type and make them mutable.
|
|
2668
|
+
& Partial<HomomorphicPick<BaseType, Keys>>> : never;
|
|
2669
|
+
//#endregion
|
|
2670
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/value-of.d.ts
|
|
2671
|
+
/**
|
|
2672
|
+
Create a union of the given object's values, and optionally specify which keys to get the values from.
|
|
2673
|
+
|
|
2674
|
+
Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/31438) if you want to have this type as a built-in in TypeScript.
|
|
2675
|
+
|
|
2676
|
+
@example
|
|
2677
|
+
```
|
|
2678
|
+
import type {ValueOf} from 'type-fest';
|
|
2679
|
+
|
|
2680
|
+
type A = ValueOf<{id: number; name: string; active: boolean}>;
|
|
2681
|
+
//=> string | number | boolean
|
|
2682
|
+
|
|
2683
|
+
type B = ValueOf<{id: number; name: string; active: boolean}, 'name'>;
|
|
2684
|
+
//=> string
|
|
2685
|
+
|
|
2686
|
+
type C = ValueOf<{id: number; name: string; active: boolean}, 'id' | 'name'>;
|
|
2687
|
+
//=> string | number
|
|
2688
|
+
```
|
|
2689
|
+
|
|
2690
|
+
@category Object
|
|
2691
|
+
*/
|
|
2692
|
+
type ValueOf<ObjectType, ValueType extends keyof ObjectType = keyof ObjectType> = ObjectType[ValueType];
|
|
2693
|
+
//#endregion
|
|
2694
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/split.d.ts
|
|
2695
|
+
/**
|
|
2696
|
+
Split options.
|
|
2697
|
+
|
|
2698
|
+
@see {@link Split}
|
|
2699
|
+
*/
|
|
2700
|
+
type SplitOptions = {
|
|
2701
|
+
/**
|
|
2702
|
+
When enabled, instantiations with non-literal string types (e.g., `string`, `Uppercase<string>`, `on${string}`) simply return back `string[]` without performing any splitting, as the exact structure cannot be statically determined.
|
|
2703
|
+
@default true
|
|
2704
|
+
@example
|
|
2705
|
+
```ts
|
|
2706
|
+
import type {Split} from 'type-fest';
|
|
2707
|
+
type Example1 = Split<`foo.${string}.bar`, '.', {strictLiteralChecks: false}>;
|
|
2708
|
+
//=> ['foo', string, 'bar']
|
|
2709
|
+
type Example2 = Split<`foo.${string}`, '.', {strictLiteralChecks: true}>;
|
|
2710
|
+
//=> string[]
|
|
2711
|
+
type Example3 = Split<'foobarbaz', `b${string}`, {strictLiteralChecks: false}>;
|
|
2712
|
+
//=> ['foo', 'r', 'z']
|
|
2713
|
+
type Example4 = Split<'foobarbaz', `b${string}`, {strictLiteralChecks: true}>;
|
|
2714
|
+
//=> string[]
|
|
2715
|
+
```
|
|
2716
|
+
*/
|
|
2717
|
+
strictLiteralChecks?: boolean;
|
|
2718
|
+
};
|
|
2719
|
+
type DefaultSplitOptions = {
|
|
2720
|
+
strictLiteralChecks: true;
|
|
2721
|
+
};
|
|
2722
|
+
/**
|
|
2723
|
+
Represents an array of strings split using a given character or character set.
|
|
2724
|
+
|
|
2725
|
+
Use-case: Defining the return type of a method like `String.prototype.split`.
|
|
2726
|
+
|
|
2727
|
+
@example
|
|
2728
|
+
```
|
|
2729
|
+
import type {Split} from 'type-fest';
|
|
2730
|
+
|
|
2731
|
+
declare function split<S extends string, D extends string>(string: S, separator: D): Split<S, D>;
|
|
2732
|
+
|
|
2733
|
+
type Item = 'foo' | 'bar' | 'baz' | 'waldo';
|
|
2734
|
+
const items = 'foo,bar,baz,waldo';
|
|
2735
|
+
const array: Item[] = split(items, ',');
|
|
2736
|
+
```
|
|
2737
|
+
|
|
2738
|
+
@see {@link SplitOptions}
|
|
2739
|
+
|
|
2740
|
+
@category String
|
|
2741
|
+
@category Template literal
|
|
2742
|
+
*/
|
|
2743
|
+
type Split<S extends string, Delimiter extends string, Options extends SplitOptions = {}> = SplitHelper<S, Delimiter, ApplyDefaultOptions<SplitOptions, DefaultSplitOptions, Options>>;
|
|
2744
|
+
type SplitHelper<S extends string, Delimiter extends string, Options extends Required<SplitOptions>, Accumulator extends string[] = []> = S extends string // For distributing `S`
|
|
2745
|
+
? Delimiter extends string // For distributing `Delimiter`
|
|
2746
|
+
// If `strictLiteralChecks` is `false` OR `S` and `Delimiter` both are string literals, then perform the split
|
|
2747
|
+
? Or<Not<Options['strictLiteralChecks']>, And<IsStringLiteral<S>, IsStringLiteral<Delimiter>>> extends true ? S extends `${infer Head}${Delimiter}${infer Tail}` ? SplitHelper<Tail, Delimiter, Options, [...Accumulator, Head]> : Delimiter extends '' ? S extends '' ? Accumulator : [...Accumulator, S] : [...Accumulator, S] // Otherwise, return `string[]`
|
|
2748
|
+
: string[] : never // Should never happen
|
|
2749
|
+
: never; // Should never happen
|
|
2750
|
+
//#endregion
|
|
2751
|
+
//#region ../../node_modules/.pnpm/type-fest@5.6.0/node_modules/type-fest/source/replace.d.ts
|
|
2752
|
+
type ReplaceOptions = {
|
|
2753
|
+
all?: boolean;
|
|
2754
|
+
};
|
|
2755
|
+
type DefaultReplaceOptions = {
|
|
2756
|
+
all: false;
|
|
2757
|
+
};
|
|
2758
|
+
/**
|
|
2759
|
+
Represents a string with some or all matches replaced by a replacement.
|
|
2760
|
+
|
|
2761
|
+
Use-case:
|
|
2762
|
+
- `kebab-case-path` to `dotted.path.notation`
|
|
2763
|
+
- Changing date/time format: `01-08-2042` → `01/08/2042`
|
|
2764
|
+
- Manipulation of type properties, for example, removal of prefixes
|
|
2765
|
+
|
|
2766
|
+
@example
|
|
2767
|
+
```
|
|
2768
|
+
import type {Replace} from 'type-fest';
|
|
2769
|
+
|
|
2770
|
+
declare function replace<
|
|
2771
|
+
Input extends string,
|
|
2772
|
+
Search extends string,
|
|
2773
|
+
Replacement extends string,
|
|
2774
|
+
>(
|
|
2775
|
+
input: Input,
|
|
2776
|
+
search: Search,
|
|
2777
|
+
replacement: Replacement,
|
|
2778
|
+
): Replace<Input, Search, Replacement>;
|
|
2779
|
+
|
|
2780
|
+
declare function replaceAll<
|
|
2781
|
+
Input extends string,
|
|
2782
|
+
Search extends string,
|
|
2783
|
+
Replacement extends string,
|
|
2784
|
+
>(
|
|
2785
|
+
input: Input,
|
|
2786
|
+
search: Search,
|
|
2787
|
+
replacement: Replacement,
|
|
2788
|
+
): Replace<Input, Search, Replacement, {all: true}>;
|
|
2789
|
+
|
|
2790
|
+
// The return type is the exact string literal, not just `string`.
|
|
2791
|
+
|
|
2792
|
+
replace('hello ?', '?', '🦄');
|
|
2793
|
+
//=> 'hello 🦄'
|
|
2794
|
+
|
|
2795
|
+
replace('hello ??', '?', '❓');
|
|
2796
|
+
//=> 'hello ❓?'
|
|
2797
|
+
|
|
2798
|
+
replaceAll('10:42:00', ':', '-');
|
|
2799
|
+
//=> '10-42-00'
|
|
2800
|
+
|
|
2801
|
+
replaceAll('__userName__', '__', '');
|
|
2802
|
+
//=> 'userName'
|
|
2803
|
+
|
|
2804
|
+
replaceAll('My Cool Title', ' ', '');
|
|
2805
|
+
//=> 'MyCoolTitle'
|
|
2806
|
+
```
|
|
2807
|
+
|
|
2808
|
+
@category String
|
|
2809
|
+
@category Template literal
|
|
2810
|
+
*/
|
|
2811
|
+
type Replace<Input extends string, Search extends string, Replacement extends string, Options extends ReplaceOptions = {}> = _Replace<Input, Search, Replacement, ApplyDefaultOptions<ReplaceOptions, DefaultReplaceOptions, Options>>;
|
|
2812
|
+
type _Replace<Input extends string, Search extends string, Replacement extends string, Options extends Required<ReplaceOptions>, Accumulator extends string = ''> = Search extends string // For distributing `Search`
|
|
2813
|
+
? Replacement extends string // For distributing `Replacement`
|
|
2814
|
+
? Input extends `${infer Head}${Search}${infer Tail}` ? Options['all'] extends true ? _Replace<Tail, Search, Replacement, Options, `${Accumulator}${Head}${Replacement}`> : `${Head}${Replacement}${Tail}` : `${Accumulator}${Input}` : never : never;
|
|
2815
|
+
//#endregion
|
|
2816
|
+
//#region ../../node_modules/.pnpm/ts-toolbelt@9.6.0/node_modules/ts-toolbelt/out/List/List.d.ts
|
|
2817
|
+
/**
|
|
2818
|
+
* A [[List]]
|
|
2819
|
+
* @param A its type
|
|
2820
|
+
* @returns [[List]]
|
|
2821
|
+
* @example
|
|
2822
|
+
* ```ts
|
|
2823
|
+
* type list0 = [1, 2, 3]
|
|
2824
|
+
* type list1 = number[]
|
|
2825
|
+
* ```
|
|
2826
|
+
*/
|
|
2827
|
+
declare type List<A = any> = ReadonlyArray<A>;
|
|
2828
|
+
//#endregion
|
|
2829
|
+
//#region ../../node_modules/.pnpm/ts-toolbelt@9.6.0/node_modules/ts-toolbelt/out/Any/Cast.d.ts
|
|
2830
|
+
/**
|
|
2831
|
+
* Ask TS to re-check that `A1` extends `A2`.
|
|
2832
|
+
* And if it fails, `A2` will be enforced anyway.
|
|
2833
|
+
* Can also be used to add constraints on parameters.
|
|
2834
|
+
* @param A1 to check against
|
|
2835
|
+
* @param A2 to cast to
|
|
2836
|
+
* @returns `A1 | A2`
|
|
2837
|
+
* @example
|
|
2838
|
+
* ```ts
|
|
2839
|
+
* import {A} from 'ts-toolbelt'
|
|
2840
|
+
*
|
|
2841
|
+
* type test0 = A.Cast<'42', string> // '42'
|
|
2842
|
+
* type test1 = A.Cast<'42', number> // number
|
|
2843
|
+
* ```
|
|
2844
|
+
*/
|
|
2845
|
+
declare type Cast<A1 extends any, A2 extends any> = A1 extends A2 ? A1 : A2;
|
|
2846
|
+
//#endregion
|
|
2847
|
+
//#region ../../node_modules/.pnpm/ts-toolbelt@9.6.0/node_modules/ts-toolbelt/out/Any/Extends.d.ts
|
|
2848
|
+
/**
|
|
2849
|
+
* Check whether `A1` is part of `A2` or not. The difference with
|
|
2850
|
+
* `extends` is that it forces a [[Boolean]] return.
|
|
2851
|
+
* @param A1
|
|
2852
|
+
* @param A2
|
|
2853
|
+
* @returns [[Boolean]]
|
|
2854
|
+
* @example
|
|
2855
|
+
* ```ts
|
|
2856
|
+
* import {A} from 'ts-toolbelt'
|
|
2857
|
+
*
|
|
2858
|
+
* type test0 = A.Extends<'a' | 'b', 'b'> // Boolean
|
|
2859
|
+
* type test1 = A.Extends<'a', 'a' | 'b'> // True
|
|
2860
|
+
*
|
|
2861
|
+
* type test2 = A.Extends<{a: string}, {a: any}> // True
|
|
2862
|
+
* type test3 = A.Extends<{a: any}, {a: any, b: any}> // False
|
|
2863
|
+
*
|
|
2864
|
+
* type test4 = A.Extends<never, never> // False
|
|
2865
|
+
* /// Nothing cannot extend nothing, use `A.Equals`
|
|
2866
|
+
* ```
|
|
2867
|
+
*/
|
|
2868
|
+
declare type Extends<A1 extends any, A2 extends any> = [A1] extends [never] ? 0 : A1 extends A2 ? 1 : 0;
|
|
2869
|
+
//#endregion
|
|
2870
|
+
//#region ../../node_modules/.pnpm/ts-toolbelt@9.6.0/node_modules/ts-toolbelt/out/Iteration/Iteration.d.ts
|
|
2871
|
+
/**
|
|
2872
|
+
* An entry of `IterationMap`
|
|
2873
|
+
*/
|
|
2874
|
+
declare type Iteration = [value: number, sign: '-' | '0' | '+', prev: keyof IterationMap, next: keyof IterationMap, oppo: keyof IterationMap];
|
|
2875
|
+
declare type IterationMap = {
|
|
2876
|
+
'__': [number, '-' | '0' | '+', '__', '__', '__'];
|
|
2877
|
+
'-100': [-100, '-', '__', '-99', '100'];
|
|
2878
|
+
'-99': [-99, '-', '-100', '-98', '99'];
|
|
2879
|
+
'-98': [-98, '-', '-99', '-97', '98'];
|
|
2880
|
+
'-97': [-97, '-', '-98', '-96', '97'];
|
|
2881
|
+
'-96': [-96, '-', '-97', '-95', '96'];
|
|
2882
|
+
'-95': [-95, '-', '-96', '-94', '95'];
|
|
2883
|
+
'-94': [-94, '-', '-95', '-93', '94'];
|
|
2884
|
+
'-93': [-93, '-', '-94', '-92', '93'];
|
|
2885
|
+
'-92': [-92, '-', '-93', '-91', '92'];
|
|
2886
|
+
'-91': [-91, '-', '-92', '-90', '91'];
|
|
2887
|
+
'-90': [-90, '-', '-91', '-89', '90'];
|
|
2888
|
+
'-89': [-89, '-', '-90', '-88', '89'];
|
|
2889
|
+
'-88': [-88, '-', '-89', '-87', '88'];
|
|
2890
|
+
'-87': [-87, '-', '-88', '-86', '87'];
|
|
2891
|
+
'-86': [-86, '-', '-87', '-85', '86'];
|
|
2892
|
+
'-85': [-85, '-', '-86', '-84', '85'];
|
|
2893
|
+
'-84': [-84, '-', '-85', '-83', '84'];
|
|
2894
|
+
'-83': [-83, '-', '-84', '-82', '83'];
|
|
2895
|
+
'-82': [-82, '-', '-83', '-81', '82'];
|
|
2896
|
+
'-81': [-81, '-', '-82', '-80', '81'];
|
|
2897
|
+
'-80': [-80, '-', '-81', '-79', '80'];
|
|
2898
|
+
'-79': [-79, '-', '-80', '-78', '79'];
|
|
2899
|
+
'-78': [-78, '-', '-79', '-77', '78'];
|
|
2900
|
+
'-77': [-77, '-', '-78', '-76', '77'];
|
|
2901
|
+
'-76': [-76, '-', '-77', '-75', '76'];
|
|
2902
|
+
'-75': [-75, '-', '-76', '-74', '75'];
|
|
2903
|
+
'-74': [-74, '-', '-75', '-73', '74'];
|
|
2904
|
+
'-73': [-73, '-', '-74', '-72', '73'];
|
|
2905
|
+
'-72': [-72, '-', '-73', '-71', '72'];
|
|
2906
|
+
'-71': [-71, '-', '-72', '-70', '71'];
|
|
2907
|
+
'-70': [-70, '-', '-71', '-69', '70'];
|
|
2908
|
+
'-69': [-69, '-', '-70', '-68', '69'];
|
|
2909
|
+
'-68': [-68, '-', '-69', '-67', '68'];
|
|
2910
|
+
'-67': [-67, '-', '-68', '-66', '67'];
|
|
2911
|
+
'-66': [-66, '-', '-67', '-65', '66'];
|
|
2912
|
+
'-65': [-65, '-', '-66', '-64', '65'];
|
|
2913
|
+
'-64': [-64, '-', '-65', '-63', '64'];
|
|
2914
|
+
'-63': [-63, '-', '-64', '-62', '63'];
|
|
2915
|
+
'-62': [-62, '-', '-63', '-61', '62'];
|
|
2916
|
+
'-61': [-61, '-', '-62', '-60', '61'];
|
|
2917
|
+
'-60': [-60, '-', '-61', '-59', '60'];
|
|
2918
|
+
'-59': [-59, '-', '-60', '-58', '59'];
|
|
2919
|
+
'-58': [-58, '-', '-59', '-57', '58'];
|
|
2920
|
+
'-57': [-57, '-', '-58', '-56', '57'];
|
|
2921
|
+
'-56': [-56, '-', '-57', '-55', '56'];
|
|
2922
|
+
'-55': [-55, '-', '-56', '-54', '55'];
|
|
2923
|
+
'-54': [-54, '-', '-55', '-53', '54'];
|
|
2924
|
+
'-53': [-53, '-', '-54', '-52', '53'];
|
|
2925
|
+
'-52': [-52, '-', '-53', '-51', '52'];
|
|
2926
|
+
'-51': [-51, '-', '-52', '-50', '51'];
|
|
2927
|
+
'-50': [-50, '-', '-51', '-49', '50'];
|
|
2928
|
+
'-49': [-49, '-', '-50', '-48', '49'];
|
|
2929
|
+
'-48': [-48, '-', '-49', '-47', '48'];
|
|
2930
|
+
'-47': [-47, '-', '-48', '-46', '47'];
|
|
2931
|
+
'-46': [-46, '-', '-47', '-45', '46'];
|
|
2932
|
+
'-45': [-45, '-', '-46', '-44', '45'];
|
|
2933
|
+
'-44': [-44, '-', '-45', '-43', '44'];
|
|
2934
|
+
'-43': [-43, '-', '-44', '-42', '43'];
|
|
2935
|
+
'-42': [-42, '-', '-43', '-41', '42'];
|
|
2936
|
+
'-41': [-41, '-', '-42', '-40', '41'];
|
|
2937
|
+
'-40': [-40, '-', '-41', '-39', '40'];
|
|
2938
|
+
'-39': [-39, '-', '-40', '-38', '39'];
|
|
2939
|
+
'-38': [-38, '-', '-39', '-37', '38'];
|
|
2940
|
+
'-37': [-37, '-', '-38', '-36', '37'];
|
|
2941
|
+
'-36': [-36, '-', '-37', '-35', '36'];
|
|
2942
|
+
'-35': [-35, '-', '-36', '-34', '35'];
|
|
2943
|
+
'-34': [-34, '-', '-35', '-33', '34'];
|
|
2944
|
+
'-33': [-33, '-', '-34', '-32', '33'];
|
|
2945
|
+
'-32': [-32, '-', '-33', '-31', '32'];
|
|
2946
|
+
'-31': [-31, '-', '-32', '-30', '31'];
|
|
2947
|
+
'-30': [-30, '-', '-31', '-29', '30'];
|
|
2948
|
+
'-29': [-29, '-', '-30', '-28', '29'];
|
|
2949
|
+
'-28': [-28, '-', '-29', '-27', '28'];
|
|
2950
|
+
'-27': [-27, '-', '-28', '-26', '27'];
|
|
2951
|
+
'-26': [-26, '-', '-27', '-25', '26'];
|
|
2952
|
+
'-25': [-25, '-', '-26', '-24', '25'];
|
|
2953
|
+
'-24': [-24, '-', '-25', '-23', '24'];
|
|
2954
|
+
'-23': [-23, '-', '-24', '-22', '23'];
|
|
2955
|
+
'-22': [-22, '-', '-23', '-21', '22'];
|
|
2956
|
+
'-21': [-21, '-', '-22', '-20', '21'];
|
|
2957
|
+
'-20': [-20, '-', '-21', '-19', '20'];
|
|
2958
|
+
'-19': [-19, '-', '-20', '-18', '19'];
|
|
2959
|
+
'-18': [-18, '-', '-19', '-17', '18'];
|
|
2960
|
+
'-17': [-17, '-', '-18', '-16', '17'];
|
|
2961
|
+
'-16': [-16, '-', '-17', '-15', '16'];
|
|
2962
|
+
'-15': [-15, '-', '-16', '-14', '15'];
|
|
2963
|
+
'-14': [-14, '-', '-15', '-13', '14'];
|
|
2964
|
+
'-13': [-13, '-', '-14', '-12', '13'];
|
|
2965
|
+
'-12': [-12, '-', '-13', '-11', '12'];
|
|
2966
|
+
'-11': [-11, '-', '-12', '-10', '11'];
|
|
2967
|
+
'-10': [-10, '-', '-11', '-9', '10'];
|
|
2968
|
+
'-9': [-9, '-', '-10', '-8', '9'];
|
|
2969
|
+
'-8': [-8, '-', '-9', '-7', '8'];
|
|
2970
|
+
'-7': [-7, '-', '-8', '-6', '7'];
|
|
2971
|
+
'-6': [-6, '-', '-7', '-5', '6'];
|
|
2972
|
+
'-5': [-5, '-', '-6', '-4', '5'];
|
|
2973
|
+
'-4': [-4, '-', '-5', '-3', '4'];
|
|
2974
|
+
'-3': [-3, '-', '-4', '-2', '3'];
|
|
2975
|
+
'-2': [-2, '-', '-3', '-1', '2'];
|
|
2976
|
+
'-1': [-1, '-', '-2', '0', '1'];
|
|
2977
|
+
'0': [0, '0', '-1', '1', '0'];
|
|
2978
|
+
'1': [1, '+', '0', '2', '-1'];
|
|
2979
|
+
'2': [2, '+', '1', '3', '-2'];
|
|
2980
|
+
'3': [3, '+', '2', '4', '-3'];
|
|
2981
|
+
'4': [4, '+', '3', '5', '-4'];
|
|
2982
|
+
'5': [5, '+', '4', '6', '-5'];
|
|
2983
|
+
'6': [6, '+', '5', '7', '-6'];
|
|
2984
|
+
'7': [7, '+', '6', '8', '-7'];
|
|
2985
|
+
'8': [8, '+', '7', '9', '-8'];
|
|
2986
|
+
'9': [9, '+', '8', '10', '-9'];
|
|
2987
|
+
'10': [10, '+', '9', '11', '-10'];
|
|
2988
|
+
'11': [11, '+', '10', '12', '-11'];
|
|
2989
|
+
'12': [12, '+', '11', '13', '-12'];
|
|
2990
|
+
'13': [13, '+', '12', '14', '-13'];
|
|
2991
|
+
'14': [14, '+', '13', '15', '-14'];
|
|
2992
|
+
'15': [15, '+', '14', '16', '-15'];
|
|
2993
|
+
'16': [16, '+', '15', '17', '-16'];
|
|
2994
|
+
'17': [17, '+', '16', '18', '-17'];
|
|
2995
|
+
'18': [18, '+', '17', '19', '-18'];
|
|
2996
|
+
'19': [19, '+', '18', '20', '-19'];
|
|
2997
|
+
'20': [20, '+', '19', '21', '-20'];
|
|
2998
|
+
'21': [21, '+', '20', '22', '-21'];
|
|
2999
|
+
'22': [22, '+', '21', '23', '-22'];
|
|
3000
|
+
'23': [23, '+', '22', '24', '-23'];
|
|
3001
|
+
'24': [24, '+', '23', '25', '-24'];
|
|
3002
|
+
'25': [25, '+', '24', '26', '-25'];
|
|
3003
|
+
'26': [26, '+', '25', '27', '-26'];
|
|
3004
|
+
'27': [27, '+', '26', '28', '-27'];
|
|
3005
|
+
'28': [28, '+', '27', '29', '-28'];
|
|
3006
|
+
'29': [29, '+', '28', '30', '-29'];
|
|
3007
|
+
'30': [30, '+', '29', '31', '-30'];
|
|
3008
|
+
'31': [31, '+', '30', '32', '-31'];
|
|
3009
|
+
'32': [32, '+', '31', '33', '-32'];
|
|
3010
|
+
'33': [33, '+', '32', '34', '-33'];
|
|
3011
|
+
'34': [34, '+', '33', '35', '-34'];
|
|
3012
|
+
'35': [35, '+', '34', '36', '-35'];
|
|
3013
|
+
'36': [36, '+', '35', '37', '-36'];
|
|
3014
|
+
'37': [37, '+', '36', '38', '-37'];
|
|
3015
|
+
'38': [38, '+', '37', '39', '-38'];
|
|
3016
|
+
'39': [39, '+', '38', '40', '-39'];
|
|
3017
|
+
'40': [40, '+', '39', '41', '-40'];
|
|
3018
|
+
'41': [41, '+', '40', '42', '-41'];
|
|
3019
|
+
'42': [42, '+', '41', '43', '-42'];
|
|
3020
|
+
'43': [43, '+', '42', '44', '-43'];
|
|
3021
|
+
'44': [44, '+', '43', '45', '-44'];
|
|
3022
|
+
'45': [45, '+', '44', '46', '-45'];
|
|
3023
|
+
'46': [46, '+', '45', '47', '-46'];
|
|
3024
|
+
'47': [47, '+', '46', '48', '-47'];
|
|
3025
|
+
'48': [48, '+', '47', '49', '-48'];
|
|
3026
|
+
'49': [49, '+', '48', '50', '-49'];
|
|
3027
|
+
'50': [50, '+', '49', '51', '-50'];
|
|
3028
|
+
'51': [51, '+', '50', '52', '-51'];
|
|
3029
|
+
'52': [52, '+', '51', '53', '-52'];
|
|
3030
|
+
'53': [53, '+', '52', '54', '-53'];
|
|
3031
|
+
'54': [54, '+', '53', '55', '-54'];
|
|
3032
|
+
'55': [55, '+', '54', '56', '-55'];
|
|
3033
|
+
'56': [56, '+', '55', '57', '-56'];
|
|
3034
|
+
'57': [57, '+', '56', '58', '-57'];
|
|
3035
|
+
'58': [58, '+', '57', '59', '-58'];
|
|
3036
|
+
'59': [59, '+', '58', '60', '-59'];
|
|
3037
|
+
'60': [60, '+', '59', '61', '-60'];
|
|
3038
|
+
'61': [61, '+', '60', '62', '-61'];
|
|
3039
|
+
'62': [62, '+', '61', '63', '-62'];
|
|
3040
|
+
'63': [63, '+', '62', '64', '-63'];
|
|
3041
|
+
'64': [64, '+', '63', '65', '-64'];
|
|
3042
|
+
'65': [65, '+', '64', '66', '-65'];
|
|
3043
|
+
'66': [66, '+', '65', '67', '-66'];
|
|
3044
|
+
'67': [67, '+', '66', '68', '-67'];
|
|
3045
|
+
'68': [68, '+', '67', '69', '-68'];
|
|
3046
|
+
'69': [69, '+', '68', '70', '-69'];
|
|
3047
|
+
'70': [70, '+', '69', '71', '-70'];
|
|
3048
|
+
'71': [71, '+', '70', '72', '-71'];
|
|
3049
|
+
'72': [72, '+', '71', '73', '-72'];
|
|
3050
|
+
'73': [73, '+', '72', '74', '-73'];
|
|
3051
|
+
'74': [74, '+', '73', '75', '-74'];
|
|
3052
|
+
'75': [75, '+', '74', '76', '-75'];
|
|
3053
|
+
'76': [76, '+', '75', '77', '-76'];
|
|
3054
|
+
'77': [77, '+', '76', '78', '-77'];
|
|
3055
|
+
'78': [78, '+', '77', '79', '-78'];
|
|
3056
|
+
'79': [79, '+', '78', '80', '-79'];
|
|
3057
|
+
'80': [80, '+', '79', '81', '-80'];
|
|
3058
|
+
'81': [81, '+', '80', '82', '-81'];
|
|
3059
|
+
'82': [82, '+', '81', '83', '-82'];
|
|
3060
|
+
'83': [83, '+', '82', '84', '-83'];
|
|
3061
|
+
'84': [84, '+', '83', '85', '-84'];
|
|
3062
|
+
'85': [85, '+', '84', '86', '-85'];
|
|
3063
|
+
'86': [86, '+', '85', '87', '-86'];
|
|
3064
|
+
'87': [87, '+', '86', '88', '-87'];
|
|
3065
|
+
'88': [88, '+', '87', '89', '-88'];
|
|
3066
|
+
'89': [89, '+', '88', '90', '-89'];
|
|
3067
|
+
'90': [90, '+', '89', '91', '-90'];
|
|
3068
|
+
'91': [91, '+', '90', '92', '-91'];
|
|
3069
|
+
'92': [92, '+', '91', '93', '-92'];
|
|
3070
|
+
'93': [93, '+', '92', '94', '-93'];
|
|
3071
|
+
'94': [94, '+', '93', '95', '-94'];
|
|
3072
|
+
'95': [95, '+', '94', '96', '-95'];
|
|
3073
|
+
'96': [96, '+', '95', '97', '-96'];
|
|
3074
|
+
'97': [97, '+', '96', '98', '-97'];
|
|
3075
|
+
'98': [98, '+', '97', '99', '-98'];
|
|
3076
|
+
'99': [99, '+', '98', '100', '-99'];
|
|
3077
|
+
'100': [100, '+', '99', '__', '-100'];
|
|
3078
|
+
};
|
|
3079
|
+
//#endregion
|
|
3080
|
+
//#region ../../node_modules/.pnpm/ts-toolbelt@9.6.0/node_modules/ts-toolbelt/out/Iteration/Prev.d.ts
|
|
3081
|
+
/**
|
|
3082
|
+
* Move `I`'s position backwards
|
|
3083
|
+
* @param I to move
|
|
3084
|
+
* @returns [[Iteration]]
|
|
3085
|
+
* @example
|
|
3086
|
+
* ```ts
|
|
3087
|
+
* import {I} from 'ts-toolbelt'
|
|
3088
|
+
*
|
|
3089
|
+
* type i = I.IterationOf<'20'>
|
|
3090
|
+
*
|
|
3091
|
+
* type test0 = I.Pos<i> // 20
|
|
3092
|
+
* type test1 = I.Pos<I.Prev<i>> // 19
|
|
3093
|
+
* ```
|
|
3094
|
+
*/
|
|
3095
|
+
declare type Prev<I extends Iteration> = IterationMap[I[2]];
|
|
3096
|
+
//#endregion
|
|
3097
|
+
//#region ../../node_modules/.pnpm/ts-toolbelt@9.6.0/node_modules/ts-toolbelt/out/Iteration/IterationOf.d.ts
|
|
3098
|
+
/**
|
|
3099
|
+
* Transform a number into an [[Iteration]]
|
|
3100
|
+
* (to use [[Prev]], [[Next]], & [[Pos]])
|
|
3101
|
+
* @param N to transform
|
|
3102
|
+
* @returns [[Iteration]]
|
|
3103
|
+
* @example
|
|
3104
|
+
* ```ts
|
|
3105
|
+
* import {I} from 'ts-toolbelt'
|
|
3106
|
+
*
|
|
3107
|
+
* type i = I.IterationOf<0> // ["-1", "1", "0", 0, "0"]
|
|
3108
|
+
*
|
|
3109
|
+
* type next = I.Next<i> // ["0", "2", "1", 1, "+"]
|
|
3110
|
+
* type prev = I.Prev<i> // ["-2", "0", "-1", -1, "-"]
|
|
3111
|
+
*
|
|
3112
|
+
* type nnext = I.Pos<next> // +1
|
|
3113
|
+
* type nprev = I.Pos<prev> // -1
|
|
3114
|
+
* ```
|
|
3115
|
+
*/
|
|
3116
|
+
declare type IterationOf<N extends number> = `${N}` extends keyof IterationMap ? IterationMap[`${N}`] : IterationMap['__'];
|
|
3117
|
+
//#endregion
|
|
3118
|
+
//#region ../../node_modules/.pnpm/ts-toolbelt@9.6.0/node_modules/ts-toolbelt/out/Iteration/Pos.d.ts
|
|
3119
|
+
/**
|
|
3120
|
+
* Get the position of `I` (**number**)
|
|
3121
|
+
* @param I to query
|
|
3122
|
+
* @returns `number`
|
|
3123
|
+
* @example
|
|
3124
|
+
* ```ts
|
|
3125
|
+
* import {I} from 'ts-toolbelt'
|
|
3126
|
+
*
|
|
3127
|
+
* type i = I.IterationOf<'20'>
|
|
3128
|
+
*
|
|
3129
|
+
* type test0 = I.Pos<i> // 20
|
|
3130
|
+
* type test1 = I.Pos<I.Next<i>> // 21
|
|
3131
|
+
* ```
|
|
3132
|
+
*/
|
|
3133
|
+
declare type Pos<I extends Iteration> = I[0];
|
|
3134
|
+
//#endregion
|
|
3135
|
+
//#region ../../node_modules/.pnpm/ts-toolbelt@9.6.0/node_modules/ts-toolbelt/out/List/Tail.d.ts
|
|
3136
|
+
/**
|
|
3137
|
+
* Remove the first item out of a [[List]]
|
|
3138
|
+
* @param L
|
|
3139
|
+
* @returns [[List]]
|
|
3140
|
+
* @example
|
|
3141
|
+
* ```ts
|
|
3142
|
+
* ```
|
|
3143
|
+
*/
|
|
3144
|
+
declare type Tail$1<L extends List> = L extends readonly [] ? L : L extends readonly [any?, ...infer LTail] ? LTail : L;
|
|
3145
|
+
//#endregion
|
|
3146
|
+
//#region ../../node_modules/.pnpm/ts-toolbelt@9.6.0/node_modules/ts-toolbelt/out/Object/Overwrite.d.ts
|
|
3147
|
+
/**
|
|
3148
|
+
* Update the fields of `O` with the ones of `O1`
|
|
3149
|
+
* (only the existing fields will be updated)
|
|
3150
|
+
* @param O to update
|
|
3151
|
+
* @param O1 to update with
|
|
3152
|
+
* @returns [[Object]]
|
|
3153
|
+
* @example
|
|
3154
|
+
* ```ts
|
|
3155
|
+
* ```
|
|
3156
|
+
*/
|
|
3157
|
+
declare type Overwrite<O extends object, O1 extends object> = { [K in keyof O]: K extends keyof O1 ? O1[K] : O[K] } & {};
|
|
3158
|
+
//#endregion
|
|
3159
|
+
//#region ../../node_modules/.pnpm/ts-toolbelt@9.6.0/node_modules/ts-toolbelt/out/List/_Internal.d.ts
|
|
3160
|
+
/**
|
|
3161
|
+
* Remove `?` & `readonly` from a [[List]]
|
|
3162
|
+
*/
|
|
3163
|
+
declare type Naked<L extends List> = Overwrite<Required<L>, L>;
|
|
3164
|
+
//#endregion
|
|
3165
|
+
//#region ../../node_modules/.pnpm/ts-toolbelt@9.6.0/node_modules/ts-toolbelt/out/List/Prepend.d.ts
|
|
3166
|
+
/**
|
|
3167
|
+
* Add an element `A` at the beginning of `L`
|
|
3168
|
+
* @param L to append to
|
|
3169
|
+
* @param A to be added to
|
|
3170
|
+
* @returns [[List]]
|
|
3171
|
+
* @example
|
|
3172
|
+
* ```ts
|
|
3173
|
+
* ```
|
|
3174
|
+
*/
|
|
3175
|
+
declare type Prepend<L extends List, A extends any> = [A, ...L];
|
|
3176
|
+
//#endregion
|
|
3177
|
+
//#region ../../node_modules/.pnpm/ts-toolbelt@9.6.0/node_modules/ts-toolbelt/out/Iteration/_Internal.d.ts
|
|
3178
|
+
/**
|
|
3179
|
+
* Describes how to perform iterations
|
|
3180
|
+
*/
|
|
3181
|
+
declare type Way = '->' | '<-';
|
|
3182
|
+
//#endregion
|
|
3183
|
+
//#region ../../node_modules/.pnpm/ts-toolbelt@9.6.0/node_modules/ts-toolbelt/out/List/Append.d.ts
|
|
3184
|
+
/**
|
|
3185
|
+
* Add an element `A` at the end of `L`.
|
|
3186
|
+
* @param L to append to
|
|
3187
|
+
* @param A to be added to
|
|
3188
|
+
* @returns [[List]]
|
|
3189
|
+
* @example
|
|
3190
|
+
* ```ts
|
|
3191
|
+
* import {L} from 'ts-toolbelt'
|
|
3192
|
+
*
|
|
3193
|
+
* type test0 = L.Append<[1, 2, 3], 4> // [1, 2, 3, 4]
|
|
3194
|
+
* type test1 = L.Append<[], 'a'> // ['a']
|
|
3195
|
+
* type test2 = L.Append<readonly ['a', 'b'], 'c'> // ['a', 'b', 'c']
|
|
3196
|
+
* type test3 = L.Append<[1, 2], [3, 4]> // [1, 2, [3, 4]]
|
|
3197
|
+
* ```
|
|
3198
|
+
*/
|
|
3199
|
+
declare type Append<L extends List, A extends any> = [...L, A];
|
|
3200
|
+
//#endregion
|
|
3201
|
+
//#region ../../node_modules/.pnpm/ts-toolbelt@9.6.0/node_modules/ts-toolbelt/out/List/Drop.d.ts
|
|
3202
|
+
/**
|
|
3203
|
+
* @hidden
|
|
3204
|
+
*/
|
|
3205
|
+
declare type DropForth<L extends List, N extends Iteration> = {
|
|
3206
|
+
0: DropForth<Tail$1<L>, Prev<N>>;
|
|
3207
|
+
1: L;
|
|
3208
|
+
}[Extends<0, Pos<N>>];
|
|
3209
|
+
/**
|
|
3210
|
+
* @hidden
|
|
3211
|
+
*/
|
|
3212
|
+
declare type DropBack<L extends List, N extends Iteration, I extends Iteration = Prev<N>, LN extends List = []> = {
|
|
3213
|
+
0: DropBack<L, N, Prev<I>, Prepend<LN, L[Pos<I>]>>;
|
|
3214
|
+
1: LN;
|
|
3215
|
+
}[Extends<-1, Pos<I>>];
|
|
3216
|
+
/**
|
|
3217
|
+
* @hidden
|
|
3218
|
+
*/
|
|
3219
|
+
declare type __Drop<L extends List, N extends Iteration, way extends Way> = {
|
|
3220
|
+
'->': DropForth<L, N>;
|
|
3221
|
+
'<-': DropBack<L, N>;
|
|
3222
|
+
}[way];
|
|
3223
|
+
/**
|
|
3224
|
+
* @hidden
|
|
3225
|
+
*/
|
|
3226
|
+
declare type _Drop<L extends List, N extends number, way extends Way = '->'> = __Drop<Naked<L>, IterationOf<N>, way> extends infer X ? Cast<X, List> : never;
|
|
3227
|
+
/**
|
|
3228
|
+
* Remove `N` entries out of `L`
|
|
3229
|
+
* @param L to remove from
|
|
3230
|
+
* @param N to remove out
|
|
3231
|
+
* @param way (?=`'->'`) from front: '->', from end: '<-'
|
|
3232
|
+
* @returns [[List]]
|
|
3233
|
+
* @example
|
|
3234
|
+
* ```ts
|
|
3235
|
+
* ```
|
|
3236
|
+
*/
|
|
3237
|
+
declare type Drop<L extends List, N extends number, way extends Way = '->'> = L extends unknown ? N extends unknown ? _Drop<L, N, way> : never : never;
|
|
3238
|
+
//#endregion
|
|
3239
|
+
//#region ../../node_modules/.pnpm/ts-toolbelt@9.6.0/node_modules/ts-toolbelt/out/List/Take.d.ts
|
|
3240
|
+
/**
|
|
3241
|
+
* starts in reverse from `N` till `N` = 0
|
|
3242
|
+
* @hidden
|
|
3243
|
+
*/
|
|
3244
|
+
declare type TakeForth<L extends List, N extends Iteration, I extends Iteration = Prev<N>, LN extends List = []> = {
|
|
3245
|
+
0: TakeForth<L, N, Prev<I>, Prepend<LN, L[Pos<I>]>>;
|
|
3246
|
+
1: LN;
|
|
3247
|
+
}[Extends<-1, Pos<I>>];
|
|
3248
|
+
/**
|
|
3249
|
+
* starts in reverse from the end till `N` = 0
|
|
3250
|
+
* @hidden
|
|
3251
|
+
*/
|
|
3252
|
+
declare type TakeBack<L extends List, N extends Iteration> = {
|
|
3253
|
+
0: TakeBack<Tail$1<L>, Prev<N>>;
|
|
3254
|
+
1: L;
|
|
3255
|
+
}[Extends<0, Pos<N>>];
|
|
3256
|
+
/**
|
|
3257
|
+
* @hidden
|
|
3258
|
+
*/
|
|
3259
|
+
declare type __Take<L extends List, N extends Iteration, way extends Way> = {
|
|
3260
|
+
'->': TakeForth<L, N>;
|
|
3261
|
+
'<-': TakeBack<L, N>;
|
|
3262
|
+
}[way];
|
|
3263
|
+
/**
|
|
3264
|
+
* @hidden
|
|
3265
|
+
*/
|
|
3266
|
+
declare type _Take<L extends List, N extends number, way extends Way = '->'> = __Take<L, IterationOf<N>, way> extends infer X ? Cast<X, List> : never;
|
|
3267
|
+
/**
|
|
3268
|
+
* Extract `N` entries out of `L`
|
|
3269
|
+
* @param L to extract from
|
|
3270
|
+
* @param N to extract out
|
|
3271
|
+
* @param way (?=`'->'`) to extract from end
|
|
3272
|
+
* @returns [[List]]
|
|
3273
|
+
* @example
|
|
3274
|
+
* ```ts
|
|
3275
|
+
* ```
|
|
3276
|
+
*/
|
|
3277
|
+
declare type Take<L extends List, N extends number, way extends Way = '->'> = L extends unknown ? N extends unknown ? _Take<L, N, way> : never : never;
|
|
3278
|
+
//#endregion
|
|
3279
|
+
//#region src/object/index.type.d.ts
|
|
3280
|
+
type Range<Start extends number, End extends number> = Exclude<keyof TupleOf<End>, keyof TupleOf<Start>>;
|
|
3281
|
+
type AnyArray<A = any> = readonly A[];
|
|
3282
|
+
type TupleToEntries<A extends readonly unknown[]> = If<IsAny<A>, unknown, { [Key in keyof A]: [Key, A[Key]] }>;
|
|
3283
|
+
type Groups<L extends AnyArray, LN extends AnyArray = [], D extends number[] = []> = D["length"] extends 40 ? LN : {
|
|
3284
|
+
0: Groups<Drop<L, 1>, Append<LN, [`${LN["length"]}`, Take<L, 1>]>, [...D, 0]>;
|
|
3285
|
+
1: LN;
|
|
3286
|
+
}[Extends<L, AnyArray<never>>];
|
|
3287
|
+
type TupleToGroups<L extends AnyArray> = Groups<L> extends infer X ? Cast<X, AnyArray> : never;
|
|
3288
|
+
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>>;
|
|
3289
|
+
type IntersectOf<U> = (U extends unknown ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
|
|
3290
|
+
type ComputeRaw<A> = A extends AnyFunction ? A : { [K in keyof A]: A[K] } & unknown;
|
|
3291
|
+
type _Invert<O extends Record<PropertyKey, PropertyKey>> = ComputeRaw<IntersectOf<{ [K in keyof O]: Record<O[K], K> }[keyof O]>>;
|
|
3292
|
+
type Invert<O extends Record<keyof O, PropertyKey>> = O extends unknown ? _Invert<O> : never;
|
|
3293
|
+
//#endregion
|
|
3294
|
+
//#region src/object/objectUtil.d.ts
|
|
3295
|
+
/**
|
|
3296
|
+
* 对象工具类
|
|
3297
|
+
*/
|
|
3298
|
+
declare class ObjectUtil {
|
|
3299
|
+
/**
|
|
3300
|
+
* 返回对象可枚举属性和方法的名称
|
|
3301
|
+
* - `Object.keys` 始终返回 `string[]` 类型,此函数可以返回具体类型
|
|
3302
|
+
*
|
|
3303
|
+
* @param value 对象
|
|
3304
|
+
* @returns 键数组
|
|
3305
|
+
* @example
|
|
3306
|
+
* ```ts
|
|
3307
|
+
* ObjectUtil.keys({ a: 1, b: 2 }); // ["a", "b"]
|
|
3308
|
+
* ```
|
|
3309
|
+
*/
|
|
3310
|
+
static keys<const S extends string>(string: S): UnionToTuple<Range<0, Split<S, "">["length"]>>;
|
|
3311
|
+
static keys<const A extends ArrayLike<unknown>>(array: A): UnionToTuple<Range<0, A["length"]>>;
|
|
3312
|
+
static keys<O extends PlainObject>(plainObject: O): `${Extract<keyof O, string | number>}`[];
|
|
3313
|
+
static keys<O extends AnyObject>(anyObject: O): `${Extract<keyof O, string | number>}`[];
|
|
3314
|
+
/**
|
|
3315
|
+
* 返回对象可枚举属性的值的数组
|
|
3316
|
+
*
|
|
3317
|
+
* @param value 对象
|
|
3318
|
+
* @returns 值数组
|
|
3319
|
+
* @example
|
|
3320
|
+
* ```ts
|
|
3321
|
+
* ObjectUtil.values({ a: 1, b: 2 }); // [1, 2]
|
|
3322
|
+
* ```
|
|
3323
|
+
*/
|
|
3324
|
+
static values<S extends string>(string: S): Split<S, "">;
|
|
3325
|
+
static values<A extends ArrayLike<unknown>>(array: A): A;
|
|
3326
|
+
static values<O extends PlainObject>(plainObject: O): O[keyof O][];
|
|
3327
|
+
static values<O extends AnyObject>(anyObject: O): O[keyof O][];
|
|
3328
|
+
/**
|
|
3329
|
+
* 返回对象的可枚举属性的键/值数组
|
|
3330
|
+
*
|
|
3331
|
+
* @param value 对象
|
|
3332
|
+
* @returns 键值对数组
|
|
3333
|
+
* @example
|
|
3334
|
+
* ```ts
|
|
3335
|
+
* ObjectUtil.entries({ a: 1 }); // [["a", 1]]
|
|
3336
|
+
* ```
|
|
3337
|
+
*/
|
|
3338
|
+
static entries<const S extends string>(string: S): TupleToEntries<Split<S, "">>;
|
|
3339
|
+
static entries<const A extends readonly unknown[]>(array: A): TupleToGroups<A>;
|
|
3340
|
+
static entries<const O extends PlainObject>(plainObject: O): [`${keyof Except<O, symbol>}`, O[keyof Except<O, symbol>]][];
|
|
3341
|
+
static entries<const O extends AnyObject>(anyObject: O): [`${keyof Except<O, symbol>}`, O[keyof Except<O, symbol>]][];
|
|
3342
|
+
/**
|
|
3343
|
+
* 映射对象条目
|
|
3344
|
+
* - 将对象的键值对映射为新的键值对
|
|
3345
|
+
*
|
|
3346
|
+
* @param plainObject 对象
|
|
3347
|
+
* @param toEntry 映射函数
|
|
3348
|
+
* @returns 映射后的新对象
|
|
3349
|
+
* @example
|
|
3350
|
+
* ```ts
|
|
3351
|
+
* const obj = { a: 1, b: 2 };
|
|
3352
|
+
* ObjectUtil.entriesMap(obj, (k, v) => [k, v * 2]); // { a: 2, b: 4 }
|
|
3353
|
+
* ```
|
|
3354
|
+
*/
|
|
3355
|
+
static entriesMap<O extends PlainObject, NK extends PropertyKey, NV>(plainObject: O, toEntry: (key: keyof O, value: O[keyof O]) => [NK, NV]): PlainObject<NK, NV>;
|
|
3356
|
+
/**
|
|
3357
|
+
* 选取对象的指定属性
|
|
3358
|
+
*
|
|
3359
|
+
* @param plainObject 对象
|
|
3360
|
+
* @param keys 要选取的属性键数组
|
|
3361
|
+
* @returns 包含指定属性的新对象
|
|
3362
|
+
* @example
|
|
3363
|
+
* ```ts
|
|
3364
|
+
* ObjectUtil.pick({ a: 1, b: 2 }, ["a"]); // { a: 1 }
|
|
3365
|
+
* ```
|
|
3366
|
+
*/
|
|
3367
|
+
static pick<O extends PlainObject, K extends keyof O>(plainObject: O, keys: readonly K[]): Pick<O, K>;
|
|
3368
|
+
static pick<O extends AnyObject, K extends keyof O>(anyObject: O, keys: readonly K[]): Pick<O, K>;
|
|
3369
|
+
/**
|
|
3370
|
+
* 排除对象的指定属性
|
|
3371
|
+
*
|
|
3372
|
+
* @param plainObject 对象
|
|
3373
|
+
* @param keys 要排除的属性键数组
|
|
3374
|
+
* @returns 排除指定属性后的新对象
|
|
3375
|
+
* @example
|
|
3376
|
+
* ```ts
|
|
3377
|
+
* ObjectUtil.omit({ a: 1, b: 2 }, ["a"]); // { b: 2 }
|
|
3378
|
+
* ```
|
|
3379
|
+
*/
|
|
3380
|
+
static omit<O extends PlainObject, K extends keyof O>(plainObject: O, keys: readonly K[]): Omit<O, K>;
|
|
3381
|
+
static omit<O extends AnyObject, K extends keyof O>(anyObject: O, keys: readonly K[]): Omit<O, K>;
|
|
3382
|
+
/**
|
|
3383
|
+
* 尽可能地交换对象的键和值
|
|
3384
|
+
*
|
|
3385
|
+
* @param obj 对象
|
|
3386
|
+
* @returns 键值互换后的对象
|
|
3387
|
+
* @example
|
|
3388
|
+
* ```ts
|
|
3389
|
+
* const obj = { a: "1", b: 2 };
|
|
3390
|
+
* ObjectUtil.invert(obj); // { "1": "a", 2: "b" }
|
|
3391
|
+
* ```
|
|
3392
|
+
*/
|
|
3393
|
+
static invert<const O extends Record<keyof O, PropertyKey>>(plainObject: O): Invert<O>;
|
|
3394
|
+
static invert<const O extends AnyObject>(anyObject: O): Invert<O>;
|
|
3395
|
+
/**
|
|
3396
|
+
* 压平对象
|
|
3397
|
+
* - 将多层级的对象转换为单层级的对象,键名使用点号连接
|
|
3398
|
+
*
|
|
3399
|
+
* @param plainObject 平面对象
|
|
3400
|
+
* @returns 压平后的对象
|
|
3401
|
+
* @example
|
|
3402
|
+
* ```ts
|
|
3403
|
+
* const obj = { a: { b: 1 } };
|
|
3404
|
+
* ObjectUtil.crush(obj); // { "a.b": 1 }
|
|
3405
|
+
* ```
|
|
3406
|
+
*/
|
|
3407
|
+
static crush<T extends PlainObject>(plainObject: T): Crush<T>;
|
|
3408
|
+
static crush<T extends AnyObject>(anyObject: T): Crush<T>;
|
|
3409
|
+
/**
|
|
3410
|
+
* 获取所有枚举成员的键
|
|
3411
|
+
*
|
|
3412
|
+
* @param enumeration 枚举对象
|
|
3413
|
+
* @returns 键数组
|
|
3414
|
+
* @example
|
|
3415
|
+
* ```ts
|
|
3416
|
+
* enum A { k = "v" }
|
|
3417
|
+
* ObjectUtil.enumKeys(A); // ["k"]
|
|
3418
|
+
* ```
|
|
3419
|
+
*/
|
|
3420
|
+
static enumKeys<E extends PlainObject>(enumeration: E): (keyof E)[];
|
|
3421
|
+
static enumKeys<E extends AnyObject>(enumeration: E): (keyof E)[];
|
|
3422
|
+
/**
|
|
3423
|
+
* 获取所有枚举成员的值
|
|
3424
|
+
*
|
|
3425
|
+
* @param enumeration 枚举对象
|
|
3426
|
+
* @returns 值数组
|
|
3427
|
+
* @example
|
|
3428
|
+
* ```ts
|
|
3429
|
+
* enum A { k = "v" }
|
|
3430
|
+
* ObjectUtil.enumValues(A); // ["v"]
|
|
3431
|
+
* ```
|
|
3432
|
+
*/
|
|
3433
|
+
static enumValues<E extends PlainObject>(enumeration: E): UnionToTuple<ValueOf<E>>;
|
|
3434
|
+
static enumValues<E extends AnyObject>(enumeration: E): UnionToTuple<ValueOf<E>>;
|
|
3435
|
+
/**
|
|
3436
|
+
* 获取所有枚举成员的键/值数组
|
|
3437
|
+
*
|
|
3438
|
+
* @param enumeration 枚举对象
|
|
3439
|
+
* @returns 键值对数组
|
|
3440
|
+
* @example
|
|
3441
|
+
* ```ts
|
|
3442
|
+
* enum A { k = "v" }
|
|
3443
|
+
* ObjectUtil.enumEntries(A); // [["k", "v"]]
|
|
3444
|
+
* ```
|
|
3445
|
+
*/
|
|
3446
|
+
static enumEntries<E extends PlainObject>(enumeration: E): [keyof E, E[keyof E]][];
|
|
3447
|
+
static enumEntries<E extends AnyObject>(enumeration: E): [keyof E, E[keyof E]][];
|
|
3448
|
+
}
|
|
3449
|
+
//#endregion
|
|
3450
|
+
//#region src/string/stringUtil.d.ts
|
|
3451
|
+
/**
|
|
3452
|
+
* 字符串工具类
|
|
3453
|
+
*/
|
|
3454
|
+
declare class StringUtil {
|
|
3455
|
+
/**
|
|
3456
|
+
* 从字符串中提取数字字符串
|
|
3457
|
+
* - 移除非数字字符,保留符号和小数点
|
|
3458
|
+
*
|
|
3459
|
+
* @param input 待处理字符串
|
|
3460
|
+
* @returns 提取出的数字字符串
|
|
3461
|
+
* @example
|
|
3462
|
+
* ```ts
|
|
3463
|
+
* StringUtil.toNumber("$1,234.56"); // "1234.56"
|
|
3464
|
+
* StringUtil.toNumber("abc-123"); // "-123"
|
|
3465
|
+
* ```
|
|
3466
|
+
*/
|
|
3467
|
+
static toNumber(input: string): string;
|
|
3468
|
+
/**
|
|
3469
|
+
* 将字符串转换为小写
|
|
3470
|
+
* - 将字符串字面量类型转换为其小写形式
|
|
3471
|
+
* - 当输入无效时,返回空字符串
|
|
3472
|
+
*
|
|
3473
|
+
* @param input 待处理字符串
|
|
3474
|
+
* @returns 转换后的小写字符串类型,如果输入无效则返回空字符串类型 ""
|
|
3475
|
+
* @example
|
|
3476
|
+
* ```ts
|
|
3477
|
+
* StringUtil.toLowerCase("HELLO"); // "hello"
|
|
3478
|
+
* StringUtil.toLowerCase(null); // ""
|
|
3479
|
+
* ```
|
|
3480
|
+
*/
|
|
3481
|
+
static toLowerCase<const T extends string>(input: T): Lowercase<T>;
|
|
3482
|
+
static toLowerCase(input: unknown): "";
|
|
3483
|
+
/**
|
|
3484
|
+
* 将字符串转换为大写
|
|
3485
|
+
* - 将字符串字面量类型转换为其大写形式
|
|
3486
|
+
* - 当输入无效时,返回空字符串
|
|
3487
|
+
*
|
|
3488
|
+
* @param input 待处理字符串
|
|
3489
|
+
* @returns 转换后的大写字符串,如果输入无效则返回空字符串
|
|
3490
|
+
* @example
|
|
3491
|
+
* ```ts
|
|
3492
|
+
* StringUtil.toUpperCase("hello"); // "HELLO"
|
|
3493
|
+
* StringUtil.toUpperCase(null); // ""
|
|
3494
|
+
* ```
|
|
3495
|
+
*/
|
|
3496
|
+
static toUpperCase<const T extends string>(input: T): Uppercase<T>;
|
|
3497
|
+
static toUpperCase(input: unknown): "";
|
|
3498
|
+
/**
|
|
3499
|
+
* 字符串首字母大小写
|
|
3500
|
+
* - 包含非西欧字母字符时,不处理
|
|
3501
|
+
* - 纯字母且全大写时,不处理
|
|
3502
|
+
* - 纯字母且非全大写时,首字母小写,其余保留
|
|
3503
|
+
* - 纯字母且非全大写时,首字母大写,其余保留
|
|
3504
|
+
*
|
|
3505
|
+
* @param input 待处理字符串
|
|
3506
|
+
* @param caseType 大小写类型
|
|
3507
|
+
* @returns 处理后的字符串
|
|
3508
|
+
* @example
|
|
3509
|
+
* ```ts
|
|
3510
|
+
* StringUtil.toInitialCase("Hello", "lower"); // "hello"
|
|
3511
|
+
* StringUtil.toInitialCase("hello", "upper"); // "Hello"
|
|
3512
|
+
* ```
|
|
3513
|
+
*/
|
|
3514
|
+
static toInitialCase(input: string, caseType?: "lower" | "upper" | undefined): string;
|
|
3515
|
+
/**
|
|
3516
|
+
* 将路径转换为 POSIX 风格
|
|
3517
|
+
* - 统一使用正斜杠 (/)
|
|
3518
|
+
* - 可选移除 Windows 盘符 (如 C:)
|
|
3519
|
+
* - 可选移除开头的斜杠
|
|
3520
|
+
* - 规范化连续斜杠为单个斜杠
|
|
3521
|
+
*
|
|
3522
|
+
* @param input 待处理字符串
|
|
3523
|
+
* @param removeLeadingSlash 是否移除开头斜杠,默认为 `false`。如果移除了盘符,路径通常会以 / 开头,此参数可控制是否保留该 /
|
|
3524
|
+
* @returns 转换后的路径,如果输入无效则返回空字符串
|
|
3525
|
+
*
|
|
3526
|
+
* @example
|
|
3527
|
+
* ```ts
|
|
3528
|
+
* StringUtil.toPosix("C:\\Windows\\System32"); // 默认: "/Windows/System32" (移除了 C: 并标准化)
|
|
3529
|
+
*
|
|
3530
|
+
* StringUtil.toPosix("C:\\Windows\\System32", true); // 移除开头斜杠: "Windows/System32"
|
|
3531
|
+
*
|
|
3532
|
+
* StringUtil.toPosix("\\\\server\\share\\file.txt"); // UNC 路径: "/server/share/file.txt"
|
|
3533
|
+
*
|
|
3534
|
+
* StringUtil.toPosix("folder\\subfolder\\file.txt"); // 相对路径: "folder/subfolder/file.txt"
|
|
3535
|
+
* ```
|
|
3536
|
+
*/
|
|
3537
|
+
static toPosix(input: string | null | undefined, removeLeadingSlash?: boolean): string;
|
|
3538
|
+
/**
|
|
3539
|
+
* 处理 JSON 字符串
|
|
3540
|
+
*
|
|
3541
|
+
* @param input 待处理字符串
|
|
3542
|
+
* @param fallback 回退值
|
|
3543
|
+
* @returns 解析后的对象 或 回退值
|
|
3544
|
+
* @example
|
|
3545
|
+
* ```ts
|
|
3546
|
+
* StringUtil.toJson('{"a": 1}', {}); // { a: 1 }
|
|
3547
|
+
* StringUtil.toJson('invalid', {}); // {}
|
|
3548
|
+
* ```
|
|
3549
|
+
*/
|
|
3550
|
+
static toJson<D extends AnyObject = AnyObject>(input: string | null | undefined): D | undefined;
|
|
3551
|
+
static toJson<D extends AnyObject = AnyObject>(input: string | null | undefined, fallback: D): D;
|
|
3552
|
+
/**
|
|
3553
|
+
* 字符串分割为数组
|
|
3554
|
+
* - 按指定分隔符分割字符串,并转换类型
|
|
3555
|
+
*
|
|
3556
|
+
* @param input 待处理字符串
|
|
3557
|
+
* @param valueType 数组中每一项的类型,默认为 "number"
|
|
3558
|
+
* @param splitSymbol 分隔符,默认为 `,`
|
|
3559
|
+
* @returns 分割后的数组
|
|
3560
|
+
* @example
|
|
3561
|
+
* ```ts
|
|
3562
|
+
* StringUtil.toValues("1,2,3"); // [1, 2, 3]
|
|
3563
|
+
* StringUtil.toValues("a-b-c", "string", "-"); // ["a", "b", "c"]
|
|
3564
|
+
* ```
|
|
3565
|
+
*/
|
|
3566
|
+
static toValues(input: string | null | undefined, valueType?: "number" | undefined, splitSymbol?: string | undefined): number[];
|
|
3567
|
+
static toValues(input: string | null | undefined, valueType: "string", splitSymbol?: string | undefined): string[];
|
|
3568
|
+
/**
|
|
3569
|
+
* 从字符串中裁切掉所有的前缀和后缀字符
|
|
3570
|
+
*
|
|
3571
|
+
* @param input 待处理字符串
|
|
3572
|
+
* @param charsToTrim 裁切字符,默认为 `" "`
|
|
3573
|
+
* @returns 裁切后的字符串
|
|
3574
|
+
* @example
|
|
3575
|
+
* ```ts
|
|
3576
|
+
* StringUtil.trim(" hello "); // "hello"
|
|
3577
|
+
* StringUtil.trim("__hello__", "_"); // "hello"
|
|
3578
|
+
* ```
|
|
3579
|
+
*/
|
|
3580
|
+
static trim(input: string | null | undefined, charsToTrim?: string): string;
|
|
3581
|
+
/**
|
|
3582
|
+
* 截取字符串
|
|
3583
|
+
* - 支持自定义省略符,不会截断在汉字中间(因为JS字符串本身按字符处理)
|
|
3584
|
+
*
|
|
3585
|
+
* @param input 待处理字符串
|
|
3586
|
+
* @param maxLength 最大长度 (包含省略符)
|
|
3587
|
+
* @param ellipsis 省略符,默认为 `...`
|
|
3588
|
+
* @returns 截取后的字符串
|
|
3589
|
+
* @example
|
|
3590
|
+
* ```ts
|
|
3591
|
+
* StringUtil.truncate("hello world", 8); // "hello..."
|
|
3592
|
+
* ```
|
|
3593
|
+
*/
|
|
3594
|
+
static truncate(input: string, maxLength: number, ellipsis?: string): string;
|
|
3595
|
+
/**
|
|
3596
|
+
* 字符串模板替换
|
|
3597
|
+
* - 使用对象的属性值替换字符串中的 {{key}} 模板
|
|
3598
|
+
*
|
|
3599
|
+
* @param input 待处理字符串
|
|
3600
|
+
* @param template 模板对象
|
|
3601
|
+
* @param regex 模板匹配正则 (默认: `\{\{(.+?)\}\}`)
|
|
3602
|
+
* @returns 替换后的字符串
|
|
3603
|
+
* @example
|
|
3604
|
+
* ```ts
|
|
3605
|
+
* StringUtil.template("Hello {{name}}", { name: "World" }); // "Hello World"
|
|
3606
|
+
* ```
|
|
3607
|
+
*/
|
|
3608
|
+
static template(input: string, template: PlainObject, regex?: RegExp): string;
|
|
3609
|
+
/**
|
|
3610
|
+
* 字符串替换
|
|
3611
|
+
* - 替换第一个匹配项
|
|
3612
|
+
*
|
|
3613
|
+
* @param input 待处理字符串
|
|
3614
|
+
* @param search 匹配项
|
|
3615
|
+
* @param replacement 替换项
|
|
3616
|
+
* @returns 替换后的字符串
|
|
3617
|
+
* @example
|
|
3618
|
+
* ```ts
|
|
3619
|
+
* StringUtil.replace("hello world", "world", "context"); // "hello context"
|
|
3620
|
+
* ```
|
|
3621
|
+
*/
|
|
3622
|
+
static replace<I extends string, S extends string, R extends string>(input: I, search: S, replacement: R): Replace<I, S, R>;
|
|
3623
|
+
}
|
|
3624
|
+
//#endregion
|
|
3625
|
+
//#region src/theme/themeUtil.d.ts
|
|
3626
|
+
/**
|
|
3627
|
+
* 主题工具类
|
|
3628
|
+
*/
|
|
3629
|
+
declare class ThemeUtil {
|
|
3630
|
+
static readonly THEME: {
|
|
3631
|
+
readonly LIGHT: "light";
|
|
3632
|
+
readonly DARK: "dark";
|
|
3633
|
+
};
|
|
3634
|
+
static readonly THEME_MODE: {
|
|
3635
|
+
readonly LIGHT: "light";
|
|
3636
|
+
readonly DARK: "dark";
|
|
3637
|
+
readonly SYSTEM: "system";
|
|
3638
|
+
};
|
|
3639
|
+
}
|
|
3640
|
+
//#endregion
|
|
3641
|
+
//#region src/theme/index.type.d.ts
|
|
3642
|
+
type THEME_TYPE = ValueOf<typeof ThemeUtil.THEME>;
|
|
3643
|
+
type THEME_MODE_TYPE = ValueOf<typeof ThemeUtil.THEME_MODE>;
|
|
3644
|
+
//#endregion
|
|
3645
|
+
//#region src/tree/index.type.d.ts
|
|
3646
|
+
type RowKey = "id";
|
|
3647
|
+
type ParentIdKey = "parentId";
|
|
3648
|
+
type ChildrenKey = "children";
|
|
3649
|
+
type Strategy = "pre" | "post" | "breadth";
|
|
3650
|
+
interface BaseCallbackMeta<T> {
|
|
3651
|
+
depth: number;
|
|
3652
|
+
parents?: T[] | undefined;
|
|
3653
|
+
}
|
|
3654
|
+
interface BaseOptions<T, CK extends string> {
|
|
3655
|
+
childrenKey?: CK;
|
|
3656
|
+
strategy?: Strategy;
|
|
3657
|
+
getChildrenKey?: ((row: T, meta: BaseCallbackMeta<T>) => CK) | undefined;
|
|
3658
|
+
}
|
|
3659
|
+
interface RowsToTreeOptions<RK extends string = RowKey, PK extends string = ParentIdKey, CK extends string = ChildrenKey> {
|
|
3660
|
+
rowKey?: RK;
|
|
3661
|
+
parentIdKey?: PK;
|
|
3662
|
+
childrenKey?: CK;
|
|
3663
|
+
}
|
|
3664
|
+
type TreeToRowsOptions<T extends AnyObject, CK extends string = ChildrenKey> = TreeForeachOptions<T, CK>;
|
|
3665
|
+
type TreeFindOptions<T extends AnyObject, CK extends string = ChildrenKey> = BaseOptions<T, CK>;
|
|
3666
|
+
type TreeFindCallback<T extends AnyObject> = (row: T, meta: BaseCallbackMeta<T>) => boolean;
|
|
3667
|
+
type TreeForeachOptions<T extends AnyObject, CK extends string = ChildrenKey> = BaseOptions<T, CK>;
|
|
3668
|
+
type TreeForeachCallback<T extends AnyObject> = (row: T, meta: BaseCallbackMeta<T>) => void;
|
|
3669
|
+
type TreeFilterOptions<T extends AnyObject, CK extends string = ChildrenKey> = BaseOptions<T, CK>;
|
|
3670
|
+
type TreeFilterCallback<T extends AnyObject> = (row: T, meta: BaseCallbackMeta<T>) => boolean;
|
|
3671
|
+
type TreeMapOptions<T extends AnyObject, CK extends string> = BaseOptions<T, CK>;
|
|
3672
|
+
type TreeMapCallback<R extends AnyObject, T extends AnyObject> = (row: T, meta: BaseCallbackMeta<T>) => R;
|
|
3673
|
+
//#endregion
|
|
3674
|
+
//#region src/tree/treeUtil.d.ts
|
|
3675
|
+
/**
|
|
3676
|
+
* 树结构工具类
|
|
3677
|
+
*/
|
|
3678
|
+
declare class TreeUtil {
|
|
3679
|
+
/**
|
|
3680
|
+
* 行结构 转 树结构
|
|
3681
|
+
* - 将平铺的数组转换为树形结构
|
|
3682
|
+
*
|
|
3683
|
+
* @param rows 行数据数组
|
|
3684
|
+
* @param options 配置项
|
|
3685
|
+
* @returns 树结构数组
|
|
3686
|
+
* @example
|
|
3687
|
+
* ```ts
|
|
3688
|
+
* const rows = [
|
|
3689
|
+
* { id: 1, parentId: null },
|
|
3690
|
+
* { id: 2, parentId: 1 },
|
|
3691
|
+
* ];
|
|
3692
|
+
* TreeUtil.rowsToTree(rows); // [{ id: 1, parentId: null, children: [{ id: 2, parentId: 1 }] }]
|
|
3693
|
+
* ```
|
|
3694
|
+
*/
|
|
3695
|
+
static rowsToTree<T extends AnyObject = AnyObject, CK extends string = ChildrenKey, R = TreeLike<T, CK>, RK extends string = RowKey, PK extends string = ParentIdKey>(rows: T[], options?: RowsToTreeOptions<RK, PK, CK> | undefined): R[];
|
|
3696
|
+
/**
|
|
3697
|
+
* 树结构 转 行结构
|
|
3698
|
+
* - 将树形结构扁平化为数组
|
|
3699
|
+
*
|
|
3700
|
+
* @param tree 树结构数据 (单个节点或节点数组)
|
|
3701
|
+
* @param options 配置项
|
|
3702
|
+
* @returns 扁平化后的数组
|
|
3703
|
+
* @example
|
|
3704
|
+
* ```ts
|
|
3705
|
+
* const tree = [{ id: 1, children: [{ id: 2 }] }];
|
|
3706
|
+
* TreeUtil.treeToRows(tree); // [{ id: 1, children: undefined }, { id: 2, children: undefined }]
|
|
3707
|
+
* ```
|
|
3708
|
+
*/
|
|
3709
|
+
static treeToRows<T extends AnyObject, CK extends string = ChildrenKey, R extends AnyObject = SetOptional<T, CK>>(tree: T | T[], options?: TreeToRowsOptions<T, CK>): R[];
|
|
3710
|
+
/**
|
|
3711
|
+
* 遍历树节点
|
|
3712
|
+
*
|
|
3713
|
+
* @param tree 树结构数据
|
|
3714
|
+
* @param callback 回调函数
|
|
3715
|
+
* @param options 配置项
|
|
3716
|
+
* @example
|
|
3717
|
+
* ```ts
|
|
3718
|
+
* const tree = [{ id: 1, children: [{ id: 2 }] }];
|
|
3719
|
+
* const ids: number[] = [];
|
|
3720
|
+
* TreeUtil.forEach(tree, (node) => ids.push(node.id)); // ids: [1, 2] (pre-order default)
|
|
3721
|
+
* ```
|
|
3722
|
+
*/
|
|
3723
|
+
static forEach<T extends AnyObject, CK extends string = ChildrenKey>(tree: T | T[], callback: TreeForeachCallback<T>, options?: TreeForeachOptions<T, CK>): void;
|
|
3724
|
+
/**
|
|
3725
|
+
* 查找树节点
|
|
3726
|
+
* - 返回第一个回调返回 true 的节点
|
|
3727
|
+
*
|
|
3728
|
+
* @param tree 树结构数据
|
|
3729
|
+
* @param callback 回调函数
|
|
3730
|
+
* @param options 配置项
|
|
3731
|
+
* @returns 找到的节点,未找到则返回 undefined
|
|
3732
|
+
* @example
|
|
3733
|
+
* ```ts
|
|
3734
|
+
* const tree = [{ id: 1, children: [{ id: 2 }] }];
|
|
3735
|
+
* TreeUtil.find(tree, (node) => node.id === 2); // { id: 2, ... }
|
|
3736
|
+
* ```
|
|
3737
|
+
*/
|
|
3738
|
+
static find<T extends AnyObject, CK extends string = ChildrenKey>(tree: T | T[], callback: TreeFindCallback<T>, options?: TreeFindOptions<T, CK>): T | undefined;
|
|
3739
|
+
/**
|
|
3740
|
+
* 过滤树节点
|
|
3741
|
+
* - 返回新的树结构,包含所有回调返回 true 的节点
|
|
3742
|
+
* - 如果父节点被过滤,则其子节点也会被过滤 (pre 策略下)
|
|
3743
|
+
*
|
|
3744
|
+
* @param tree 树结构数据
|
|
3745
|
+
* @param callback 回调函数
|
|
3746
|
+
* @param options 配置项 (childrenKey, strategy等)
|
|
3747
|
+
* @returns 过滤后的树结构数组
|
|
3748
|
+
* @example
|
|
3749
|
+
* ```ts
|
|
3750
|
+
* const tree = [{ id: 1, visible: true, children: [{ id: 2, visible: false }] }];
|
|
3751
|
+
* TreeUtil.filter(tree, (node) => node.visible);
|
|
3752
|
+
* // [{ id: 1, visible: true, children: [] }]
|
|
3753
|
+
* ```
|
|
3754
|
+
*/
|
|
3755
|
+
static filter<T extends AnyObject, CK extends string = ChildrenKey>(tree: T[], callback: TreeFilterCallback<T>, options?: TreeFilterOptions<T, CK>): T[];
|
|
3756
|
+
static filter<T extends AnyObject, CK extends string = ChildrenKey>(tree: T, callback: TreeFilterCallback<T>, options?: TreeFilterOptions<T, CK>): T;
|
|
3757
|
+
/**
|
|
3758
|
+
* 映射树节点
|
|
3759
|
+
* - 返回新的树结构,保持层级关系
|
|
3760
|
+
*
|
|
3761
|
+
* @param tree 树结构数据
|
|
3762
|
+
* @param callback 回调函数 (返回映射后的节点内容)
|
|
3763
|
+
* @param options 配置项
|
|
3764
|
+
* @returns 映射后的树结构数组
|
|
3765
|
+
* @example
|
|
3766
|
+
* ```ts
|
|
3767
|
+
* const tree = [{ id: 1, val: 10, children: [{ id: 2, val: 20 }] }];
|
|
3768
|
+
* TreeUtil.map(tree, (node) => ({ ...node, val: node.val * 2 }));
|
|
3769
|
+
* // [{ id: 1, val: 20, children: [{ id: 2, val: 40 }] }]
|
|
3770
|
+
* ```
|
|
3771
|
+
*/
|
|
3772
|
+
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>[];
|
|
3773
|
+
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>;
|
|
3774
|
+
}
|
|
3775
|
+
//#endregion
|
|
3776
|
+
//#region src/type/index.type.d.ts
|
|
3777
|
+
interface Class<T, Arguments extends unknown[] = unknown[]> {
|
|
3778
|
+
new (...arguments_: Arguments): T;
|
|
3779
|
+
prototype: Pick<T, keyof T>;
|
|
3780
|
+
}
|
|
3781
|
+
//#endregion
|
|
3782
|
+
//#region src/type/typeUtil.d.ts
|
|
3783
|
+
/**
|
|
3784
|
+
* 类型工具类
|
|
3785
|
+
*/
|
|
3786
|
+
declare class TypeUtil {
|
|
3787
|
+
private static readonly PROTOTYPE_TAGS;
|
|
3788
|
+
private static readonly TYPED_ARRAY_TAGS;
|
|
3789
|
+
/**
|
|
3790
|
+
* 获取值的 [[Prototype]] 标签
|
|
3791
|
+
*
|
|
3792
|
+
* @param value - 任意 JavaScript 值
|
|
3793
|
+
* @returns 标准化的类型标签字符串
|
|
3794
|
+
*/
|
|
3795
|
+
private static getPrototypeString;
|
|
3796
|
+
private static isConstructable;
|
|
3797
|
+
/**
|
|
3798
|
+
* 检查 value 是否为 string 类型
|
|
3799
|
+
*
|
|
3800
|
+
* @param value 待检查值
|
|
3801
|
+
* @param checkEmpty 是否检查空字符串
|
|
3802
|
+
* @returns 是否为字符串
|
|
3803
|
+
* @example
|
|
3804
|
+
* ```ts
|
|
3805
|
+
* TypeUtil.isString("abc"); // true
|
|
3806
|
+
* TypeUtil.isString(""); // true
|
|
3807
|
+
* TypeUtil.isString("", true); // false
|
|
3808
|
+
* ```
|
|
3809
|
+
*/
|
|
3810
|
+
static isString(value: unknown, checkEmpty?: boolean): value is string;
|
|
3811
|
+
/**
|
|
3812
|
+
* 检查 value 是否为 number 类型
|
|
3813
|
+
*
|
|
3814
|
+
* @param value 待检查值
|
|
3815
|
+
* @param checkNaN 是否排除 `NaN`,默认为 `true`
|
|
3816
|
+
* @returns 是否为 number
|
|
3817
|
+
* @example
|
|
3818
|
+
* ```ts
|
|
3819
|
+
* TypeUtil.isNumber(1); // true
|
|
3820
|
+
* TypeUtil.isNumber(NaN); // false (default)
|
|
3821
|
+
* TypeUtil.isNumber(NaN, false); // true
|
|
3822
|
+
* ```
|
|
3823
|
+
*/
|
|
3824
|
+
static isNumber(value: unknown, checkNaN?: boolean): value is number;
|
|
3825
|
+
/**
|
|
3826
|
+
* 检查 value 是否为 NaN
|
|
3827
|
+
*
|
|
3828
|
+
* @param value 待检查值
|
|
3829
|
+
* @returns 是否为 NaN
|
|
3830
|
+
*/
|
|
3831
|
+
static isNaN(value: unknown): value is number;
|
|
3832
|
+
/**
|
|
3833
|
+
* 检查 value 是否为整数
|
|
3834
|
+
*
|
|
3835
|
+
* @param value 待检查值
|
|
3836
|
+
* @param checkSafe 是否附加安全整数检查
|
|
3837
|
+
* @returns 是否为整数
|
|
3838
|
+
*/
|
|
3839
|
+
static isInteger(value: unknown, checkSafe?: boolean): value is number;
|
|
3840
|
+
/**
|
|
3841
|
+
* 检查 value 是否为正整数
|
|
3842
|
+
* - 此函数中 `0` 不被视为正整数
|
|
3843
|
+
*
|
|
3844
|
+
* @param value 待检查值
|
|
3845
|
+
* @param checkSafe 是否附加安全整数检查
|
|
3846
|
+
*/
|
|
3847
|
+
static isPositiveInteger(value: unknown, checkSafe?: boolean): value is number;
|
|
3848
|
+
/**
|
|
3849
|
+
* 检查 value 是否为负整数
|
|
3850
|
+
* - 此函数中 `0` 不被视为负整数
|
|
3851
|
+
*
|
|
3852
|
+
* @param value 待检查值
|
|
3853
|
+
* @param checkSafe 是否附加安全整数检查
|
|
3854
|
+
*/
|
|
3855
|
+
static isNegativeInteger(value: unknown, checkSafe?: boolean): value is number;
|
|
3856
|
+
/**
|
|
3857
|
+
* 检查 value 是否为 Infinity
|
|
3858
|
+
* - 排除 `NaN`
|
|
3859
|
+
*
|
|
3860
|
+
* @param value 待检查值
|
|
3861
|
+
*/
|
|
3862
|
+
static isInfinity(value: unknown): value is number;
|
|
3863
|
+
/**
|
|
3864
|
+
* 检查 value 是否类似 Infinity
|
|
3865
|
+
* - 排除 `NaN`
|
|
3866
|
+
*
|
|
3867
|
+
* @param value 待检查值
|
|
3868
|
+
*/
|
|
3869
|
+
static isInfinityLike(value: unknown): boolean;
|
|
3870
|
+
/**
|
|
3871
|
+
* 检查 value 是否为 Boolean
|
|
3872
|
+
* @param value 待检查值
|
|
3873
|
+
* @returns 是否为 Boolean
|
|
3874
|
+
*/
|
|
3875
|
+
static isBoolean(value: unknown): value is boolean;
|
|
3876
|
+
/**
|
|
3877
|
+
* 检查 value 是否为 BigInt
|
|
3878
|
+
* @param value 待检查值
|
|
3879
|
+
* @returns 是否为 BigInt
|
|
3880
|
+
*/
|
|
3881
|
+
static isBigInt(value: unknown): value is bigint;
|
|
3882
|
+
/**
|
|
3883
|
+
* 检查 value 是否为 Symbol
|
|
3884
|
+
* @param value 待检查值
|
|
3885
|
+
* @returns 是否为 Symbol
|
|
3886
|
+
*/
|
|
3887
|
+
static isSymbol(value: unknown): value is symbol;
|
|
3888
|
+
/**
|
|
3889
|
+
* 检查 value 是否为 undefined
|
|
3890
|
+
* @param value 待检查值
|
|
3891
|
+
* @returns 是否为 undefined
|
|
3892
|
+
*/
|
|
3893
|
+
static isUndefined(value: unknown): value is undefined;
|
|
3894
|
+
/**
|
|
3895
|
+
* 检查 value 是否为 null
|
|
3896
|
+
* @param value 待检查值
|
|
3897
|
+
* @returns 是否为 null
|
|
3898
|
+
*/
|
|
3899
|
+
static isNull(value: unknown): value is null;
|
|
3900
|
+
/**
|
|
3901
|
+
* 检查 value 是否为 Function
|
|
3902
|
+
* @param value 待检查值
|
|
3903
|
+
* @returns 是否为 Function
|
|
3904
|
+
*/
|
|
3905
|
+
static isFunction(value: unknown): value is AnyFunction;
|
|
3906
|
+
/**
|
|
3907
|
+
* 检查 value 是否为 AsyncFunction
|
|
3908
|
+
* @param value 待检查值
|
|
3909
|
+
* @returns 是否为 AsyncFunction
|
|
3910
|
+
*/
|
|
3911
|
+
static isAsyncFunction(value: unknown): value is AnyAsyncFunction;
|
|
3912
|
+
/**
|
|
3913
|
+
* 检查 value 是否为 GeneratorFunction
|
|
3914
|
+
* @param value 待检查值
|
|
3915
|
+
* @returns 是否为 GeneratorFunction
|
|
3916
|
+
*/
|
|
3917
|
+
static isGeneratorFunction(value: unknown): value is AnyGeneratorFunction;
|
|
3918
|
+
/**
|
|
3919
|
+
* 检查 value 是否为 AsyncGeneratorFunction
|
|
3920
|
+
* @param value 待检查值
|
|
3921
|
+
* @returns 是否为 AsyncGeneratorFunction
|
|
3922
|
+
*/
|
|
3923
|
+
static isAsyncGeneratorFunction(value: unknown): value is AnyAsyncGeneratorFunction;
|
|
3924
|
+
/**
|
|
3925
|
+
* 检查 value 是否为 Promise
|
|
3926
|
+
* @param value 待检查值
|
|
3927
|
+
* @returns 是否为 Promise
|
|
3928
|
+
*/
|
|
3929
|
+
static isPromise(value: unknown): value is Promise<unknown>;
|
|
3930
|
+
/**
|
|
3931
|
+
* 检查 value 是否为 PromiseLike
|
|
3932
|
+
* - 可识别拥有 then 方法的非 Promise 对象
|
|
3933
|
+
* @param value 待检查值
|
|
3934
|
+
* @returns 是否为 PromiseLike
|
|
3935
|
+
*/
|
|
3936
|
+
static isPromiseLike(value: unknown): value is PromiseLike<unknown>;
|
|
3937
|
+
/**
|
|
3938
|
+
* 判断是否为普通对象类型
|
|
3939
|
+
* - 可选是否检查原型为 `Object.prototype`,防止原型链污染
|
|
3940
|
+
*
|
|
3941
|
+
* @param value 待检查值
|
|
3942
|
+
* @param prototypeCheck 是否进行原型检查,默认 `true`
|
|
3943
|
+
* @returns 是否为 Plain Object (当 checkPrototype=true) 或 object
|
|
3944
|
+
* @example
|
|
3945
|
+
* ```ts
|
|
3946
|
+
* TypeUtil.isObject({}); // true
|
|
3947
|
+
* TypeUtil.isObject([]); // false
|
|
3948
|
+
* TypeUtil.isObject(new Date()); // false
|
|
3949
|
+
* TypeUtil.isObject(new Date(), false); // true
|
|
3950
|
+
* TypeUtil.isObject(Object.create(null)) // false
|
|
3951
|
+
* TypeUtil.isObject(Object.create(null), false) // true
|
|
3952
|
+
* ```
|
|
3953
|
+
*/
|
|
3954
|
+
static isObject(value: unknown, prototypeCheck?: boolean): value is Record<PropertyKey, unknown>;
|
|
3955
|
+
/**
|
|
3956
|
+
* 判断一个对象是否为有效的枚举
|
|
3957
|
+
* - 枚举成员不能为空
|
|
3958
|
+
* - 枚举成员的键不能具有数值名
|
|
3959
|
+
* - 枚举成员的值必须类型一致且为 `string` 或 `number` 类型
|
|
3960
|
+
* - 枚举成员的值不能重复
|
|
3961
|
+
* - 枚举成员的值必须全部为双向映射或非双向映射
|
|
3962
|
+
*
|
|
3963
|
+
* @param enumeration 待检查值
|
|
3964
|
+
* @returns [是否为有效的枚举, 是否为双向枚举]
|
|
3965
|
+
*/
|
|
3966
|
+
static isEnumeration(enumeration: PlainObject): [boolean, boolean];
|
|
3967
|
+
/**
|
|
3968
|
+
* 检查 value 是否为 Class
|
|
3969
|
+
*
|
|
3970
|
+
* @param value 待检查值
|
|
3971
|
+
* @returns 是否为 Class
|
|
3972
|
+
* @example
|
|
3973
|
+
* ```ts
|
|
3974
|
+
* class A {}
|
|
3975
|
+
* TypeUtil.isClass(A); // true
|
|
3976
|
+
* TypeUtil.isClass(() => {}); // false
|
|
3977
|
+
* ```
|
|
3978
|
+
*/
|
|
3979
|
+
static isClass(value: unknown): value is Class<AnyObject>;
|
|
3980
|
+
/**
|
|
3981
|
+
* 检查 value 是否为数组
|
|
3982
|
+
*
|
|
3983
|
+
* @param value 待检查值
|
|
3984
|
+
* @returns 是否为数组
|
|
3985
|
+
* @example
|
|
3986
|
+
* ```ts
|
|
3987
|
+
* TypeUtil.isArray([]); // true
|
|
3988
|
+
* ```
|
|
3989
|
+
*/
|
|
3990
|
+
static isArray(value: unknown): value is unknown[];
|
|
3991
|
+
/**
|
|
3992
|
+
* 检查 value 是否为 TypedArray
|
|
3993
|
+
*
|
|
3994
|
+
* @param value 待检查值
|
|
3995
|
+
* @returns 是否为 TypedArray
|
|
3996
|
+
* @example
|
|
3997
|
+
* ```ts
|
|
3998
|
+
* TypeUtil.isTypedArray(new Int8Array()); // true
|
|
3999
|
+
* ```
|
|
4000
|
+
*/
|
|
4001
|
+
static isTypedArray(value: unknown): value is TypedArray;
|
|
4002
|
+
/**
|
|
4003
|
+
* 检查 value 是否为 Map
|
|
4004
|
+
* @param value 待检查值
|
|
4005
|
+
* @returns 是否为 Map
|
|
4006
|
+
*/
|
|
4007
|
+
static isMap(value: unknown): value is Map<unknown, unknown>;
|
|
4008
|
+
/**
|
|
4009
|
+
* 检查 value 是否为 WeakMap
|
|
4010
|
+
* @param value 待检查值
|
|
4011
|
+
* @returns 是否为 WeakMap
|
|
4012
|
+
*/
|
|
4013
|
+
static isWeakMap(value: unknown): value is WeakMap<AnyObject, unknown>;
|
|
4014
|
+
/**
|
|
4015
|
+
* 检查 value 是否为 Set
|
|
4016
|
+
* @param value 待检查值
|
|
4017
|
+
* @returns 是否为 Set
|
|
4018
|
+
*/
|
|
4019
|
+
static isSet(value: unknown): value is Set<unknown>;
|
|
4020
|
+
/**
|
|
4021
|
+
* 检查 value 是否为 WeakSet
|
|
4022
|
+
* @param value 待检查值
|
|
4023
|
+
* @returns 是否为 WeakSet
|
|
4024
|
+
*/
|
|
4025
|
+
static isWeakSet(value: unknown): value is WeakSet<AnyObject>;
|
|
4026
|
+
/**
|
|
4027
|
+
* 检查 value 是否为 Blob
|
|
4028
|
+
* @param value 待检查值
|
|
4029
|
+
* @returns 是否为 Blob
|
|
4030
|
+
*/
|
|
4031
|
+
static isBlob(value: unknown): value is Blob;
|
|
4032
|
+
/**
|
|
4033
|
+
* 检查 value 是否为 File
|
|
4034
|
+
* @param value 待检查值
|
|
4035
|
+
* @returns 是否为 File
|
|
4036
|
+
*/
|
|
4037
|
+
static isFile(value: unknown): value is File;
|
|
4038
|
+
/**
|
|
4039
|
+
* 检查 value 是否为 ReadableStream
|
|
4040
|
+
* - Uses `Object.prototype.toString` where supported (modern browsers, Node.js ≥18).
|
|
4041
|
+
* - Falls back to duck-typing in older environments.
|
|
4042
|
+
* - Resistant to basic forgery, but not 100% secure in all polyfill scenarios.
|
|
4043
|
+
* - ⚠️ Note: In older Node.js (<18) or with non-compliant polyfills, this may return false positives or negatives.
|
|
4044
|
+
*
|
|
4045
|
+
* @param value 待检查值
|
|
4046
|
+
* @returns 是否为 ReadableStream
|
|
4047
|
+
*/
|
|
4048
|
+
static isReadableStream(value: unknown): value is ReadableStream;
|
|
4049
|
+
/**
|
|
4050
|
+
* 检查 value 是否为 Window
|
|
4051
|
+
* @param value 待检查值
|
|
4052
|
+
* @returns 是否为 Window
|
|
4053
|
+
*/
|
|
4054
|
+
static isWindow(value: unknown): value is Window;
|
|
4055
|
+
/**
|
|
4056
|
+
* 检查 value 是否为 HTMLIFrameElement
|
|
4057
|
+
* @param value 待检查值
|
|
4058
|
+
* @returns 是否为 HTMLIFrameElement
|
|
4059
|
+
*/
|
|
4060
|
+
static isIframe(value: unknown): value is HTMLIFrameElement;
|
|
4061
|
+
/**
|
|
4062
|
+
* 检查 value 是否为 Date 对象
|
|
4063
|
+
*
|
|
4064
|
+
* @param value 待检查值
|
|
4065
|
+
* @param invalidCheck 是否要求日期有效(非 Invalid Date)。默认 true
|
|
4066
|
+
* - true: 仅当是有效 Date 对象时返回 true(排除 new Date('invalid'))
|
|
4067
|
+
* - false: 只要 [[Prototype]] 是 Date 即返回 true(包含 Invalid Date)
|
|
4068
|
+
* @returns 是否为 Date 对象,根据 invalidCheck 返回不同语义的 Date 判定
|
|
4069
|
+
*
|
|
4070
|
+
* @example
|
|
4071
|
+
* ```ts
|
|
4072
|
+
* TypeUtil.isDate(new Date()); // true
|
|
4073
|
+
* TypeUtil.isDate(new Date('invalid')); // false
|
|
4074
|
+
* TypeUtil.isDate(new Date('invalid'), false); // true
|
|
4075
|
+
* TypeUtil.isDate(null); // false
|
|
4076
|
+
* TypeUtil.isDate({}); // false
|
|
4077
|
+
* ```
|
|
4078
|
+
*/
|
|
4079
|
+
static isDate(value: unknown, invalidCheck?: boolean): value is Date;
|
|
4080
|
+
/**
|
|
4081
|
+
* 检查 value 是否为 Error 对象
|
|
4082
|
+
* @param value 待检查值
|
|
4083
|
+
* @returns 是否为 Error
|
|
4084
|
+
*/
|
|
4085
|
+
static isError(value: unknown): value is Error;
|
|
4086
|
+
/**
|
|
4087
|
+
* 检查 value 是否为 RegExp
|
|
4088
|
+
* @param value 待检查值
|
|
4089
|
+
* @returns 是否为 RegExp
|
|
4090
|
+
*/
|
|
4091
|
+
static isRegExp(value: unknown): value is RegExp;
|
|
4092
|
+
/**
|
|
4093
|
+
* 检查 value 是否为 WebSocket
|
|
4094
|
+
* @param value 待检查值
|
|
4095
|
+
* @returns 是否为 WebSocket
|
|
4096
|
+
*/
|
|
4097
|
+
static isWebSocket(value: unknown): value is WebSocket;
|
|
4098
|
+
/**
|
|
4099
|
+
* 检查 value 是否为 URLSearchParams
|
|
4100
|
+
* @param value 待检查值
|
|
4101
|
+
* @returns 是否为 URLSearchParams
|
|
4102
|
+
*/
|
|
4103
|
+
static isURLSearchParams(value: unknown): value is URLSearchParams;
|
|
4104
|
+
/**
|
|
4105
|
+
* 检查 value 是否为 AbortSignal
|
|
4106
|
+
* @param value 待检查值
|
|
4107
|
+
* @returns 是否为 AbortSignal
|
|
4108
|
+
*/
|
|
4109
|
+
static isAbortSignal(value: unknown): value is AbortSignal;
|
|
4110
|
+
/**
|
|
4111
|
+
* 检查 value 是否为可迭代对象 (Iterable)
|
|
4112
|
+
* @param value 待检查值
|
|
4113
|
+
* @returns 是否为 Iterable
|
|
4114
|
+
*/
|
|
4115
|
+
static isIterable(value: unknown): value is {
|
|
4116
|
+
[Symbol.iterator]: () => Iterator<unknown>;
|
|
4117
|
+
};
|
|
4118
|
+
/**
|
|
4119
|
+
* 检查 value 是否为 Falsy 值 (false, 0, "", null, undefined, NaN)
|
|
4120
|
+
* @param value 待检查值
|
|
4121
|
+
* @returns 是否为 Falsy
|
|
4122
|
+
*/
|
|
4123
|
+
static isFalsy(value: unknown): value is false | 0 | "" | null | undefined;
|
|
4124
|
+
static isFalsyLike(value: unknown): boolean;
|
|
4125
|
+
}
|
|
4126
|
+
//#endregion
|
|
4127
|
+
//#region src/validate/validateUtil.d.ts
|
|
4128
|
+
/**
|
|
4129
|
+
* 验证工具类
|
|
4130
|
+
*/
|
|
4131
|
+
declare class ValidateUtil {
|
|
4132
|
+
static _phone: RegExp;
|
|
4133
|
+
/**
|
|
4134
|
+
* 验证是否为手机号码
|
|
4135
|
+
*/
|
|
4136
|
+
static isPhone(input: string): boolean;
|
|
4137
|
+
static _telephone: RegExp;
|
|
4138
|
+
/**
|
|
4139
|
+
* 验证是否为固定电话
|
|
4140
|
+
*/
|
|
4141
|
+
static isTelephone(input: string): boolean;
|
|
4142
|
+
static _IMEI: RegExp;
|
|
4143
|
+
/**
|
|
4144
|
+
* 验证是否为移动设备识别码
|
|
4145
|
+
*/
|
|
4146
|
+
static isIMEI(input: string): boolean;
|
|
4147
|
+
static _email: RegExp;
|
|
4148
|
+
/**
|
|
4149
|
+
* 验证是否为电子邮箱
|
|
4150
|
+
*/
|
|
4151
|
+
static isEmail(input: string): boolean;
|
|
4152
|
+
static _link: RegExp;
|
|
4153
|
+
/**
|
|
4154
|
+
* 验证是否为 http(s) 链接
|
|
4155
|
+
*/
|
|
4156
|
+
static isHttpLink(input: string): boolean;
|
|
4157
|
+
static _portLink: RegExp;
|
|
4158
|
+
/**
|
|
4159
|
+
* 验证是否为端口号链接
|
|
4160
|
+
*/
|
|
4161
|
+
static isPortLink(input: string): boolean;
|
|
4162
|
+
static _thunderLink: RegExp;
|
|
4163
|
+
/**
|
|
4164
|
+
* 验证是否为迅雷链接
|
|
4165
|
+
*/
|
|
4166
|
+
static isThunderLink(input: string): boolean;
|
|
4167
|
+
static _uscc: RegExp;
|
|
4168
|
+
/**
|
|
4169
|
+
* 验证是否为统一社会信用代码
|
|
4170
|
+
*/
|
|
4171
|
+
static isUSCC(input: string): boolean;
|
|
4172
|
+
static _usccs: RegExp;
|
|
4173
|
+
/**
|
|
4174
|
+
* 验证是否为统一社会信用代码 - 15位/18位/20位数字/字母
|
|
4175
|
+
*/
|
|
4176
|
+
static isUSCCS(input: string): boolean;
|
|
4177
|
+
static _dirPathWindows: RegExp;
|
|
4178
|
+
/**
|
|
4179
|
+
* 验证是否为 Windows 系统文件夹路径
|
|
4180
|
+
*/
|
|
4181
|
+
static isDirPathWindows(input: string): boolean;
|
|
4182
|
+
static _filePathWindows: RegExp;
|
|
4183
|
+
/**
|
|
4184
|
+
* 验证是否为 Windows 系统文件路径
|
|
4185
|
+
*/
|
|
4186
|
+
static isFilePathWindows(input: string): boolean;
|
|
4187
|
+
static _dirPathLinux: RegExp;
|
|
4188
|
+
/**
|
|
4189
|
+
* 验证是否为 Linux 系统文件夹路径
|
|
4190
|
+
*/
|
|
4191
|
+
static isDirPathLinux(input: string): boolean;
|
|
4192
|
+
static _filePathLinux: RegExp;
|
|
4193
|
+
/**
|
|
4194
|
+
* 验证是否为 Linux 系统文件路径
|
|
4195
|
+
*/
|
|
4196
|
+
static isFilePathLinux(input: string): boolean;
|
|
4197
|
+
static _EVCarNumber: RegExp;
|
|
4198
|
+
/**
|
|
4199
|
+
* 验证是否为新能源车牌号
|
|
4200
|
+
*/
|
|
4201
|
+
static isEVCarNumber(input: string): boolean;
|
|
4202
|
+
static _GVCarNumber: RegExp;
|
|
4203
|
+
/**
|
|
4204
|
+
* 验证是否为燃油车车牌号
|
|
4205
|
+
*/
|
|
4206
|
+
static isGVCarNumber(input: string): boolean;
|
|
4207
|
+
static _chineseName: RegExp;
|
|
4208
|
+
/**
|
|
4209
|
+
* 验证是否为中文姓名
|
|
4210
|
+
*/
|
|
4211
|
+
static isChineseName(input: string): boolean;
|
|
4212
|
+
static _chineseId: RegExp;
|
|
4213
|
+
/**
|
|
4214
|
+
* 验证是否为中国身份证号
|
|
4215
|
+
*/
|
|
4216
|
+
static isChineseID(input: string): boolean;
|
|
4217
|
+
static _chineseProvince: RegExp;
|
|
4218
|
+
/**
|
|
4219
|
+
* 验证是否为中国省份
|
|
4220
|
+
*/
|
|
4221
|
+
static isChineseProvince(input: string): boolean;
|
|
4222
|
+
static _chineseNation: RegExp;
|
|
4223
|
+
/**
|
|
4224
|
+
* 验证是否为中华民族
|
|
4225
|
+
*/
|
|
4226
|
+
static isChineseNation(input: string): boolean;
|
|
4227
|
+
static _letter: RegExp;
|
|
4228
|
+
/**
|
|
4229
|
+
* 验证是否只包含字母
|
|
4230
|
+
*/
|
|
4231
|
+
static isLetter(input: string): boolean;
|
|
4232
|
+
static _letterLowercase: RegExp;
|
|
4233
|
+
/**
|
|
4234
|
+
* 验证是否只包含小写字母
|
|
4235
|
+
*/
|
|
4236
|
+
static isLetterLowercase(input: string): boolean;
|
|
4237
|
+
static _letterUppercase: RegExp;
|
|
4238
|
+
/**
|
|
4239
|
+
* 验证是否只包含大写字母
|
|
4240
|
+
*/
|
|
4241
|
+
static isLetterUppercase(input: string): boolean;
|
|
4242
|
+
static _letterOmit: RegExp;
|
|
4243
|
+
/**
|
|
4244
|
+
* 验证是否不包含字母
|
|
4245
|
+
*/
|
|
4246
|
+
static isLetterOmit(input: string): boolean;
|
|
4247
|
+
static _LetterAndNumber: RegExp;
|
|
4248
|
+
/**
|
|
4249
|
+
* 验证是否为数字和字母组合
|
|
4250
|
+
*/
|
|
4251
|
+
static isLetterAndNumber(input: string): boolean;
|
|
4252
|
+
static _signedFloat: RegExp;
|
|
4253
|
+
/**
|
|
4254
|
+
* 验证是否为有符号浮点数
|
|
4255
|
+
*/
|
|
4256
|
+
static isSignedFloat(input: string): boolean;
|
|
4257
|
+
static _unsignedFloat: RegExp;
|
|
4258
|
+
/**
|
|
4259
|
+
* 验证是否为无符号浮点数
|
|
4260
|
+
*/
|
|
4261
|
+
static isUnsignedFloat(input: string): boolean;
|
|
4262
|
+
static _signedInteger: RegExp;
|
|
4263
|
+
/**
|
|
4264
|
+
* 验证是否为有符号整数
|
|
4265
|
+
*/
|
|
4266
|
+
static isSignedInteger(input: string): boolean;
|
|
4267
|
+
static _unsignedInteger: RegExp;
|
|
4268
|
+
/**
|
|
4269
|
+
* 验证是否为无符号整数
|
|
4270
|
+
*/
|
|
4271
|
+
static isUnsignedInteger(input: string): boolean;
|
|
4272
|
+
static _spaceInclude: RegExp;
|
|
4273
|
+
/**
|
|
4274
|
+
* 验证是否包含空格
|
|
4275
|
+
*/
|
|
4276
|
+
static isSpaceInclude(input: string): boolean;
|
|
4277
|
+
static _spaceStart: RegExp;
|
|
4278
|
+
/**
|
|
4279
|
+
* 验证是否以空格开头
|
|
4280
|
+
*/
|
|
4281
|
+
static isSpaceStart(input: string): boolean;
|
|
4282
|
+
static _spaceEnd: RegExp;
|
|
4283
|
+
/**
|
|
4284
|
+
* 验证是否以空格结尾
|
|
4285
|
+
*/
|
|
4286
|
+
static isSpaceEnd(input: string): boolean;
|
|
4287
|
+
/**
|
|
4288
|
+
* 验证是否以空格开头或结尾
|
|
4289
|
+
*/
|
|
4290
|
+
static isSpaceStartOrEnd(input: string): boolean;
|
|
4291
|
+
}
|
|
4292
|
+
//#endregion
|
|
4293
|
+
export { ArrayUtil, DateTimeUtil, EnvUtil, FunctionUtil, MimeUtil, NumberUtil, ObjectUtil, StringUtil, THEME_MODE_TYPE, THEME_TYPE, ThemeUtil, TreeUtil, TypeUtil, ValidateUtil };
|