@pawover/kit 0.0.0-alpha.9 → 0.0.0-beta.2
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/dist/enums.d.ts +25 -0
- package/dist/enums.d.ts.map +1 -0
- package/dist/enums.js +25 -0
- package/dist/enums.js.map +1 -0
- package/dist/hooks-alova.d.ts +23 -0
- package/dist/hooks-alova.d.ts.map +1 -0
- package/dist/hooks-alova.js +39 -0
- package/dist/hooks-alova.js.map +1 -0
- package/dist/hooks-react.d.ts +89 -0
- package/dist/hooks-react.d.ts.map +1 -0
- package/dist/hooks-react.js +340 -0
- package/dist/hooks-react.js.map +1 -0
- package/dist/index.d.ts +2445 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1430 -1
- package/dist/index.js.map +1 -0
- package/dist/patches-fetchEventSource.d.ts +806 -0
- package/dist/patches-fetchEventSource.d.ts.map +1 -0
- package/dist/patches-fetchEventSource.js +315 -0
- package/dist/patches-fetchEventSource.js.map +1 -0
- package/dist/vite.d.ts +13 -0
- package/dist/vite.d.ts.map +1 -0
- package/dist/vite.js +23 -0
- package/dist/vite.js.map +1 -0
- package/dist/zod.d.ts +105 -0
- package/dist/zod.d.ts.map +1 -0
- package/dist/zod.js +138 -0
- package/dist/zod.js.map +1 -0
- package/metadata.json +160 -0
- package/package.json +51 -35
- package/dist/enums/index.js +0 -20
- package/dist/hooks/react/index.js +0 -5
- package/dist/hooks/react/useCreation.js +0 -19
- package/dist/hooks/react/useLatest.js +0 -13
- package/dist/hooks/react/useMount.js +0 -29
- package/dist/hooks/react/useResponsive.js +0 -59
- package/dist/hooks/react/useUnmount.js +0 -18
- package/dist/types/enums/index.d.ts +0 -20
- package/dist/types/hooks/react/index.d.ts +0 -5
- package/dist/types/hooks/react/useCreation.d.ts +0 -10
- package/dist/types/hooks/react/useLatest.d.ts +0 -8
- package/dist/types/hooks/react/useMount.d.ts +0 -11
- package/dist/types/hooks/react/useResponsive.d.ts +0 -16
- package/dist/types/hooks/react/useUnmount.d.ts +0 -7
- package/dist/types/index.d.ts +0 -1
- package/dist/types/utils/array.d.ts +0 -76
- package/dist/types/utils/clone.d.ts +0 -13
- package/dist/types/utils/index.d.ts +0 -7
- package/dist/types/utils/object.d.ts +0 -54
- package/dist/types/utils/string.d.ts +0 -15
- package/dist/types/utils/to.d.ts +0 -5
- package/dist/types/utils/tree/index.d.ts +0 -6
- package/dist/types/utils/tree/rowsToTree.d.ts +0 -10
- package/dist/types/utils/tree/treeFilter.d.ts +0 -6
- package/dist/types/utils/tree/treeFind.d.ts +0 -8
- package/dist/types/utils/tree/treeForEach.d.ts +0 -5
- package/dist/types/utils/tree/treeMap.d.ts +0 -6
- package/dist/types/utils/tree/treeToRows.d.ts +0 -9
- package/dist/types/utils/tree/types.d.ts +0 -24
- package/dist/types/utils/typeof.d.ts +0 -37
- package/dist/types/zod/index.d.ts +0 -3
- package/dist/types/zod/primitive.d.ts +0 -32
- package/dist/types/zod/validator/input.d.ts +0 -27
- package/dist/types/zod/validator/societal.d.ts +0 -39
- package/dist/utils/array.js +0 -196
- package/dist/utils/clone.js +0 -75
- package/dist/utils/index.js +0 -7
- package/dist/utils/object.js +0 -149
- package/dist/utils/string.js +0 -73
- package/dist/utils/to.js +0 -16
- package/dist/utils/tree/index.js +0 -6
- package/dist/utils/tree/rowsToTree.js +0 -35
- package/dist/utils/tree/treeFilter.js +0 -92
- package/dist/utils/tree/treeFind.js +0 -82
- package/dist/utils/tree/treeForEach.js +0 -60
- package/dist/utils/tree/treeMap.js +0 -79
- package/dist/utils/tree/treeToRows.js +0 -13
- package/dist/utils/tree/types.js +0 -10
- package/dist/utils/typeof.js +0 -149
- package/dist/zod/index.js +0 -3
- package/dist/zod/primitive.js +0 -32
- package/dist/zod/validator/input.js +0 -39
- package/dist/zod/validator/societal.js +0 -57
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,2445 @@
|
|
|
1
|
+
import { BigNumber, MathExpression, MathJsInstance, Matrix } from "mathjs";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/array/arrayCast.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 构造数组
|
|
7
|
+
* @param candidate 待构造项
|
|
8
|
+
* @param checkEmpty 是否检查 `undefined` 和 `null`
|
|
9
|
+
*/
|
|
10
|
+
declare function arrayCast<T>(candidate: T | T[], checkEmpty?: boolean): T[];
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/utils/array/arrayCompete.d.ts
|
|
13
|
+
/**
|
|
14
|
+
* 数组竞争
|
|
15
|
+
* - 返回在匹配函数的比较条件中获胜的最终项目,适用于更复杂的最小值/最大值计算
|
|
16
|
+
*
|
|
17
|
+
* @param initialList 数组
|
|
18
|
+
* @param match 匹配函数
|
|
19
|
+
*/
|
|
20
|
+
declare function arrayCompete<T>(initialList: readonly T[], match: (a: T, b: T) => T): T | null;
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region src/utils/array/arrayCounting.d.ts
|
|
23
|
+
/**
|
|
24
|
+
* 统计数组的项目出现次数
|
|
25
|
+
* - 通过给定的标识符匹配函数,返回一个对象,其中键是回调函数返回的 key 值,每个值是一个整数,表示该 key 出现的次数
|
|
26
|
+
*
|
|
27
|
+
* @param initialList 初始数组
|
|
28
|
+
* @param match 匹配函数
|
|
29
|
+
*/
|
|
30
|
+
declare function arrayCounting<T, K$1 extends PropertyKey>(initialList: readonly T[], match: (row: T) => K$1): Record<string, number>;
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/utils/array/arrayDifference.d.ts
|
|
33
|
+
/**
|
|
34
|
+
* 求数组差集
|
|
35
|
+
*
|
|
36
|
+
* @param initialList 初始数组
|
|
37
|
+
* @param diffList 对比数组
|
|
38
|
+
* @param match 匹配函数
|
|
39
|
+
*/
|
|
40
|
+
declare function arrayDifference<T>(initialList: readonly T[], diffList: readonly T[], match?: (row: T) => unknown): T[];
|
|
41
|
+
//#endregion
|
|
42
|
+
//#region src/utils/array/arrayFirst.d.ts
|
|
43
|
+
/**
|
|
44
|
+
* 获取数组第一项
|
|
45
|
+
*
|
|
46
|
+
* @param initialList 初始数组
|
|
47
|
+
* @param saveValue 安全值
|
|
48
|
+
*/
|
|
49
|
+
declare function arrayFirst<T>(initialList: readonly T[]): T | undefined;
|
|
50
|
+
declare function arrayFirst<T>(initialList: readonly T[], saveValue: T): T;
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/utils/array/arrayFork.d.ts
|
|
53
|
+
/**
|
|
54
|
+
* 数组分组过滤
|
|
55
|
+
* - 给定一个数组和一个条件,返回一个由两个数组组成的元组,其中第一个数组包含所有满足条件的项,第二个数组包含所有不满足条件的项
|
|
56
|
+
*
|
|
57
|
+
* @param initialList 初始数组
|
|
58
|
+
* @param match 条件匹配函数
|
|
59
|
+
*/
|
|
60
|
+
declare function arrayFork<T>(initialList: readonly T[], match: (item: T) => boolean): [T[], T[]];
|
|
61
|
+
//#endregion
|
|
62
|
+
//#region src/utils/array/arrayIntersection.d.ts
|
|
63
|
+
/**
|
|
64
|
+
* 求数组交集
|
|
65
|
+
*
|
|
66
|
+
* @param initialList 初始数组
|
|
67
|
+
* @param diffList 对比数组
|
|
68
|
+
* @param match 匹配函数
|
|
69
|
+
*/
|
|
70
|
+
declare function arrayIntersection<T>(initialList: readonly T[], diffList: readonly T[], match?: (row: T) => unknown): T[];
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/utils/array/arrayLast.d.ts
|
|
73
|
+
/**
|
|
74
|
+
* 获取数组最后一项
|
|
75
|
+
*
|
|
76
|
+
* @param initialList 初始数组
|
|
77
|
+
* @param saveValue 安全值
|
|
78
|
+
*/
|
|
79
|
+
declare function arrayLast<T>(initialList: readonly T[]): T | undefined;
|
|
80
|
+
declare function arrayLast<T>(initialList: readonly T[], saveValue: T): T;
|
|
81
|
+
//#endregion
|
|
82
|
+
//#region src/utils/array/arrayMerge.d.ts
|
|
83
|
+
/**
|
|
84
|
+
* 数组合并
|
|
85
|
+
* - 通过给定的标识符匹配函数,用第二个数组中的匹配项替换第一个数组中匹配项的所有内容
|
|
86
|
+
*
|
|
87
|
+
* @param initialList 初始数组
|
|
88
|
+
* @param mergeList 待合并数组
|
|
89
|
+
* @param match 匹配函数
|
|
90
|
+
*/
|
|
91
|
+
declare function arrayMerge<T>(initialList: readonly T[], mergeList: readonly T[], match?: (item: T) => unknown): T[];
|
|
92
|
+
//#endregion
|
|
93
|
+
//#region src/utils/array/arrayPick.d.ts
|
|
94
|
+
/**
|
|
95
|
+
* 数组选择
|
|
96
|
+
* - 一次性应用 `filter` 和 `map` 操作
|
|
97
|
+
*
|
|
98
|
+
* @param initialList 初始数组
|
|
99
|
+
* @param filter filter 函数
|
|
100
|
+
* @param mapper map 函数
|
|
101
|
+
*/
|
|
102
|
+
declare function arrayPick<T, K$1 = T>(initialList: readonly T[], filter: (row: T, index: number) => boolean, mapper?: ((row: T, index: number) => K$1) | undefined): T[] | K$1[];
|
|
103
|
+
//#endregion
|
|
104
|
+
//#region src/utils/array/arrayReplace.d.ts
|
|
105
|
+
/**
|
|
106
|
+
* 数组项替换
|
|
107
|
+
* - 在给定的数组中,替换符合匹配函数结果的项目。只替换第一个匹配项。始终返回原始数组的副本。
|
|
108
|
+
*
|
|
109
|
+
* @param initialList 初始数组
|
|
110
|
+
* @param newItem 替换项
|
|
111
|
+
* @param match 匹配函数
|
|
112
|
+
*/
|
|
113
|
+
declare function arrayReplace<T>(initialList: readonly T[], newItem: T, match: (row: T, index: number) => boolean): T[];
|
|
114
|
+
//#endregion
|
|
115
|
+
//#region src/utils/array/arraySplit.d.ts
|
|
116
|
+
/**
|
|
117
|
+
* 数组切分
|
|
118
|
+
* - 将数组以指定的长度切分后,组合在高维数组中
|
|
119
|
+
*
|
|
120
|
+
* @param initialList 初始数组
|
|
121
|
+
* @param size 分割尺寸,默认 `10`
|
|
122
|
+
*/
|
|
123
|
+
declare function arraySplit<T>(initialList: readonly T[], size?: number): T[][];
|
|
124
|
+
//#endregion
|
|
125
|
+
//#region src/utils/function/to.d.ts
|
|
126
|
+
/**
|
|
127
|
+
* @param promise
|
|
128
|
+
* @param errorExt 可以传递给err对象的其他信息
|
|
129
|
+
*/
|
|
130
|
+
declare function to<T, U$1 = Error>(promise: Readonly<Promise<T>>, errorExt?: PlainObject): Promise<[U$1, undefined] | [null, T]>;
|
|
131
|
+
//#endregion
|
|
132
|
+
//#region src/utils/math/toMathBignumber.d.ts
|
|
133
|
+
/**
|
|
134
|
+
* 将任意类型的值转换为 `math.bignumber`
|
|
135
|
+
*
|
|
136
|
+
* @param mathJsInstance mathJs 实例
|
|
137
|
+
* @param value 任意类型的值
|
|
138
|
+
* @param saveValue 安全值
|
|
139
|
+
*/
|
|
140
|
+
declare function toMathBignumber(mathJsInstance: MathJsInstance, value: unknown, saveValue?: BigNumber | undefined): BigNumber;
|
|
141
|
+
//#endregion
|
|
142
|
+
//#region src/utils/math/toMathDecimal.d.ts
|
|
143
|
+
/**
|
|
144
|
+
* 将任意类型的值转换为十进制数字字符串
|
|
145
|
+
*
|
|
146
|
+
* @param mathJsInstance mathJs 实例
|
|
147
|
+
* @param value 任意类型的值
|
|
148
|
+
* @param precision 精度
|
|
149
|
+
* @param isFormat 是否格式化为字符串
|
|
150
|
+
*/
|
|
151
|
+
declare function toMathDecimal(mathJsInstance: MathJsInstance, value: unknown, precision?: number | undefined, isFormat?: true): string;
|
|
152
|
+
declare function toMathDecimal(mathJsInstance: MathJsInstance, value: unknown, precision?: number | undefined, isFormat?: false): BigNumber;
|
|
153
|
+
//#endregion
|
|
154
|
+
//#region src/utils/math/toMathEvaluate.d.ts
|
|
155
|
+
/**
|
|
156
|
+
* 数学表达式求值
|
|
157
|
+
*
|
|
158
|
+
* @param mathJsInstance mathJs 实例
|
|
159
|
+
* @param expr 表达式
|
|
160
|
+
* @param scope 键值映射
|
|
161
|
+
*/
|
|
162
|
+
declare function toMathEvaluate(mathJsInstance: MathJsInstance, expr: MathExpression | Matrix, scope?: Record<string, BigNumber>): string;
|
|
163
|
+
//#endregion
|
|
164
|
+
//#region src/utils/object/cloneDeep.d.ts
|
|
165
|
+
interface CloningStrategy {
|
|
166
|
+
cloneMap: <K$1, V>(parent: Map<K$1, V>, track: (newParent: Map<K$1, V>) => Map<K$1, V>, clone: <T>(value: T) => T) => Map<K$1, V> | null;
|
|
167
|
+
cloneSet: <T>(parent: Set<T>, track: (newParent: Set<T>) => Set<T>, clone: <T>(value: T) => T) => Set<T> | null;
|
|
168
|
+
cloneArray: <T>(parent: readonly T[], track: (newParent: T[]) => T[], clone: <T>(value: T) => T) => T[] | null;
|
|
169
|
+
cloneObject: <T extends AnyObject>(parent: T, track: (newParent: T) => T, clone: <T>(value: T) => T) => T | null;
|
|
170
|
+
cloneOther: <T>(parent: T, track: (newParent: T) => T, clone: <T>(value: T) => T) => T | null;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* cloneDeep
|
|
174
|
+
* @reference https://github.com/radashi-org/radashi/blob/main/src/object/cloneDeep.ts
|
|
175
|
+
*/
|
|
176
|
+
declare function cloneDeep<T extends AnyObject>(root: T, customStrategy?: Partial<CloningStrategy>): T;
|
|
177
|
+
//#endregion
|
|
178
|
+
//#region node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/basic.d.ts
|
|
179
|
+
/**
|
|
180
|
+
Matches a [`class`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes).
|
|
181
|
+
|
|
182
|
+
@category Class
|
|
183
|
+
*/
|
|
184
|
+
type Class<T, Arguments extends unknown[] = any[]> = {
|
|
185
|
+
prototype: Pick<T, keyof T>;
|
|
186
|
+
new (...arguments_: Arguments): T;
|
|
187
|
+
};
|
|
188
|
+
//#endregion
|
|
189
|
+
//#region node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/union-to-intersection.d.ts
|
|
190
|
+
/**
|
|
191
|
+
Convert a union type to an intersection type using [distributive conditional types](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types).
|
|
192
|
+
|
|
193
|
+
Inspired by [this Stack Overflow answer](https://stackoverflow.com/a/50375286/2172153).
|
|
194
|
+
|
|
195
|
+
@example
|
|
196
|
+
```
|
|
197
|
+
import type {UnionToIntersection} from 'type-fest';
|
|
198
|
+
|
|
199
|
+
type Union = {the(): void} | {great(arg: string): void} | {escape: boolean};
|
|
200
|
+
|
|
201
|
+
type Intersection = UnionToIntersection<Union>;
|
|
202
|
+
//=> {the(): void; great(arg: string): void; escape: boolean};
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
@category Type
|
|
206
|
+
*/
|
|
207
|
+
type UnionToIntersection<Union> = (
|
|
208
|
+
// `extends unknown` is always going to be the case and is used to convert the
|
|
209
|
+
// `Union` into a [distributive conditional
|
|
210
|
+
// type](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types).
|
|
211
|
+
Union extends unknown
|
|
212
|
+
// The union type is used as the only argument to a function since the union
|
|
213
|
+
// of function arguments is an intersection.
|
|
214
|
+
? (distributedUnion: Union) => void
|
|
215
|
+
// This won't happen.
|
|
216
|
+
: never
|
|
217
|
+
// Infer the `Intersection` type since TypeScript represents the positional
|
|
218
|
+
// arguments of unions of functions as an intersection of the union.
|
|
219
|
+
) extends ((mergedIntersection: infer Intersection) => void)
|
|
220
|
+
// The `& Union` is to ensure result of `UnionToIntersection<A | B>` is always assignable to `A | B`
|
|
221
|
+
? Intersection & Union : never;
|
|
222
|
+
//#endregion
|
|
223
|
+
//#region node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/keys-of-union.d.ts
|
|
224
|
+
/**
|
|
225
|
+
Create a union of all keys from a given type, even those exclusive to specific union members.
|
|
226
|
+
|
|
227
|
+
Unlike the native `keyof` keyword, which returns keys present in **all** union members, this type returns keys from **any** member.
|
|
228
|
+
|
|
229
|
+
@link https://stackoverflow.com/a/49402091
|
|
230
|
+
|
|
231
|
+
@example
|
|
232
|
+
```
|
|
233
|
+
import type {KeysOfUnion} from 'type-fest';
|
|
234
|
+
|
|
235
|
+
type A = {
|
|
236
|
+
common: string;
|
|
237
|
+
a: number;
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
type B = {
|
|
241
|
+
common: string;
|
|
242
|
+
b: string;
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
type C = {
|
|
246
|
+
common: string;
|
|
247
|
+
c: boolean;
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
type Union = A | B | C;
|
|
251
|
+
|
|
252
|
+
type CommonKeys = keyof Union;
|
|
253
|
+
//=> 'common'
|
|
254
|
+
|
|
255
|
+
type AllKeys = KeysOfUnion<Union>;
|
|
256
|
+
//=> 'common' | 'a' | 'b' | 'c'
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
@category Object
|
|
260
|
+
*/
|
|
261
|
+
type KeysOfUnion<ObjectType> =
|
|
262
|
+
// Hack to fix https://github.com/sindresorhus/type-fest/issues/1008
|
|
263
|
+
keyof UnionToIntersection<ObjectType extends unknown ? Record<keyof ObjectType, never> : never>;
|
|
264
|
+
//#endregion
|
|
265
|
+
//#region node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/is-any.d.ts
|
|
266
|
+
/**
|
|
267
|
+
Returns a boolean for whether the given type is `any`.
|
|
268
|
+
|
|
269
|
+
@link https://stackoverflow.com/a/49928360/1490091
|
|
270
|
+
|
|
271
|
+
Useful in type utilities, such as disallowing `any`s to be passed to a function.
|
|
272
|
+
|
|
273
|
+
@example
|
|
274
|
+
```
|
|
275
|
+
import type {IsAny} from 'type-fest';
|
|
276
|
+
|
|
277
|
+
const typedObject = {a: 1, b: 2} as const;
|
|
278
|
+
const anyObject: any = {a: 1, b: 2};
|
|
279
|
+
|
|
280
|
+
function get<O extends (IsAny<O> extends true ? {} : Record<string, number>), K extends keyof O = keyof O>(object: O, key: K) {
|
|
281
|
+
return object[key];
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
const typedA = get(typedObject, 'a');
|
|
285
|
+
//=> 1
|
|
286
|
+
|
|
287
|
+
const anyA = get(anyObject, 'a');
|
|
288
|
+
//=> any
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
@category Type Guard
|
|
292
|
+
@category Utilities
|
|
293
|
+
*/
|
|
294
|
+
type IsAny<T> = 0 extends 1 & NoInfer<T> ? true : false;
|
|
295
|
+
//#endregion
|
|
296
|
+
//#region node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/is-optional-key-of.d.ts
|
|
297
|
+
/**
|
|
298
|
+
Returns a boolean for whether the given key is an optional key of type.
|
|
299
|
+
|
|
300
|
+
This is useful when writing utility types or schema validators that need to differentiate `optional` keys.
|
|
301
|
+
|
|
302
|
+
@example
|
|
303
|
+
```
|
|
304
|
+
import type {IsOptionalKeyOf} from 'type-fest';
|
|
305
|
+
|
|
306
|
+
type User = {
|
|
307
|
+
name: string;
|
|
308
|
+
surname: string;
|
|
309
|
+
|
|
310
|
+
luckyNumber?: number;
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
type Admin = {
|
|
314
|
+
name: string;
|
|
315
|
+
surname?: string;
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
type T1 = IsOptionalKeyOf<User, 'luckyNumber'>;
|
|
319
|
+
//=> true
|
|
320
|
+
|
|
321
|
+
type T2 = IsOptionalKeyOf<User, 'name'>;
|
|
322
|
+
//=> false
|
|
323
|
+
|
|
324
|
+
type T3 = IsOptionalKeyOf<User, 'name' | 'luckyNumber'>;
|
|
325
|
+
//=> boolean
|
|
326
|
+
|
|
327
|
+
type T4 = IsOptionalKeyOf<User | Admin, 'name'>;
|
|
328
|
+
//=> false
|
|
329
|
+
|
|
330
|
+
type T5 = IsOptionalKeyOf<User | Admin, 'surname'>;
|
|
331
|
+
//=> boolean
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
@category Type Guard
|
|
335
|
+
@category Utilities
|
|
336
|
+
*/
|
|
337
|
+
type IsOptionalKeyOf<Type extends object, Key$1 extends keyof Type> = IsAny<Type | Key$1> extends true ? never : Key$1 extends keyof Type ? Type extends Record<Key$1, Type[Key$1]> ? false : true : false;
|
|
338
|
+
//#endregion
|
|
339
|
+
//#region node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/optional-keys-of.d.ts
|
|
340
|
+
/**
|
|
341
|
+
Extract all optional keys from the given type.
|
|
342
|
+
|
|
343
|
+
This is useful when you want to create a new type that contains different type values for the optional keys only.
|
|
344
|
+
|
|
345
|
+
@example
|
|
346
|
+
```
|
|
347
|
+
import type {OptionalKeysOf, Except} from 'type-fest';
|
|
348
|
+
|
|
349
|
+
type User = {
|
|
350
|
+
name: string;
|
|
351
|
+
surname: string;
|
|
352
|
+
|
|
353
|
+
luckyNumber?: number;
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
const REMOVE_FIELD = Symbol('remove field symbol');
|
|
357
|
+
type UpdateOperation<Entity extends object> = Except<Partial<Entity>, OptionalKeysOf<Entity>> & {
|
|
358
|
+
[Key in OptionalKeysOf<Entity>]?: Entity[Key] | typeof REMOVE_FIELD;
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
const update1: UpdateOperation<User> = {
|
|
362
|
+
name: 'Alice',
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
const update2: UpdateOperation<User> = {
|
|
366
|
+
name: 'Bob',
|
|
367
|
+
luckyNumber: REMOVE_FIELD,
|
|
368
|
+
};
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
@category Utilities
|
|
372
|
+
*/
|
|
373
|
+
type OptionalKeysOf<Type extends object> = Type extends unknown // For distributing `Type`
|
|
374
|
+
? (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`
|
|
375
|
+
: never;
|
|
376
|
+
//#endregion
|
|
377
|
+
//#region node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/required-keys-of.d.ts
|
|
378
|
+
/**
|
|
379
|
+
Extract all required keys from the given type.
|
|
380
|
+
|
|
381
|
+
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...
|
|
382
|
+
|
|
383
|
+
@example
|
|
384
|
+
```
|
|
385
|
+
import type {RequiredKeysOf} from 'type-fest';
|
|
386
|
+
|
|
387
|
+
declare function createValidation<
|
|
388
|
+
Entity extends object,
|
|
389
|
+
Key extends RequiredKeysOf<Entity> = RequiredKeysOf<Entity>,
|
|
390
|
+
>(field: Key, validator: (value: Entity[Key]) => boolean): (entity: Entity) => boolean;
|
|
391
|
+
|
|
392
|
+
type User = {
|
|
393
|
+
name: string;
|
|
394
|
+
surname: string;
|
|
395
|
+
luckyNumber?: number;
|
|
396
|
+
};
|
|
397
|
+
|
|
398
|
+
const validator1 = createValidation<User>('name', value => value.length < 25);
|
|
399
|
+
const validator2 = createValidation<User>('surname', value => value.length < 25);
|
|
400
|
+
|
|
401
|
+
// @ts-expect-error
|
|
402
|
+
const validator3 = createValidation<User>('luckyNumber', value => value > 0);
|
|
403
|
+
// Error: Argument of type '"luckyNumber"' is not assignable to parameter of type '"name" | "surname"'.
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
@category Utilities
|
|
407
|
+
*/
|
|
408
|
+
type RequiredKeysOf<Type extends object> = Type extends unknown // For distributing `Type`
|
|
409
|
+
? Exclude<keyof Type, OptionalKeysOf<Type>> : never;
|
|
410
|
+
//#endregion
|
|
411
|
+
//#region node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/has-required-keys.d.ts
|
|
412
|
+
/**
|
|
413
|
+
Creates a type that represents `true` or `false` depending on whether the given type has any required fields.
|
|
414
|
+
|
|
415
|
+
This is useful when you want to create an API whose behavior depends on the presence or absence of required fields.
|
|
416
|
+
|
|
417
|
+
@example
|
|
418
|
+
```
|
|
419
|
+
import type {HasRequiredKeys} from 'type-fest';
|
|
420
|
+
|
|
421
|
+
type GeneratorOptions<Template extends object> = {
|
|
422
|
+
prop1: number;
|
|
423
|
+
prop2: string;
|
|
424
|
+
} & (HasRequiredKeys<Template> extends true
|
|
425
|
+
? {template: Template}
|
|
426
|
+
: {template?: Template});
|
|
427
|
+
|
|
428
|
+
type Template1 = {
|
|
429
|
+
optionalSubParam?: string;
|
|
430
|
+
};
|
|
431
|
+
|
|
432
|
+
type Template2 = {
|
|
433
|
+
requiredSubParam: string;
|
|
434
|
+
};
|
|
435
|
+
|
|
436
|
+
type Options1 = GeneratorOptions<Template1>;
|
|
437
|
+
type Options2 = GeneratorOptions<Template2>;
|
|
438
|
+
|
|
439
|
+
const optA: Options1 = {
|
|
440
|
+
prop1: 0,
|
|
441
|
+
prop2: 'hi',
|
|
442
|
+
};
|
|
443
|
+
const optB: Options1 = {
|
|
444
|
+
prop1: 0,
|
|
445
|
+
prop2: 'hi',
|
|
446
|
+
template: {},
|
|
447
|
+
};
|
|
448
|
+
const optC: Options1 = {
|
|
449
|
+
prop1: 0,
|
|
450
|
+
prop2: 'hi',
|
|
451
|
+
template: {
|
|
452
|
+
optionalSubParam: 'optional value',
|
|
453
|
+
},
|
|
454
|
+
};
|
|
455
|
+
|
|
456
|
+
const optD: Options2 = {
|
|
457
|
+
prop1: 0,
|
|
458
|
+
prop2: 'hi',
|
|
459
|
+
template: {
|
|
460
|
+
requiredSubParam: 'required value',
|
|
461
|
+
},
|
|
462
|
+
};
|
|
463
|
+
|
|
464
|
+
```
|
|
465
|
+
|
|
466
|
+
@category Utilities
|
|
467
|
+
*/
|
|
468
|
+
type HasRequiredKeys<BaseType extends object> = RequiredKeysOf<BaseType> extends never ? false : true;
|
|
469
|
+
//#endregion
|
|
470
|
+
//#region node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/is-never.d.ts
|
|
471
|
+
/**
|
|
472
|
+
Returns a boolean for whether the given type is `never`.
|
|
473
|
+
|
|
474
|
+
@link https://github.com/microsoft/TypeScript/issues/31751#issuecomment-498526919
|
|
475
|
+
@link https://stackoverflow.com/a/53984913/10292952
|
|
476
|
+
@link https://www.zhenghao.io/posts/ts-never
|
|
477
|
+
|
|
478
|
+
Useful in type utilities, such as checking if something does not occur.
|
|
479
|
+
|
|
480
|
+
@example
|
|
481
|
+
```
|
|
482
|
+
import type {IsNever, And} from 'type-fest';
|
|
483
|
+
|
|
484
|
+
type A = IsNever<never>;
|
|
485
|
+
//=> true
|
|
486
|
+
|
|
487
|
+
type B = IsNever<any>;
|
|
488
|
+
//=> false
|
|
489
|
+
|
|
490
|
+
type C = IsNever<unknown>;
|
|
491
|
+
//=> false
|
|
492
|
+
|
|
493
|
+
type D = IsNever<never[]>;
|
|
494
|
+
//=> false
|
|
495
|
+
|
|
496
|
+
type E = IsNever<object>;
|
|
497
|
+
//=> false
|
|
498
|
+
|
|
499
|
+
type F = IsNever<string>;
|
|
500
|
+
//=> false
|
|
501
|
+
```
|
|
502
|
+
|
|
503
|
+
@example
|
|
504
|
+
```
|
|
505
|
+
import type {IsNever} from 'type-fest';
|
|
506
|
+
|
|
507
|
+
type IsTrue<T> = T extends true ? true : false;
|
|
508
|
+
|
|
509
|
+
// When a distributive conditional is instantiated with `never`, the entire conditional results in `never`.
|
|
510
|
+
type A = IsTrue<never>;
|
|
511
|
+
// ^? type A = never
|
|
512
|
+
|
|
513
|
+
// If you don't want that behaviour, you can explicitly add an `IsNever` check before the distributive conditional.
|
|
514
|
+
type IsTrueFixed<T> =
|
|
515
|
+
IsNever<T> extends true ? false : T extends true ? true : false;
|
|
516
|
+
|
|
517
|
+
type B = IsTrueFixed<never>;
|
|
518
|
+
// ^? type B = false
|
|
519
|
+
```
|
|
520
|
+
|
|
521
|
+
@category Type Guard
|
|
522
|
+
@category Utilities
|
|
523
|
+
*/
|
|
524
|
+
type IsNever<T> = [T] extends [never] ? true : false;
|
|
525
|
+
//#endregion
|
|
526
|
+
//#region node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/if.d.ts
|
|
527
|
+
/**
|
|
528
|
+
An if-else-like type that resolves depending on whether the given `boolean` type is `true` or `false`.
|
|
529
|
+
|
|
530
|
+
Use-cases:
|
|
531
|
+
- 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'>`.
|
|
532
|
+
|
|
533
|
+
Note:
|
|
534
|
+
- 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'`.
|
|
535
|
+
- Returns the else branch if the given type is `never`. For example, `If<never, 'Y', 'N'>` will return `'N'`.
|
|
536
|
+
|
|
537
|
+
@example
|
|
538
|
+
```
|
|
539
|
+
import type {If} from 'type-fest';
|
|
540
|
+
|
|
541
|
+
type A = If<true, 'yes', 'no'>;
|
|
542
|
+
//=> 'yes'
|
|
543
|
+
|
|
544
|
+
type B = If<false, 'yes', 'no'>;
|
|
545
|
+
//=> 'no'
|
|
546
|
+
|
|
547
|
+
type C = If<boolean, 'yes', 'no'>;
|
|
548
|
+
//=> 'yes' | 'no'
|
|
549
|
+
|
|
550
|
+
type D = If<any, 'yes', 'no'>;
|
|
551
|
+
//=> 'yes' | 'no'
|
|
552
|
+
|
|
553
|
+
type E = If<never, 'yes', 'no'>;
|
|
554
|
+
//=> 'no'
|
|
555
|
+
```
|
|
556
|
+
|
|
557
|
+
@example
|
|
558
|
+
```
|
|
559
|
+
import type {If, IsAny, IsNever} from 'type-fest';
|
|
560
|
+
|
|
561
|
+
type A = If<IsAny<unknown>, 'is any', 'not any'>;
|
|
562
|
+
//=> 'not any'
|
|
563
|
+
|
|
564
|
+
type B = If<IsNever<never>, 'is never', 'not never'>;
|
|
565
|
+
//=> 'is never'
|
|
566
|
+
```
|
|
567
|
+
|
|
568
|
+
@example
|
|
569
|
+
```
|
|
570
|
+
import type {If, IsEqual} from 'type-fest';
|
|
571
|
+
|
|
572
|
+
type IfEqual<T, U, IfBranch, ElseBranch> = If<IsEqual<T, U>, IfBranch, ElseBranch>;
|
|
573
|
+
|
|
574
|
+
type A = IfEqual<string, string, 'equal', 'not equal'>;
|
|
575
|
+
//=> 'equal'
|
|
576
|
+
|
|
577
|
+
type B = IfEqual<string, number, 'equal', 'not equal'>;
|
|
578
|
+
//=> 'not equal'
|
|
579
|
+
```
|
|
580
|
+
|
|
581
|
+
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:
|
|
582
|
+
|
|
583
|
+
@example
|
|
584
|
+
```
|
|
585
|
+
import type {If, IsEqual, StringRepeat} from 'type-fest';
|
|
586
|
+
|
|
587
|
+
type HundredZeroes = StringRepeat<'0', 100>;
|
|
588
|
+
|
|
589
|
+
// The following implementation is not tail recursive
|
|
590
|
+
type Includes<S extends string, Char extends string> =
|
|
591
|
+
S extends `${infer First}${infer Rest}`
|
|
592
|
+
? If<IsEqual<First, Char>,
|
|
593
|
+
'found',
|
|
594
|
+
Includes<Rest, Char>>
|
|
595
|
+
: 'not found';
|
|
596
|
+
|
|
597
|
+
// Hence, instantiations with long strings will fail
|
|
598
|
+
// @ts-expect-error
|
|
599
|
+
type Fails = Includes<HundredZeroes, '1'>;
|
|
600
|
+
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
601
|
+
// Error: Type instantiation is excessively deep and possibly infinite.
|
|
602
|
+
|
|
603
|
+
// However, if we use a simple conditional instead of `If`, the implementation becomes tail-recursive
|
|
604
|
+
type IncludesWithoutIf<S extends string, Char extends string> =
|
|
605
|
+
S extends `${infer First}${infer Rest}`
|
|
606
|
+
? IsEqual<First, Char> extends true
|
|
607
|
+
? 'found'
|
|
608
|
+
: IncludesWithoutIf<Rest, Char>
|
|
609
|
+
: 'not found';
|
|
610
|
+
|
|
611
|
+
// Now, instantiations with long strings will work
|
|
612
|
+
type Works = IncludesWithoutIf<HundredZeroes, '1'>;
|
|
613
|
+
//=> 'not found'
|
|
614
|
+
```
|
|
615
|
+
|
|
616
|
+
@category Type Guard
|
|
617
|
+
@category Utilities
|
|
618
|
+
*/
|
|
619
|
+
type If<Type extends boolean, IfBranch, ElseBranch> = IsNever<Type> extends true ? ElseBranch : Type extends true ? IfBranch : ElseBranch;
|
|
620
|
+
//#endregion
|
|
621
|
+
//#region node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/internal/type.d.ts
|
|
622
|
+
/**
|
|
623
|
+
An if-else-like type that resolves depending on whether the given type is `any` or `never`.
|
|
624
|
+
|
|
625
|
+
@example
|
|
626
|
+
```
|
|
627
|
+
// When `T` is a NOT `any` or `never` (like `string`) => Returns `IfNotAnyOrNever` branch
|
|
628
|
+
type A = IfNotAnyOrNever<string, 'VALID', 'IS_ANY', 'IS_NEVER'>;
|
|
629
|
+
//=> 'VALID'
|
|
630
|
+
|
|
631
|
+
// When `T` is `any` => Returns `IfAny` branch
|
|
632
|
+
type B = IfNotAnyOrNever<any, 'VALID', 'IS_ANY', 'IS_NEVER'>;
|
|
633
|
+
//=> 'IS_ANY'
|
|
634
|
+
|
|
635
|
+
// When `T` is `never` => Returns `IfNever` branch
|
|
636
|
+
type C = IfNotAnyOrNever<never, 'VALID', 'IS_ANY', 'IS_NEVER'>;
|
|
637
|
+
//=> 'IS_NEVER'
|
|
638
|
+
```
|
|
639
|
+
|
|
640
|
+
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:
|
|
641
|
+
|
|
642
|
+
@example
|
|
643
|
+
```ts
|
|
644
|
+
import type {StringRepeat} from 'type-fest';
|
|
645
|
+
|
|
646
|
+
type NineHundredNinetyNineSpaces = StringRepeat<' ', 999>;
|
|
647
|
+
|
|
648
|
+
// The following implementation is not tail recursive
|
|
649
|
+
type TrimLeft<S extends string> = IfNotAnyOrNever<S, S extends ` ${infer R}` ? TrimLeft<R> : S>;
|
|
650
|
+
|
|
651
|
+
// Hence, instantiations with long strings will fail
|
|
652
|
+
// @ts-expect-error
|
|
653
|
+
type T1 = TrimLeft<NineHundredNinetyNineSpaces>;
|
|
654
|
+
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
655
|
+
// Error: Type instantiation is excessively deep and possibly infinite.
|
|
656
|
+
|
|
657
|
+
// To fix this, move the recursion into a helper type
|
|
658
|
+
type TrimLeftOptimised<S extends string> = IfNotAnyOrNever<S, _TrimLeftOptimised<S>>;
|
|
659
|
+
|
|
660
|
+
type _TrimLeftOptimised<S extends string> = S extends ` ${infer R}` ? _TrimLeftOptimised<R> : S;
|
|
661
|
+
|
|
662
|
+
type T2 = TrimLeftOptimised<NineHundredNinetyNineSpaces>;
|
|
663
|
+
//=> ''
|
|
664
|
+
```
|
|
665
|
+
*/
|
|
666
|
+
type IfNotAnyOrNever<T, IfNotAnyOrNever$1, IfAny = any, IfNever = never> = If<IsAny<T>, IfAny, If<IsNever<T>, IfNever, IfNotAnyOrNever$1>>;
|
|
667
|
+
//#endregion
|
|
668
|
+
//#region node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/simplify.d.ts
|
|
669
|
+
/**
|
|
670
|
+
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.
|
|
671
|
+
|
|
672
|
+
@example
|
|
673
|
+
```
|
|
674
|
+
import type {Simplify} from 'type-fest';
|
|
675
|
+
|
|
676
|
+
type PositionProps = {
|
|
677
|
+
top: number;
|
|
678
|
+
left: number;
|
|
679
|
+
};
|
|
680
|
+
|
|
681
|
+
type SizeProps = {
|
|
682
|
+
width: number;
|
|
683
|
+
height: number;
|
|
684
|
+
};
|
|
685
|
+
|
|
686
|
+
// In your editor, hovering over `Props` will show a flattened object with all the properties.
|
|
687
|
+
type Props = Simplify<PositionProps & SizeProps>;
|
|
688
|
+
```
|
|
689
|
+
|
|
690
|
+
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.
|
|
691
|
+
|
|
692
|
+
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`.
|
|
693
|
+
|
|
694
|
+
@example
|
|
695
|
+
```
|
|
696
|
+
import type {Simplify} from 'type-fest';
|
|
697
|
+
|
|
698
|
+
interface SomeInterface {
|
|
699
|
+
foo: number;
|
|
700
|
+
bar?: string;
|
|
701
|
+
baz: number | undefined;
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
type SomeType = {
|
|
705
|
+
foo: number;
|
|
706
|
+
bar?: string;
|
|
707
|
+
baz: number | undefined;
|
|
708
|
+
};
|
|
709
|
+
|
|
710
|
+
const literal = {foo: 123, bar: 'hello', baz: 456};
|
|
711
|
+
const someType: SomeType = literal;
|
|
712
|
+
const someInterface: SomeInterface = literal;
|
|
713
|
+
|
|
714
|
+
declare function fn(object: Record<string, unknown>): void;
|
|
715
|
+
|
|
716
|
+
fn(literal); // Good: literal object type is sealed
|
|
717
|
+
fn(someType); // Good: type is sealed
|
|
718
|
+
// @ts-expect-error
|
|
719
|
+
fn(someInterface); // Error: Index signature for type 'string' is missing in type 'someInterface'. Because `interface` can be re-opened
|
|
720
|
+
fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface` into a `type`
|
|
721
|
+
```
|
|
722
|
+
|
|
723
|
+
@link https://github.com/microsoft/TypeScript/issues/15300
|
|
724
|
+
@see {@link SimplifyDeep}
|
|
725
|
+
@category Object
|
|
726
|
+
*/
|
|
727
|
+
type Simplify<T> = { [KeyType in keyof T]: T[KeyType] } & {};
|
|
728
|
+
//#endregion
|
|
729
|
+
//#region node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/is-equal.d.ts
|
|
730
|
+
/**
|
|
731
|
+
Returns a boolean for whether the two given types are equal.
|
|
732
|
+
|
|
733
|
+
@link https://github.com/microsoft/TypeScript/issues/27024#issuecomment-421529650
|
|
734
|
+
@link https://stackoverflow.com/questions/68961864/how-does-the-equals-work-in-typescript/68963796#68963796
|
|
735
|
+
|
|
736
|
+
Use-cases:
|
|
737
|
+
- If you want to make a conditional branch based on the result of a comparison of two types.
|
|
738
|
+
|
|
739
|
+
@example
|
|
740
|
+
```
|
|
741
|
+
import type {IsEqual} from 'type-fest';
|
|
742
|
+
|
|
743
|
+
// This type returns a boolean for whether the given array includes the given item.
|
|
744
|
+
// `IsEqual` is used to compare the given array at position 0 and the given item and then return true if they are equal.
|
|
745
|
+
type Includes<Value extends readonly any[], Item> =
|
|
746
|
+
Value extends readonly [Value[0], ...infer rest]
|
|
747
|
+
? IsEqual<Value[0], Item> extends true
|
|
748
|
+
? true
|
|
749
|
+
: Includes<rest, Item>
|
|
750
|
+
: false;
|
|
751
|
+
```
|
|
752
|
+
|
|
753
|
+
@category Type Guard
|
|
754
|
+
@category Utilities
|
|
755
|
+
*/
|
|
756
|
+
type IsEqual<A$1, B$1> = [A$1] extends [B$1] ? [B$1] extends [A$1] ? _IsEqual<A$1, B$1> : false : false;
|
|
757
|
+
// This version fails the `equalWrappedTupleIntersectionToBeNeverAndNeverExpanded` test in `test-d/is-equal.ts`.
|
|
758
|
+
type _IsEqual<A$1, B$1> = (<G>() => G extends A$1 & G | G ? 1 : 2) extends (<G>() => G extends B$1 & G | G ? 1 : 2) ? true : false;
|
|
759
|
+
//#endregion
|
|
760
|
+
//#region node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/omit-index-signature.d.ts
|
|
761
|
+
/**
|
|
762
|
+
Omit any index signatures from the given object type, leaving only explicitly defined properties.
|
|
763
|
+
|
|
764
|
+
This is the counterpart of `PickIndexSignature`.
|
|
765
|
+
|
|
766
|
+
Use-cases:
|
|
767
|
+
- Remove overly permissive signatures from third-party types.
|
|
768
|
+
|
|
769
|
+
This type was taken from this [StackOverflow answer](https://stackoverflow.com/a/68261113/420747).
|
|
770
|
+
|
|
771
|
+
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>`.
|
|
772
|
+
|
|
773
|
+
(The actual value type, `unknown`, is irrelevant and could be any type. Only the key type matters.)
|
|
774
|
+
|
|
775
|
+
```
|
|
776
|
+
const indexed: Record<string, unknown> = {}; // Allowed
|
|
777
|
+
|
|
778
|
+
// @ts-expect-error
|
|
779
|
+
const keyed: Record<'foo', unknown> = {}; // Error
|
|
780
|
+
// => TS2739: Type '{}' is missing the following properties from type 'Record<"foo" | "bar", unknown>': foo, bar
|
|
781
|
+
```
|
|
782
|
+
|
|
783
|
+
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:
|
|
784
|
+
|
|
785
|
+
```
|
|
786
|
+
type Indexed = {} extends Record<string, unknown>
|
|
787
|
+
? '✅ `{}` is assignable to `Record<string, unknown>`'
|
|
788
|
+
: '❌ `{}` is NOT assignable to `Record<string, unknown>`';
|
|
789
|
+
// => '✅ `{}` is assignable to `Record<string, unknown>`'
|
|
790
|
+
|
|
791
|
+
type Keyed = {} extends Record<'foo' | 'bar', unknown>
|
|
792
|
+
? '✅ `{}` is assignable to `Record<\'foo\' | \'bar\', unknown>`'
|
|
793
|
+
: '❌ `{}` is NOT assignable to `Record<\'foo\' | \'bar\', unknown>`';
|
|
794
|
+
// => "❌ `{}` is NOT assignable to `Record<'foo' | 'bar', unknown>`"
|
|
795
|
+
```
|
|
796
|
+
|
|
797
|
+
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`...
|
|
798
|
+
|
|
799
|
+
```
|
|
800
|
+
type OmitIndexSignature<ObjectType> = {
|
|
801
|
+
[KeyType in keyof ObjectType // Map each key of `ObjectType`...
|
|
802
|
+
]: ObjectType[KeyType]; // ...to its original value, i.e. `OmitIndexSignature<Foo> == Foo`.
|
|
803
|
+
};
|
|
804
|
+
```
|
|
805
|
+
|
|
806
|
+
...whether an empty object (`{}`) would be assignable to an object with that `KeyType` (`Record<KeyType, unknown>`)...
|
|
807
|
+
|
|
808
|
+
```
|
|
809
|
+
type OmitIndexSignature<ObjectType> = {
|
|
810
|
+
[KeyType in keyof ObjectType
|
|
811
|
+
// Is `{}` assignable to `Record<KeyType, unknown>`?
|
|
812
|
+
as {} extends Record<KeyType, unknown>
|
|
813
|
+
? never // ✅ `{}` is assignable to `Record<KeyType, unknown>`
|
|
814
|
+
: KeyType // ❌ `{}` is NOT assignable to `Record<KeyType, unknown>`
|
|
815
|
+
]: ObjectType[KeyType];
|
|
816
|
+
};
|
|
817
|
+
```
|
|
818
|
+
|
|
819
|
+
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.
|
|
820
|
+
|
|
821
|
+
@example
|
|
822
|
+
```
|
|
823
|
+
import type {OmitIndexSignature} from 'type-fest';
|
|
824
|
+
|
|
825
|
+
type Example = {
|
|
826
|
+
// These index signatures will be removed.
|
|
827
|
+
[x: string]: any;
|
|
828
|
+
[x: number]: any;
|
|
829
|
+
[x: symbol]: any;
|
|
830
|
+
[x: `head-${string}`]: string;
|
|
831
|
+
[x: `${string}-tail`]: string;
|
|
832
|
+
[x: `head-${string}-tail`]: string;
|
|
833
|
+
[x: `${bigint}`]: string;
|
|
834
|
+
[x: `embedded-${number}`]: string;
|
|
835
|
+
|
|
836
|
+
// These explicitly defined keys will remain.
|
|
837
|
+
foo: 'bar';
|
|
838
|
+
qux?: 'baz';
|
|
839
|
+
};
|
|
840
|
+
|
|
841
|
+
type ExampleWithoutIndexSignatures = OmitIndexSignature<Example>;
|
|
842
|
+
// => { foo: 'bar'; qux?: 'baz' | undefined; }
|
|
843
|
+
```
|
|
844
|
+
|
|
845
|
+
@see {@link PickIndexSignature}
|
|
846
|
+
@category Object
|
|
847
|
+
*/
|
|
848
|
+
type OmitIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? never : KeyType]: ObjectType[KeyType] };
|
|
849
|
+
//#endregion
|
|
850
|
+
//#region node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/pick-index-signature.d.ts
|
|
851
|
+
/**
|
|
852
|
+
Pick only index signatures from the given object type, leaving out all explicitly defined properties.
|
|
853
|
+
|
|
854
|
+
This is the counterpart of `OmitIndexSignature`.
|
|
855
|
+
|
|
856
|
+
@example
|
|
857
|
+
```
|
|
858
|
+
import type {PickIndexSignature} from 'type-fest';
|
|
859
|
+
|
|
860
|
+
declare const symbolKey: unique symbol;
|
|
861
|
+
|
|
862
|
+
type Example = {
|
|
863
|
+
// These index signatures will remain.
|
|
864
|
+
[x: string]: unknown;
|
|
865
|
+
[x: number]: unknown;
|
|
866
|
+
[x: symbol]: unknown;
|
|
867
|
+
[x: `head-${string}`]: string;
|
|
868
|
+
[x: `${string}-tail`]: string;
|
|
869
|
+
[x: `head-${string}-tail`]: string;
|
|
870
|
+
[x: `${bigint}`]: string;
|
|
871
|
+
[x: `embedded-${number}`]: string;
|
|
872
|
+
|
|
873
|
+
// These explicitly defined keys will be removed.
|
|
874
|
+
['kebab-case-key']: string;
|
|
875
|
+
[symbolKey]: string;
|
|
876
|
+
foo: 'bar';
|
|
877
|
+
qux?: 'baz';
|
|
878
|
+
};
|
|
879
|
+
|
|
880
|
+
type ExampleIndexSignature = PickIndexSignature<Example>;
|
|
881
|
+
// {
|
|
882
|
+
// [x: string]: unknown;
|
|
883
|
+
// [x: number]: unknown;
|
|
884
|
+
// [x: symbol]: unknown;
|
|
885
|
+
// [x: `head-${string}`]: string;
|
|
886
|
+
// [x: `${string}-tail`]: string;
|
|
887
|
+
// [x: `head-${string}-tail`]: string;
|
|
888
|
+
// [x: `${bigint}`]: string;
|
|
889
|
+
// [x: `embedded-${number}`]: string;
|
|
890
|
+
// }
|
|
891
|
+
```
|
|
892
|
+
|
|
893
|
+
@see {@link OmitIndexSignature}
|
|
894
|
+
@category Object
|
|
895
|
+
*/
|
|
896
|
+
type PickIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? KeyType : never]: ObjectType[KeyType] };
|
|
897
|
+
//#endregion
|
|
898
|
+
//#region node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/merge.d.ts
|
|
899
|
+
// Merges two objects without worrying about index signatures.
|
|
900
|
+
type SimpleMerge<Destination, Source> = { [Key in keyof Destination as Key extends keyof Source ? never : Key]: Destination[Key] } & Source;
|
|
901
|
+
|
|
902
|
+
/**
|
|
903
|
+
Merge two types into a new type. Keys of the second type overrides keys of the first type.
|
|
904
|
+
|
|
905
|
+
@example
|
|
906
|
+
```
|
|
907
|
+
import type {Merge} from 'type-fest';
|
|
908
|
+
|
|
909
|
+
type Foo = {
|
|
910
|
+
[x: string]: unknown;
|
|
911
|
+
[x: number]: unknown;
|
|
912
|
+
foo: string;
|
|
913
|
+
bar: symbol;
|
|
914
|
+
};
|
|
915
|
+
|
|
916
|
+
type Bar = {
|
|
917
|
+
[x: number]: number;
|
|
918
|
+
[x: symbol]: unknown;
|
|
919
|
+
bar: Date;
|
|
920
|
+
baz: boolean;
|
|
921
|
+
};
|
|
922
|
+
|
|
923
|
+
export type FooBar = Merge<Foo, Bar>;
|
|
924
|
+
// => {
|
|
925
|
+
// [x: string]: unknown;
|
|
926
|
+
// [x: number]: number;
|
|
927
|
+
// [x: symbol]: unknown;
|
|
928
|
+
// foo: string;
|
|
929
|
+
// bar: Date;
|
|
930
|
+
// baz: boolean;
|
|
931
|
+
// }
|
|
932
|
+
```
|
|
933
|
+
|
|
934
|
+
@category Object
|
|
935
|
+
*/
|
|
936
|
+
type Merge<Destination, Source> = Simplify<SimpleMerge<PickIndexSignature<Destination>, PickIndexSignature<Source>> & SimpleMerge<OmitIndexSignature<Destination>, OmitIndexSignature<Source>>>;
|
|
937
|
+
//#endregion
|
|
938
|
+
//#region node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/internal/object.d.ts
|
|
939
|
+
/**
|
|
940
|
+
Works similar to the built-in `Pick` utility type, except for the following differences:
|
|
941
|
+
- Distributes over union types and allows picking keys from any member of the union type.
|
|
942
|
+
- Primitives types are returned as-is.
|
|
943
|
+
- Picks all keys if `Keys` is `any`.
|
|
944
|
+
- Doesn't pick `number` from a `string` index signature.
|
|
945
|
+
|
|
946
|
+
@example
|
|
947
|
+
```
|
|
948
|
+
type ImageUpload = {
|
|
949
|
+
url: string;
|
|
950
|
+
size: number;
|
|
951
|
+
thumbnailUrl: string;
|
|
952
|
+
};
|
|
953
|
+
|
|
954
|
+
type VideoUpload = {
|
|
955
|
+
url: string;
|
|
956
|
+
duration: number;
|
|
957
|
+
encodingFormat: string;
|
|
958
|
+
};
|
|
959
|
+
|
|
960
|
+
// Distributes over union types and allows picking keys from any member of the union type
|
|
961
|
+
type MediaDisplay = HomomorphicPick<ImageUpload | VideoUpload, "url" | "size" | "duration">;
|
|
962
|
+
//=> {url: string; size: number} | {url: string; duration: number}
|
|
963
|
+
|
|
964
|
+
// Primitive types are returned as-is
|
|
965
|
+
type Primitive = HomomorphicPick<string | number, 'toUpperCase' | 'toString'>;
|
|
966
|
+
//=> string | number
|
|
967
|
+
|
|
968
|
+
// Picks all keys if `Keys` is `any`
|
|
969
|
+
type Any = HomomorphicPick<{a: 1; b: 2} | {c: 3}, any>;
|
|
970
|
+
//=> {a: 1; b: 2} | {c: 3}
|
|
971
|
+
|
|
972
|
+
// Doesn't pick `number` from a `string` index signature
|
|
973
|
+
type IndexSignature = HomomorphicPick<{[k: string]: unknown}, number>;
|
|
974
|
+
//=> {}
|
|
975
|
+
*/
|
|
976
|
+
type HomomorphicPick<T, Keys extends KeysOfUnion<T>> = { [P in keyof T as Extract<P, Keys>]: T[P] };
|
|
977
|
+
/**
|
|
978
|
+
Merges user specified options with default options.
|
|
979
|
+
|
|
980
|
+
@example
|
|
981
|
+
```
|
|
982
|
+
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
983
|
+
type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
|
|
984
|
+
type SpecifiedOptions = {leavesOnly: true};
|
|
985
|
+
|
|
986
|
+
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
987
|
+
//=> {maxRecursionDepth: 10; leavesOnly: true}
|
|
988
|
+
```
|
|
989
|
+
|
|
990
|
+
@example
|
|
991
|
+
```
|
|
992
|
+
// Complains if default values are not provided for optional options
|
|
993
|
+
|
|
994
|
+
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
995
|
+
type DefaultPathsOptions = {maxRecursionDepth: 10};
|
|
996
|
+
type SpecifiedOptions = {};
|
|
997
|
+
|
|
998
|
+
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
999
|
+
// ~~~~~~~~~~~~~~~~~~~
|
|
1000
|
+
// Property 'leavesOnly' is missing in type 'DefaultPathsOptions' but required in type '{ maxRecursionDepth: number; leavesOnly: boolean; }'.
|
|
1001
|
+
```
|
|
1002
|
+
|
|
1003
|
+
@example
|
|
1004
|
+
```
|
|
1005
|
+
// Complains if an option's default type does not conform to the expected type
|
|
1006
|
+
|
|
1007
|
+
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
1008
|
+
type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: 'no'};
|
|
1009
|
+
type SpecifiedOptions = {};
|
|
1010
|
+
|
|
1011
|
+
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
1012
|
+
// ~~~~~~~~~~~~~~~~~~~
|
|
1013
|
+
// Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
|
|
1014
|
+
```
|
|
1015
|
+
|
|
1016
|
+
@example
|
|
1017
|
+
```
|
|
1018
|
+
// Complains if an option's specified type does not conform to the expected type
|
|
1019
|
+
|
|
1020
|
+
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
1021
|
+
type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
|
|
1022
|
+
type SpecifiedOptions = {leavesOnly: 'yes'};
|
|
1023
|
+
|
|
1024
|
+
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
1025
|
+
// ~~~~~~~~~~~~~~~~
|
|
1026
|
+
// Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
|
|
1027
|
+
```
|
|
1028
|
+
*/
|
|
1029
|
+
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>>>>;
|
|
1030
|
+
//#endregion
|
|
1031
|
+
//#region node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/except.d.ts
|
|
1032
|
+
/**
|
|
1033
|
+
Filter out keys from an object.
|
|
1034
|
+
|
|
1035
|
+
Returns `never` if `Exclude` is strictly equal to `Key`.
|
|
1036
|
+
Returns `never` if `Key` extends `Exclude`.
|
|
1037
|
+
Returns `Key` otherwise.
|
|
1038
|
+
|
|
1039
|
+
@example
|
|
1040
|
+
```
|
|
1041
|
+
type Filtered = Filter<'foo', 'foo'>;
|
|
1042
|
+
//=> never
|
|
1043
|
+
```
|
|
1044
|
+
|
|
1045
|
+
@example
|
|
1046
|
+
```
|
|
1047
|
+
type Filtered = Filter<'bar', string>;
|
|
1048
|
+
//=> never
|
|
1049
|
+
```
|
|
1050
|
+
|
|
1051
|
+
@example
|
|
1052
|
+
```
|
|
1053
|
+
type Filtered = Filter<'bar', 'foo'>;
|
|
1054
|
+
//=> 'bar'
|
|
1055
|
+
```
|
|
1056
|
+
|
|
1057
|
+
@see {Except}
|
|
1058
|
+
*/
|
|
1059
|
+
type Filter<KeyType$1, ExcludeType> = IsEqual<KeyType$1, ExcludeType> extends true ? never : (KeyType$1 extends ExcludeType ? never : KeyType$1);
|
|
1060
|
+
type ExceptOptions = {
|
|
1061
|
+
/**
|
|
1062
|
+
Disallow assigning non-specified properties.
|
|
1063
|
+
Note that any omitted properties in the resulting type will be present in autocomplete as `undefined`.
|
|
1064
|
+
@default false
|
|
1065
|
+
*/
|
|
1066
|
+
requireExactProps?: boolean;
|
|
1067
|
+
};
|
|
1068
|
+
type DefaultExceptOptions = {
|
|
1069
|
+
requireExactProps: false;
|
|
1070
|
+
};
|
|
1071
|
+
|
|
1072
|
+
/**
|
|
1073
|
+
Create a type from an object type without certain keys.
|
|
1074
|
+
|
|
1075
|
+
We recommend setting the `requireExactProps` option to `true`.
|
|
1076
|
+
|
|
1077
|
+
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.
|
|
1078
|
+
|
|
1079
|
+
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)).
|
|
1080
|
+
|
|
1081
|
+
@example
|
|
1082
|
+
```
|
|
1083
|
+
import type {Except} from 'type-fest';
|
|
1084
|
+
|
|
1085
|
+
type Foo = {
|
|
1086
|
+
a: number;
|
|
1087
|
+
b: string;
|
|
1088
|
+
};
|
|
1089
|
+
|
|
1090
|
+
type FooWithoutA = Except<Foo, 'a'>;
|
|
1091
|
+
//=> {b: string}
|
|
1092
|
+
|
|
1093
|
+
// @ts-expect-error
|
|
1094
|
+
const fooWithoutA: FooWithoutA = {a: 1, b: '2'};
|
|
1095
|
+
//=> errors: 'a' does not exist in type '{ b: string; }'
|
|
1096
|
+
|
|
1097
|
+
type FooWithoutB = Except<Foo, 'b', {requireExactProps: true}>;
|
|
1098
|
+
//=> {a: number} & Partial<Record<"b", never>>
|
|
1099
|
+
|
|
1100
|
+
// @ts-expect-error
|
|
1101
|
+
const fooWithoutB: FooWithoutB = {a: 1, b: '2'};
|
|
1102
|
+
//=> errors at 'b': Type 'string' is not assignable to type 'undefined'.
|
|
1103
|
+
|
|
1104
|
+
// The `Omit` utility type doesn't work when omitting specific keys from objects containing index signatures.
|
|
1105
|
+
|
|
1106
|
+
// Consider the following example:
|
|
1107
|
+
|
|
1108
|
+
type UserData = {
|
|
1109
|
+
[metadata: string]: string;
|
|
1110
|
+
email: string;
|
|
1111
|
+
name: string;
|
|
1112
|
+
role: 'admin' | 'user';
|
|
1113
|
+
};
|
|
1114
|
+
|
|
1115
|
+
// `Omit` clearly doesn't behave as expected in this case:
|
|
1116
|
+
type PostPayload = Omit<UserData, 'email'>;
|
|
1117
|
+
//=> { [x: string]: string; [x: number]: string; }
|
|
1118
|
+
|
|
1119
|
+
// In situations like this, `Except` works better.
|
|
1120
|
+
// It simply removes the `email` key while preserving all the other keys.
|
|
1121
|
+
type PostPayloadFixed = Except<UserData, 'email'>;
|
|
1122
|
+
//=> { [x: string]: string; name: string; role: 'admin' | 'user'; }
|
|
1123
|
+
```
|
|
1124
|
+
|
|
1125
|
+
@category Object
|
|
1126
|
+
*/
|
|
1127
|
+
type Except<ObjectType, KeysType extends keyof ObjectType, Options extends ExceptOptions = {}> = _Except<ObjectType, KeysType, ApplyDefaultOptions<ExceptOptions, DefaultExceptOptions, Options>>;
|
|
1128
|
+
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>> : {});
|
|
1129
|
+
//#endregion
|
|
1130
|
+
//#region node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/require-at-least-one.d.ts
|
|
1131
|
+
/**
|
|
1132
|
+
Create a type that requires at least one of the given keys. The remaining keys are kept as is.
|
|
1133
|
+
|
|
1134
|
+
@example
|
|
1135
|
+
```
|
|
1136
|
+
import type {RequireAtLeastOne} from 'type-fest';
|
|
1137
|
+
|
|
1138
|
+
type Responder = {
|
|
1139
|
+
text?: () => string;
|
|
1140
|
+
json?: () => string;
|
|
1141
|
+
secure?: boolean;
|
|
1142
|
+
};
|
|
1143
|
+
|
|
1144
|
+
const responder: RequireAtLeastOne<Responder, 'text' | 'json'> = {
|
|
1145
|
+
json: () => '{"message": "ok"}',
|
|
1146
|
+
secure: true,
|
|
1147
|
+
};
|
|
1148
|
+
```
|
|
1149
|
+
|
|
1150
|
+
@category Object
|
|
1151
|
+
*/
|
|
1152
|
+
type RequireAtLeastOne<ObjectType, KeysType extends keyof ObjectType = keyof ObjectType> = IfNotAnyOrNever<ObjectType, If<IsNever<KeysType>, never, _RequireAtLeastOne<ObjectType, If<IsAny<KeysType>, keyof ObjectType, KeysType>>>>;
|
|
1153
|
+
type _RequireAtLeastOne<ObjectType, KeysType extends keyof ObjectType> = {
|
|
1154
|
+
// For each `Key` in `KeysType` make a mapped type:
|
|
1155
|
+
[Key in KeysType]-?: Required<Pick<ObjectType, Key>> &
|
|
1156
|
+
// 1. Make `Key`'s type required
|
|
1157
|
+
// 2. Make all other keys in `KeysType` optional
|
|
1158
|
+
Partial<Pick<ObjectType, Exclude<KeysType, Key>>> }[KeysType] &
|
|
1159
|
+
// 3. Add the remaining keys not in `KeysType`
|
|
1160
|
+
Except<ObjectType, KeysType>;
|
|
1161
|
+
//#endregion
|
|
1162
|
+
//#region node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/non-empty-object.d.ts
|
|
1163
|
+
/**
|
|
1164
|
+
Represents an object with at least 1 non-optional key.
|
|
1165
|
+
|
|
1166
|
+
This is useful when you need an object where all keys are optional, but there must be at least 1 key.
|
|
1167
|
+
|
|
1168
|
+
@example
|
|
1169
|
+
```
|
|
1170
|
+
import type {NonEmptyObject} from 'type-fest';
|
|
1171
|
+
|
|
1172
|
+
type User = {
|
|
1173
|
+
name: string;
|
|
1174
|
+
surname: string;
|
|
1175
|
+
id: number;
|
|
1176
|
+
};
|
|
1177
|
+
|
|
1178
|
+
type UpdateRequest<Entity extends object> = NonEmptyObject<Partial<Entity>>;
|
|
1179
|
+
|
|
1180
|
+
const update1: UpdateRequest<User> = {
|
|
1181
|
+
name: 'Alice',
|
|
1182
|
+
surname: 'Acme',
|
|
1183
|
+
};
|
|
1184
|
+
|
|
1185
|
+
// At least 1 key is required, therefore this will report a 2322 error:
|
|
1186
|
+
// Type '{}' is not assignable to type 'UpdateRequest<User>'
|
|
1187
|
+
// @ts-expect-error
|
|
1188
|
+
const update2: UpdateRequest<User> = {};
|
|
1189
|
+
```
|
|
1190
|
+
|
|
1191
|
+
@see Use `IsEmptyObject` to check whether an object is empty.
|
|
1192
|
+
|
|
1193
|
+
@category Object
|
|
1194
|
+
*/
|
|
1195
|
+
type NonEmptyObject<T extends object> = HasRequiredKeys<T> extends true ? T : RequireAtLeastOne<T, keyof T>;
|
|
1196
|
+
//#endregion
|
|
1197
|
+
//#region node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/union-to-tuple.d.ts
|
|
1198
|
+
/**
|
|
1199
|
+
Returns the last element of a union type.
|
|
1200
|
+
|
|
1201
|
+
@example
|
|
1202
|
+
```
|
|
1203
|
+
type Last = LastOfUnion<1 | 2 | 3>;
|
|
1204
|
+
//=> 3
|
|
1205
|
+
```
|
|
1206
|
+
*/
|
|
1207
|
+
type LastOfUnion<T> = UnionToIntersection<T extends any ? () => T : never> extends (() => (infer R)) ? R : never;
|
|
1208
|
+
|
|
1209
|
+
/**
|
|
1210
|
+
Convert a union type into an unordered tuple type of its elements.
|
|
1211
|
+
|
|
1212
|
+
"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.
|
|
1213
|
+
|
|
1214
|
+
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.
|
|
1215
|
+
|
|
1216
|
+
@example
|
|
1217
|
+
```
|
|
1218
|
+
import type {UnionToTuple} from 'type-fest';
|
|
1219
|
+
|
|
1220
|
+
type Numbers = 1 | 2 | 3;
|
|
1221
|
+
type NumbersTuple = UnionToTuple<Numbers>;
|
|
1222
|
+
//=> [1, 2, 3]
|
|
1223
|
+
```
|
|
1224
|
+
|
|
1225
|
+
@example
|
|
1226
|
+
```
|
|
1227
|
+
import type {UnionToTuple} from 'type-fest';
|
|
1228
|
+
|
|
1229
|
+
const pets = {
|
|
1230
|
+
dog: '🐶',
|
|
1231
|
+
cat: '🐱',
|
|
1232
|
+
snake: '🐍',
|
|
1233
|
+
};
|
|
1234
|
+
|
|
1235
|
+
type Pet = keyof typeof pets;
|
|
1236
|
+
//=> 'dog' | 'cat' | 'snake'
|
|
1237
|
+
|
|
1238
|
+
const petList = Object.keys(pets) as UnionToTuple<Pet>;
|
|
1239
|
+
//=> ['dog', 'cat', 'snake']
|
|
1240
|
+
```
|
|
1241
|
+
|
|
1242
|
+
@category Array
|
|
1243
|
+
*/
|
|
1244
|
+
type UnionToTuple<T, L = LastOfUnion<T>> = IsNever<T> extends false ? [...UnionToTuple<Exclude<T, L>>, L] : [];
|
|
1245
|
+
//#endregion
|
|
1246
|
+
//#region node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/set-optional.d.ts
|
|
1247
|
+
/**
|
|
1248
|
+
Create a type that makes the given keys optional. The remaining keys are kept as is. The sister of the `SetRequired` type.
|
|
1249
|
+
|
|
1250
|
+
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.
|
|
1251
|
+
|
|
1252
|
+
@example
|
|
1253
|
+
```
|
|
1254
|
+
import type {SetOptional} from 'type-fest';
|
|
1255
|
+
|
|
1256
|
+
type Foo = {
|
|
1257
|
+
a: number;
|
|
1258
|
+
b?: string;
|
|
1259
|
+
c: boolean;
|
|
1260
|
+
};
|
|
1261
|
+
|
|
1262
|
+
type SomeOptional = SetOptional<Foo, 'b' | 'c'>;
|
|
1263
|
+
// type SomeOptional = {
|
|
1264
|
+
// a: number;
|
|
1265
|
+
// b?: string; // Was already optional and still is.
|
|
1266
|
+
// c?: boolean; // Is now optional.
|
|
1267
|
+
// }
|
|
1268
|
+
```
|
|
1269
|
+
|
|
1270
|
+
@category Object
|
|
1271
|
+
*/
|
|
1272
|
+
type SetOptional<BaseType, Keys extends keyof BaseType> = (BaseType extends ((...arguments_: never) => any) ? (...arguments_: Parameters<BaseType>) => ReturnType<BaseType> : unknown) & _SetOptional<BaseType, Keys>;
|
|
1273
|
+
type _SetOptional<BaseType, Keys extends keyof BaseType> = BaseType extends unknown // To distribute `BaseType` when it's a union type.
|
|
1274
|
+
? Simplify<
|
|
1275
|
+
// Pick just the keys that are readonly from the base type.
|
|
1276
|
+
Except<BaseType, Keys> &
|
|
1277
|
+
// Pick the keys that should be mutable from the base type and make them mutable.
|
|
1278
|
+
Partial<HomomorphicPick<BaseType, Keys>>> : never;
|
|
1279
|
+
//#endregion
|
|
1280
|
+
//#region node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/value-of.d.ts
|
|
1281
|
+
/**
|
|
1282
|
+
Create a union of the given object's values, and optionally specify which keys to get the values from.
|
|
1283
|
+
|
|
1284
|
+
Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/31438) if you want to have this type as a built-in in TypeScript.
|
|
1285
|
+
|
|
1286
|
+
@example
|
|
1287
|
+
```
|
|
1288
|
+
import type {ValueOf} from 'type-fest';
|
|
1289
|
+
|
|
1290
|
+
type A = ValueOf<{id: number; name: string; active: boolean}>;
|
|
1291
|
+
//=> number | string | boolean
|
|
1292
|
+
|
|
1293
|
+
type B = ValueOf<{id: number; name: string; active: boolean}, 'name'>;
|
|
1294
|
+
//=> string
|
|
1295
|
+
|
|
1296
|
+
type C = ValueOf<{id: number; name: string; active: boolean}, 'id' | 'name'>;
|
|
1297
|
+
//=> number | string
|
|
1298
|
+
```
|
|
1299
|
+
|
|
1300
|
+
@category Object
|
|
1301
|
+
*/
|
|
1302
|
+
type ValueOf<ObjectType, ValueType extends keyof ObjectType = keyof ObjectType> = ObjectType[ValueType];
|
|
1303
|
+
//#endregion
|
|
1304
|
+
//#region node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/replace.d.ts
|
|
1305
|
+
type ReplaceOptions = {
|
|
1306
|
+
all?: boolean;
|
|
1307
|
+
};
|
|
1308
|
+
type DefaultReplaceOptions = {
|
|
1309
|
+
all: false;
|
|
1310
|
+
};
|
|
1311
|
+
|
|
1312
|
+
/**
|
|
1313
|
+
Represents a string with some or all matches replaced by a replacement.
|
|
1314
|
+
|
|
1315
|
+
Use-case:
|
|
1316
|
+
- `kebab-case-path` to `dotted.path.notation`
|
|
1317
|
+
- Changing date/time format: `01-08-2042` → `01/08/2042`
|
|
1318
|
+
- Manipulation of type properties, for example, removal of prefixes
|
|
1319
|
+
|
|
1320
|
+
@example
|
|
1321
|
+
```
|
|
1322
|
+
import type {Replace} from 'type-fest';
|
|
1323
|
+
|
|
1324
|
+
declare function replace<
|
|
1325
|
+
Input extends string,
|
|
1326
|
+
Search extends string,
|
|
1327
|
+
Replacement extends string,
|
|
1328
|
+
>(
|
|
1329
|
+
input: Input,
|
|
1330
|
+
search: Search,
|
|
1331
|
+
replacement: Replacement
|
|
1332
|
+
): Replace<Input, Search, Replacement>;
|
|
1333
|
+
|
|
1334
|
+
declare function replaceAll<
|
|
1335
|
+
Input extends string,
|
|
1336
|
+
Search extends string,
|
|
1337
|
+
Replacement extends string,
|
|
1338
|
+
>(
|
|
1339
|
+
input: Input,
|
|
1340
|
+
search: Search,
|
|
1341
|
+
replacement: Replacement
|
|
1342
|
+
): Replace<Input, Search, Replacement, {all: true}>;
|
|
1343
|
+
|
|
1344
|
+
// The return type is the exact string literal, not just `string`.
|
|
1345
|
+
|
|
1346
|
+
replace('hello ?', '?', '🦄');
|
|
1347
|
+
//=> 'hello 🦄'
|
|
1348
|
+
|
|
1349
|
+
replace('hello ??', '?', '❓');
|
|
1350
|
+
//=> 'hello ❓?'
|
|
1351
|
+
|
|
1352
|
+
replaceAll('10:42:00', ':', '-');
|
|
1353
|
+
//=> '10-42-00'
|
|
1354
|
+
|
|
1355
|
+
replaceAll('__userName__', '__', '');
|
|
1356
|
+
//=> 'userName'
|
|
1357
|
+
|
|
1358
|
+
replaceAll('My Cool Title', ' ', '');
|
|
1359
|
+
//=> 'MyCoolTitle'
|
|
1360
|
+
```
|
|
1361
|
+
|
|
1362
|
+
@category String
|
|
1363
|
+
@category Template literal
|
|
1364
|
+
*/
|
|
1365
|
+
type Replace<Input extends string, Search extends string, Replacement extends string, Options extends ReplaceOptions = {}> = _Replace<Input, Search, Replacement, ApplyDefaultOptions<ReplaceOptions, DefaultReplaceOptions, Options>>;
|
|
1366
|
+
type _Replace<Input extends string, Search extends string, Replacement extends string, Options extends Required<ReplaceOptions>, Accumulator extends string = ''> = Search extends string // For distributing `Search`
|
|
1367
|
+
? Replacement extends string // For distributing `Replacement`
|
|
1368
|
+
? 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;
|
|
1369
|
+
//#endregion
|
|
1370
|
+
//#region src/utils/object/enumEntries.d.ts
|
|
1371
|
+
/**
|
|
1372
|
+
* 返回枚举的属性的键/值数组
|
|
1373
|
+
*
|
|
1374
|
+
* @param enumeration 枚举
|
|
1375
|
+
*/
|
|
1376
|
+
declare function enumEntries<E extends AnyObject>(enumeration: NonEmptyObject<E>): [keyof E, E[keyof E]][];
|
|
1377
|
+
//#endregion
|
|
1378
|
+
//#region src/utils/object/enumKeys.d.ts
|
|
1379
|
+
/**
|
|
1380
|
+
* 获取枚举所有属性的键
|
|
1381
|
+
*
|
|
1382
|
+
* @param enumeration 枚举
|
|
1383
|
+
*/
|
|
1384
|
+
declare function enumKeys<E extends AnyObject>(enumeration: NonEmptyObject<E>): [keyof E, ...(keyof E)[]];
|
|
1385
|
+
//#endregion
|
|
1386
|
+
//#region src/utils/object/enumTypeCheck.d.ts
|
|
1387
|
+
declare function enumTypeCheck<E extends AnyObject>(enumeration: E): E & Record<PropertyKey, unknown>;
|
|
1388
|
+
//#endregion
|
|
1389
|
+
//#region src/utils/object/enumValues.d.ts
|
|
1390
|
+
/**
|
|
1391
|
+
* 获取枚举所有属性的值
|
|
1392
|
+
*
|
|
1393
|
+
* @param enumeration 枚举
|
|
1394
|
+
*/
|
|
1395
|
+
declare function enumValues<E extends AnyObject>(enumeration: NonEmptyObject<E>): UnionToTuple<ValueOf<E>>;
|
|
1396
|
+
//#endregion
|
|
1397
|
+
//#region src/utils/object/mapEntries.d.ts
|
|
1398
|
+
declare function mapEntries<K$1 extends PropertyKey, V, NK extends PropertyKey, NV>(obj: PlainObject<K$1, V>, toEntry: (key: K$1, value: V) => [NK, NV]): PlainObject<NK, NV>;
|
|
1399
|
+
//#endregion
|
|
1400
|
+
//#region node_modules/.pnpm/radashi@12.7.1/node_modules/radashi/dist/radashi.d.cts
|
|
1401
|
+
|
|
1402
|
+
interface BigInt {
|
|
1403
|
+
/**
|
|
1404
|
+
* Returns a string representation of an object.
|
|
1405
|
+
* @param radix Specifies a radix for converting numeric values to strings.
|
|
1406
|
+
*/
|
|
1407
|
+
toString(radix?: number): string;
|
|
1408
|
+
/** Returns a string representation appropriate to the host environment's current locale. */
|
|
1409
|
+
toLocaleString(locales?: any, options?: BigIntToLocaleStringOptions): string;
|
|
1410
|
+
/** Returns the primitive value of the specified object. */
|
|
1411
|
+
valueOf(): bigint;
|
|
1412
|
+
readonly [Symbol.toStringTag]: "BigInt";
|
|
1413
|
+
}
|
|
1414
|
+
/**
|
|
1415
|
+
* A typed array of 64-bit signed integer values. The contents are initialized to 0. If the
|
|
1416
|
+
* requested number of bytes could not be allocated, an exception is raised.
|
|
1417
|
+
*/
|
|
1418
|
+
interface BigInt64Array$1 {
|
|
1419
|
+
/** The size in bytes of each element in the array. */
|
|
1420
|
+
readonly BYTES_PER_ELEMENT: number;
|
|
1421
|
+
/** The ArrayBuffer instance referenced by the array. */
|
|
1422
|
+
readonly buffer: ArrayBufferLike;
|
|
1423
|
+
/** The length in bytes of the array. */
|
|
1424
|
+
readonly byteLength: number;
|
|
1425
|
+
/** The offset in bytes of the array. */
|
|
1426
|
+
readonly byteOffset: number;
|
|
1427
|
+
/**
|
|
1428
|
+
* Returns the this object after copying a section of the array identified by start and end
|
|
1429
|
+
* to the same array starting at position target
|
|
1430
|
+
* @param target If target is negative, it is treated as length+target where length is the
|
|
1431
|
+
* length of the array.
|
|
1432
|
+
* @param start If start is negative, it is treated as length+start. If end is negative, it
|
|
1433
|
+
* is treated as length+end.
|
|
1434
|
+
* @param end If not specified, length of the this object is used as its default value.
|
|
1435
|
+
*/
|
|
1436
|
+
copyWithin(target: number, start: number, end?: number): this;
|
|
1437
|
+
/** Yields index, value pairs for every entry in the array. */
|
|
1438
|
+
entries(): IterableIterator<[number, bigint]>;
|
|
1439
|
+
/**
|
|
1440
|
+
* Determines whether all the members of an array satisfy the specified test.
|
|
1441
|
+
* @param predicate A function that accepts up to three arguments. The every method calls
|
|
1442
|
+
* the predicate function for each element in the array until the predicate returns false,
|
|
1443
|
+
* or until the end of the array.
|
|
1444
|
+
* @param thisArg An object to which the this keyword can refer in the predicate function.
|
|
1445
|
+
* If thisArg is omitted, undefined is used as the this value.
|
|
1446
|
+
*/
|
|
1447
|
+
every(predicate: (value: bigint, index: number, array: BigInt64Array$1) => boolean, thisArg?: any): boolean;
|
|
1448
|
+
/**
|
|
1449
|
+
* Changes all array elements from `start` to `end` index to a static `value` and returns the modified array
|
|
1450
|
+
* @param value value to fill array section with
|
|
1451
|
+
* @param start index to start filling the array at. If start is negative, it is treated as
|
|
1452
|
+
* length+start where length is the length of the array.
|
|
1453
|
+
* @param end index to stop filling the array at. If end is negative, it is treated as
|
|
1454
|
+
* length+end.
|
|
1455
|
+
*/
|
|
1456
|
+
fill(value: bigint, start?: number, end?: number): this;
|
|
1457
|
+
/**
|
|
1458
|
+
* Returns the elements of an array that meet the condition specified in a callback function.
|
|
1459
|
+
* @param predicate A function that accepts up to three arguments. The filter method calls
|
|
1460
|
+
* the predicate function one time for each element in the array.
|
|
1461
|
+
* @param thisArg An object to which the this keyword can refer in the predicate function.
|
|
1462
|
+
* If thisArg is omitted, undefined is used as the this value.
|
|
1463
|
+
*/
|
|
1464
|
+
filter(predicate: (value: bigint, index: number, array: BigInt64Array$1) => any, thisArg?: any): BigInt64Array$1;
|
|
1465
|
+
/**
|
|
1466
|
+
* Returns the value of the first element in the array where predicate is true, and undefined
|
|
1467
|
+
* otherwise.
|
|
1468
|
+
* @param predicate find calls predicate once for each element of the array, in ascending
|
|
1469
|
+
* order, until it finds one where predicate returns true. If such an element is found, find
|
|
1470
|
+
* immediately returns that element value. Otherwise, find returns undefined.
|
|
1471
|
+
* @param thisArg If provided, it will be used as the this value for each invocation of
|
|
1472
|
+
* predicate. If it is not provided, undefined is used instead.
|
|
1473
|
+
*/
|
|
1474
|
+
find(predicate: (value: bigint, index: number, array: BigInt64Array$1) => boolean, thisArg?: any): bigint | undefined;
|
|
1475
|
+
/**
|
|
1476
|
+
* Returns the index of the first element in the array where predicate is true, and -1
|
|
1477
|
+
* otherwise.
|
|
1478
|
+
* @param predicate find calls predicate once for each element of the array, in ascending
|
|
1479
|
+
* order, until it finds one where predicate returns true. If such an element is found,
|
|
1480
|
+
* findIndex immediately returns that element index. Otherwise, findIndex returns -1.
|
|
1481
|
+
* @param thisArg If provided, it will be used as the this value for each invocation of
|
|
1482
|
+
* predicate. If it is not provided, undefined is used instead.
|
|
1483
|
+
*/
|
|
1484
|
+
findIndex(predicate: (value: bigint, index: number, array: BigInt64Array$1) => boolean, thisArg?: any): number;
|
|
1485
|
+
/**
|
|
1486
|
+
* Performs the specified action for each element in an array.
|
|
1487
|
+
* @param callbackfn A function that accepts up to three arguments. forEach calls the
|
|
1488
|
+
* callbackfn function one time for each element in the array.
|
|
1489
|
+
* @param thisArg An object to which the this keyword can refer in the callbackfn function.
|
|
1490
|
+
* If thisArg is omitted, undefined is used as the this value.
|
|
1491
|
+
*/
|
|
1492
|
+
forEach(callbackfn: (value: bigint, index: number, array: BigInt64Array$1) => void, thisArg?: any): void;
|
|
1493
|
+
/**
|
|
1494
|
+
* Determines whether an array includes a certain element, returning true or false as appropriate.
|
|
1495
|
+
* @param searchElement The element to search for.
|
|
1496
|
+
* @param fromIndex The position in this array at which to begin searching for searchElement.
|
|
1497
|
+
*/
|
|
1498
|
+
includes(searchElement: bigint, fromIndex?: number): boolean;
|
|
1499
|
+
/**
|
|
1500
|
+
* Returns the index of the first occurrence of a value in an array.
|
|
1501
|
+
* @param searchElement The value to locate in the array.
|
|
1502
|
+
* @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the
|
|
1503
|
+
* search starts at index 0.
|
|
1504
|
+
*/
|
|
1505
|
+
indexOf(searchElement: bigint, fromIndex?: number): number;
|
|
1506
|
+
/**
|
|
1507
|
+
* Adds all the elements of an array separated by the specified separator string.
|
|
1508
|
+
* @param separator A string used to separate one element of an array from the next in the
|
|
1509
|
+
* resulting String. If omitted, the array elements are separated with a comma.
|
|
1510
|
+
*/
|
|
1511
|
+
join(separator?: string): string;
|
|
1512
|
+
/** Yields each index in the array. */
|
|
1513
|
+
keys(): IterableIterator<number>;
|
|
1514
|
+
/**
|
|
1515
|
+
* Returns the index of the last occurrence of a value in an array.
|
|
1516
|
+
* @param searchElement The value to locate in the array.
|
|
1517
|
+
* @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the
|
|
1518
|
+
* search starts at index 0.
|
|
1519
|
+
*/
|
|
1520
|
+
lastIndexOf(searchElement: bigint, fromIndex?: number): number;
|
|
1521
|
+
/** The length of the array. */
|
|
1522
|
+
readonly length: number;
|
|
1523
|
+
/**
|
|
1524
|
+
* Calls a defined callback function on each element of an array, and returns an array that
|
|
1525
|
+
* contains the results.
|
|
1526
|
+
* @param callbackfn A function that accepts up to three arguments. The map method calls the
|
|
1527
|
+
* callbackfn function one time for each element in the array.
|
|
1528
|
+
* @param thisArg An object to which the this keyword can refer in the callbackfn function.
|
|
1529
|
+
* If thisArg is omitted, undefined is used as the this value.
|
|
1530
|
+
*/
|
|
1531
|
+
map(callbackfn: (value: bigint, index: number, array: BigInt64Array$1) => bigint, thisArg?: any): BigInt64Array$1;
|
|
1532
|
+
/**
|
|
1533
|
+
* Calls the specified callback function for all the elements in an array. The return value of
|
|
1534
|
+
* the callback function is the accumulated result, and is provided as an argument in the next
|
|
1535
|
+
* call to the callback function.
|
|
1536
|
+
* @param callbackfn A function that accepts up to four arguments. The reduce method calls the
|
|
1537
|
+
* callbackfn function one time for each element in the array.
|
|
1538
|
+
* @param initialValue If initialValue is specified, it is used as the initial value to start
|
|
1539
|
+
* the accumulation. The first call to the callbackfn function provides this value as an argument
|
|
1540
|
+
* instead of an array value.
|
|
1541
|
+
*/
|
|
1542
|
+
reduce(callbackfn: (previousValue: bigint, currentValue: bigint, currentIndex: number, array: BigInt64Array$1) => bigint): bigint;
|
|
1543
|
+
/**
|
|
1544
|
+
* Calls the specified callback function for all the elements in an array. The return value of
|
|
1545
|
+
* the callback function is the accumulated result, and is provided as an argument in the next
|
|
1546
|
+
* call to the callback function.
|
|
1547
|
+
* @param callbackfn A function that accepts up to four arguments. The reduce method calls the
|
|
1548
|
+
* callbackfn function one time for each element in the array.
|
|
1549
|
+
* @param initialValue If initialValue is specified, it is used as the initial value to start
|
|
1550
|
+
* the accumulation. The first call to the callbackfn function provides this value as an argument
|
|
1551
|
+
* instead of an array value.
|
|
1552
|
+
*/
|
|
1553
|
+
reduce<U$1>(callbackfn: (previousValue: U$1, currentValue: bigint, currentIndex: number, array: BigInt64Array$1) => U$1, initialValue: U$1): U$1;
|
|
1554
|
+
/**
|
|
1555
|
+
* Calls the specified callback function for all the elements in an array, in descending order.
|
|
1556
|
+
* The return value of the callback function is the accumulated result, and is provided as an
|
|
1557
|
+
* argument in the next call to the callback function.
|
|
1558
|
+
* @param callbackfn A function that accepts up to four arguments. The reduceRight method calls
|
|
1559
|
+
* the callbackfn function one time for each element in the array.
|
|
1560
|
+
* @param initialValue If initialValue is specified, it is used as the initial value to start
|
|
1561
|
+
* the accumulation. The first call to the callbackfn function provides this value as an
|
|
1562
|
+
* argument instead of an array value.
|
|
1563
|
+
*/
|
|
1564
|
+
reduceRight(callbackfn: (previousValue: bigint, currentValue: bigint, currentIndex: number, array: BigInt64Array$1) => bigint): bigint;
|
|
1565
|
+
/**
|
|
1566
|
+
* Calls the specified callback function for all the elements in an array, in descending order.
|
|
1567
|
+
* The return value of the callback function is the accumulated result, and is provided as an
|
|
1568
|
+
* argument in the next call to the callback function.
|
|
1569
|
+
* @param callbackfn A function that accepts up to four arguments. The reduceRight method calls
|
|
1570
|
+
* the callbackfn function one time for each element in the array.
|
|
1571
|
+
* @param initialValue If initialValue is specified, it is used as the initial value to start
|
|
1572
|
+
* the accumulation. The first call to the callbackfn function provides this value as an argument
|
|
1573
|
+
* instead of an array value.
|
|
1574
|
+
*/
|
|
1575
|
+
reduceRight<U$1>(callbackfn: (previousValue: U$1, currentValue: bigint, currentIndex: number, array: BigInt64Array$1) => U$1, initialValue: U$1): U$1;
|
|
1576
|
+
/** Reverses the elements in the array. */
|
|
1577
|
+
reverse(): this;
|
|
1578
|
+
/**
|
|
1579
|
+
* Sets a value or an array of values.
|
|
1580
|
+
* @param array A typed or untyped array of values to set.
|
|
1581
|
+
* @param offset The index in the current array at which the values are to be written.
|
|
1582
|
+
*/
|
|
1583
|
+
set(array: ArrayLike<bigint>, offset?: number): void;
|
|
1584
|
+
/**
|
|
1585
|
+
* Returns a section of an array.
|
|
1586
|
+
* @param start The beginning of the specified portion of the array.
|
|
1587
|
+
* @param end The end of the specified portion of the array.
|
|
1588
|
+
*/
|
|
1589
|
+
slice(start?: number, end?: number): BigInt64Array$1;
|
|
1590
|
+
/**
|
|
1591
|
+
* Determines whether the specified callback function returns true for any element of an array.
|
|
1592
|
+
* @param predicate A function that accepts up to three arguments. The some method calls the
|
|
1593
|
+
* predicate function for each element in the array until the predicate returns true, or until
|
|
1594
|
+
* the end of the array.
|
|
1595
|
+
* @param thisArg An object to which the this keyword can refer in the predicate function.
|
|
1596
|
+
* If thisArg is omitted, undefined is used as the this value.
|
|
1597
|
+
*/
|
|
1598
|
+
some(predicate: (value: bigint, index: number, array: BigInt64Array$1) => boolean, thisArg?: any): boolean;
|
|
1599
|
+
/**
|
|
1600
|
+
* Sorts the array.
|
|
1601
|
+
* @param compareFn The function used to determine the order of the elements. If omitted, the elements are sorted in ascending order.
|
|
1602
|
+
*/
|
|
1603
|
+
sort(compareFn?: (a: bigint, b: bigint) => number | bigint): this;
|
|
1604
|
+
/**
|
|
1605
|
+
* Gets a new BigInt64Array view of the ArrayBuffer store for this array, referencing the elements
|
|
1606
|
+
* at begin, inclusive, up to end, exclusive.
|
|
1607
|
+
* @param begin The index of the beginning of the array.
|
|
1608
|
+
* @param end The index of the end of the array.
|
|
1609
|
+
*/
|
|
1610
|
+
subarray(begin?: number, end?: number): BigInt64Array$1;
|
|
1611
|
+
/** Converts the array to a string by using the current locale. */
|
|
1612
|
+
toLocaleString(locales?: string | string[], options?: Intl.NumberFormatOptions): string;
|
|
1613
|
+
/** Returns a string representation of the array. */
|
|
1614
|
+
toString(): string;
|
|
1615
|
+
/** Returns the primitive value of the specified object. */
|
|
1616
|
+
valueOf(): BigInt64Array$1;
|
|
1617
|
+
/** Yields each value in the array. */
|
|
1618
|
+
values(): IterableIterator<bigint>;
|
|
1619
|
+
[Symbol.iterator](): IterableIterator<bigint>;
|
|
1620
|
+
readonly [Symbol.toStringTag]: "BigInt64Array";
|
|
1621
|
+
[index: number]: bigint;
|
|
1622
|
+
}
|
|
1623
|
+
/**
|
|
1624
|
+
* A typed array of 64-bit unsigned integer values. The contents are initialized to 0. If the
|
|
1625
|
+
* requested number of bytes could not be allocated, an exception is raised.
|
|
1626
|
+
*/
|
|
1627
|
+
interface BigUint64Array$1 {
|
|
1628
|
+
/** The size in bytes of each element in the array. */
|
|
1629
|
+
readonly BYTES_PER_ELEMENT: number;
|
|
1630
|
+
/** The ArrayBuffer instance referenced by the array. */
|
|
1631
|
+
readonly buffer: ArrayBufferLike;
|
|
1632
|
+
/** The length in bytes of the array. */
|
|
1633
|
+
readonly byteLength: number;
|
|
1634
|
+
/** The offset in bytes of the array. */
|
|
1635
|
+
readonly byteOffset: number;
|
|
1636
|
+
/**
|
|
1637
|
+
* Returns the this object after copying a section of the array identified by start and end
|
|
1638
|
+
* to the same array starting at position target
|
|
1639
|
+
* @param target If target is negative, it is treated as length+target where length is the
|
|
1640
|
+
* length of the array.
|
|
1641
|
+
* @param start If start is negative, it is treated as length+start. If end is negative, it
|
|
1642
|
+
* is treated as length+end.
|
|
1643
|
+
* @param end If not specified, length of the this object is used as its default value.
|
|
1644
|
+
*/
|
|
1645
|
+
copyWithin(target: number, start: number, end?: number): this;
|
|
1646
|
+
/** Yields index, value pairs for every entry in the array. */
|
|
1647
|
+
entries(): IterableIterator<[number, bigint]>;
|
|
1648
|
+
/**
|
|
1649
|
+
* Determines whether all the members of an array satisfy the specified test.
|
|
1650
|
+
* @param predicate A function that accepts up to three arguments. The every method calls
|
|
1651
|
+
* the predicate function for each element in the array until the predicate returns false,
|
|
1652
|
+
* or until the end of the array.
|
|
1653
|
+
* @param thisArg An object to which the this keyword can refer in the predicate function.
|
|
1654
|
+
* If thisArg is omitted, undefined is used as the this value.
|
|
1655
|
+
*/
|
|
1656
|
+
every(predicate: (value: bigint, index: number, array: BigUint64Array$1) => boolean, thisArg?: any): boolean;
|
|
1657
|
+
/**
|
|
1658
|
+
* Changes all array elements from `start` to `end` index to a static `value` and returns the modified array
|
|
1659
|
+
* @param value value to fill array section with
|
|
1660
|
+
* @param start index to start filling the array at. If start is negative, it is treated as
|
|
1661
|
+
* length+start where length is the length of the array.
|
|
1662
|
+
* @param end index to stop filling the array at. If end is negative, it is treated as
|
|
1663
|
+
* length+end.
|
|
1664
|
+
*/
|
|
1665
|
+
fill(value: bigint, start?: number, end?: number): this;
|
|
1666
|
+
/**
|
|
1667
|
+
* Returns the elements of an array that meet the condition specified in a callback function.
|
|
1668
|
+
* @param predicate A function that accepts up to three arguments. The filter method calls
|
|
1669
|
+
* the predicate function one time for each element in the array.
|
|
1670
|
+
* @param thisArg An object to which the this keyword can refer in the predicate function.
|
|
1671
|
+
* If thisArg is omitted, undefined is used as the this value.
|
|
1672
|
+
*/
|
|
1673
|
+
filter(predicate: (value: bigint, index: number, array: BigUint64Array$1) => any, thisArg?: any): BigUint64Array$1;
|
|
1674
|
+
/**
|
|
1675
|
+
* Returns the value of the first element in the array where predicate is true, and undefined
|
|
1676
|
+
* otherwise.
|
|
1677
|
+
* @param predicate find calls predicate once for each element of the array, in ascending
|
|
1678
|
+
* order, until it finds one where predicate returns true. If such an element is found, find
|
|
1679
|
+
* immediately returns that element value. Otherwise, find returns undefined.
|
|
1680
|
+
* @param thisArg If provided, it will be used as the this value for each invocation of
|
|
1681
|
+
* predicate. If it is not provided, undefined is used instead.
|
|
1682
|
+
*/
|
|
1683
|
+
find(predicate: (value: bigint, index: number, array: BigUint64Array$1) => boolean, thisArg?: any): bigint | undefined;
|
|
1684
|
+
/**
|
|
1685
|
+
* Returns the index of the first element in the array where predicate is true, and -1
|
|
1686
|
+
* otherwise.
|
|
1687
|
+
* @param predicate find calls predicate once for each element of the array, in ascending
|
|
1688
|
+
* order, until it finds one where predicate returns true. If such an element is found,
|
|
1689
|
+
* findIndex immediately returns that element index. Otherwise, findIndex returns -1.
|
|
1690
|
+
* @param thisArg If provided, it will be used as the this value for each invocation of
|
|
1691
|
+
* predicate. If it is not provided, undefined is used instead.
|
|
1692
|
+
*/
|
|
1693
|
+
findIndex(predicate: (value: bigint, index: number, array: BigUint64Array$1) => boolean, thisArg?: any): number;
|
|
1694
|
+
/**
|
|
1695
|
+
* Performs the specified action for each element in an array.
|
|
1696
|
+
* @param callbackfn A function that accepts up to three arguments. forEach calls the
|
|
1697
|
+
* callbackfn function one time for each element in the array.
|
|
1698
|
+
* @param thisArg An object to which the this keyword can refer in the callbackfn function.
|
|
1699
|
+
* If thisArg is omitted, undefined is used as the this value.
|
|
1700
|
+
*/
|
|
1701
|
+
forEach(callbackfn: (value: bigint, index: number, array: BigUint64Array$1) => void, thisArg?: any): void;
|
|
1702
|
+
/**
|
|
1703
|
+
* Determines whether an array includes a certain element, returning true or false as appropriate.
|
|
1704
|
+
* @param searchElement The element to search for.
|
|
1705
|
+
* @param fromIndex The position in this array at which to begin searching for searchElement.
|
|
1706
|
+
*/
|
|
1707
|
+
includes(searchElement: bigint, fromIndex?: number): boolean;
|
|
1708
|
+
/**
|
|
1709
|
+
* Returns the index of the first occurrence of a value in an array.
|
|
1710
|
+
* @param searchElement The value to locate in the array.
|
|
1711
|
+
* @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the
|
|
1712
|
+
* search starts at index 0.
|
|
1713
|
+
*/
|
|
1714
|
+
indexOf(searchElement: bigint, fromIndex?: number): number;
|
|
1715
|
+
/**
|
|
1716
|
+
* Adds all the elements of an array separated by the specified separator string.
|
|
1717
|
+
* @param separator A string used to separate one element of an array from the next in the
|
|
1718
|
+
* resulting String. If omitted, the array elements are separated with a comma.
|
|
1719
|
+
*/
|
|
1720
|
+
join(separator?: string): string;
|
|
1721
|
+
/** Yields each index in the array. */
|
|
1722
|
+
keys(): IterableIterator<number>;
|
|
1723
|
+
/**
|
|
1724
|
+
* Returns the index of the last occurrence of a value in an array.
|
|
1725
|
+
* @param searchElement The value to locate in the array.
|
|
1726
|
+
* @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the
|
|
1727
|
+
* search starts at index 0.
|
|
1728
|
+
*/
|
|
1729
|
+
lastIndexOf(searchElement: bigint, fromIndex?: number): number;
|
|
1730
|
+
/** The length of the array. */
|
|
1731
|
+
readonly length: number;
|
|
1732
|
+
/**
|
|
1733
|
+
* Calls a defined callback function on each element of an array, and returns an array that
|
|
1734
|
+
* contains the results.
|
|
1735
|
+
* @param callbackfn A function that accepts up to three arguments. The map method calls the
|
|
1736
|
+
* callbackfn function one time for each element in the array.
|
|
1737
|
+
* @param thisArg An object to which the this keyword can refer in the callbackfn function.
|
|
1738
|
+
* If thisArg is omitted, undefined is used as the this value.
|
|
1739
|
+
*/
|
|
1740
|
+
map(callbackfn: (value: bigint, index: number, array: BigUint64Array$1) => bigint, thisArg?: any): BigUint64Array$1;
|
|
1741
|
+
/**
|
|
1742
|
+
* Calls the specified callback function for all the elements in an array. The return value of
|
|
1743
|
+
* the callback function is the accumulated result, and is provided as an argument in the next
|
|
1744
|
+
* call to the callback function.
|
|
1745
|
+
* @param callbackfn A function that accepts up to four arguments. The reduce method calls the
|
|
1746
|
+
* callbackfn function one time for each element in the array.
|
|
1747
|
+
* @param initialValue If initialValue is specified, it is used as the initial value to start
|
|
1748
|
+
* the accumulation. The first call to the callbackfn function provides this value as an argument
|
|
1749
|
+
* instead of an array value.
|
|
1750
|
+
*/
|
|
1751
|
+
reduce(callbackfn: (previousValue: bigint, currentValue: bigint, currentIndex: number, array: BigUint64Array$1) => bigint): bigint;
|
|
1752
|
+
/**
|
|
1753
|
+
* Calls the specified callback function for all the elements in an array. The return value of
|
|
1754
|
+
* the callback function is the accumulated result, and is provided as an argument in the next
|
|
1755
|
+
* call to the callback function.
|
|
1756
|
+
* @param callbackfn A function that accepts up to four arguments. The reduce method calls the
|
|
1757
|
+
* callbackfn function one time for each element in the array.
|
|
1758
|
+
* @param initialValue If initialValue is specified, it is used as the initial value to start
|
|
1759
|
+
* the accumulation. The first call to the callbackfn function provides this value as an argument
|
|
1760
|
+
* instead of an array value.
|
|
1761
|
+
*/
|
|
1762
|
+
reduce<U$1>(callbackfn: (previousValue: U$1, currentValue: bigint, currentIndex: number, array: BigUint64Array$1) => U$1, initialValue: U$1): U$1;
|
|
1763
|
+
/**
|
|
1764
|
+
* Calls the specified callback function for all the elements in an array, in descending order.
|
|
1765
|
+
* The return value of the callback function is the accumulated result, and is provided as an
|
|
1766
|
+
* argument in the next call to the callback function.
|
|
1767
|
+
* @param callbackfn A function that accepts up to four arguments. The reduceRight method calls
|
|
1768
|
+
* the callbackfn function one time for each element in the array.
|
|
1769
|
+
* @param initialValue If initialValue is specified, it is used as the initial value to start
|
|
1770
|
+
* the accumulation. The first call to the callbackfn function provides this value as an
|
|
1771
|
+
* argument instead of an array value.
|
|
1772
|
+
*/
|
|
1773
|
+
reduceRight(callbackfn: (previousValue: bigint, currentValue: bigint, currentIndex: number, array: BigUint64Array$1) => bigint): bigint;
|
|
1774
|
+
/**
|
|
1775
|
+
* Calls the specified callback function for all the elements in an array, in descending order.
|
|
1776
|
+
* The return value of the callback function is the accumulated result, and is provided as an
|
|
1777
|
+
* argument in the next call to the callback function.
|
|
1778
|
+
* @param callbackfn A function that accepts up to four arguments. The reduceRight method calls
|
|
1779
|
+
* the callbackfn function one time for each element in the array.
|
|
1780
|
+
* @param initialValue If initialValue is specified, it is used as the initial value to start
|
|
1781
|
+
* the accumulation. The first call to the callbackfn function provides this value as an argument
|
|
1782
|
+
* instead of an array value.
|
|
1783
|
+
*/
|
|
1784
|
+
reduceRight<U$1>(callbackfn: (previousValue: U$1, currentValue: bigint, currentIndex: number, array: BigUint64Array$1) => U$1, initialValue: U$1): U$1;
|
|
1785
|
+
/** Reverses the elements in the array. */
|
|
1786
|
+
reverse(): this;
|
|
1787
|
+
/**
|
|
1788
|
+
* Sets a value or an array of values.
|
|
1789
|
+
* @param array A typed or untyped array of values to set.
|
|
1790
|
+
* @param offset The index in the current array at which the values are to be written.
|
|
1791
|
+
*/
|
|
1792
|
+
set(array: ArrayLike<bigint>, offset?: number): void;
|
|
1793
|
+
/**
|
|
1794
|
+
* Returns a section of an array.
|
|
1795
|
+
* @param start The beginning of the specified portion of the array.
|
|
1796
|
+
* @param end The end of the specified portion of the array.
|
|
1797
|
+
*/
|
|
1798
|
+
slice(start?: number, end?: number): BigUint64Array$1;
|
|
1799
|
+
/**
|
|
1800
|
+
* Determines whether the specified callback function returns true for any element of an array.
|
|
1801
|
+
* @param predicate A function that accepts up to three arguments. The some method calls the
|
|
1802
|
+
* predicate function for each element in the array until the predicate returns true, or until
|
|
1803
|
+
* the end of the array.
|
|
1804
|
+
* @param thisArg An object to which the this keyword can refer in the predicate function.
|
|
1805
|
+
* If thisArg is omitted, undefined is used as the this value.
|
|
1806
|
+
*/
|
|
1807
|
+
some(predicate: (value: bigint, index: number, array: BigUint64Array$1) => boolean, thisArg?: any): boolean;
|
|
1808
|
+
/**
|
|
1809
|
+
* Sorts the array.
|
|
1810
|
+
* @param compareFn The function used to determine the order of the elements. If omitted, the elements are sorted in ascending order.
|
|
1811
|
+
*/
|
|
1812
|
+
sort(compareFn?: (a: bigint, b: bigint) => number | bigint): this;
|
|
1813
|
+
/**
|
|
1814
|
+
* Gets a new BigUint64Array view of the ArrayBuffer store for this array, referencing the elements
|
|
1815
|
+
* at begin, inclusive, up to end, exclusive.
|
|
1816
|
+
* @param begin The index of the beginning of the array.
|
|
1817
|
+
* @param end The index of the end of the array.
|
|
1818
|
+
*/
|
|
1819
|
+
subarray(begin?: number, end?: number): BigUint64Array$1;
|
|
1820
|
+
/** Converts the array to a string by using the current locale. */
|
|
1821
|
+
toLocaleString(locales?: string | string[], options?: Intl.NumberFormatOptions): string;
|
|
1822
|
+
/** Returns a string representation of the array. */
|
|
1823
|
+
toString(): string;
|
|
1824
|
+
/** Returns the primitive value of the specified object. */
|
|
1825
|
+
valueOf(): BigUint64Array$1;
|
|
1826
|
+
/** Yields each value in the array. */
|
|
1827
|
+
values(): IterableIterator<bigint>;
|
|
1828
|
+
[Symbol.iterator](): IterableIterator<bigint>;
|
|
1829
|
+
readonly [Symbol.toStringTag]: "BigUint64Array";
|
|
1830
|
+
[index: number]: bigint;
|
|
1831
|
+
}
|
|
1832
|
+
interface BigIntToLocaleStringOptions {
|
|
1833
|
+
/**
|
|
1834
|
+
* The locale matching algorithm to use.The default is "best fit". For information about this option, see the {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_negotiation Intl page}.
|
|
1835
|
+
*/
|
|
1836
|
+
localeMatcher?: string;
|
|
1837
|
+
/**
|
|
1838
|
+
* The formatting style to use , the default is "decimal".
|
|
1839
|
+
*/
|
|
1840
|
+
style?: string;
|
|
1841
|
+
numberingSystem?: string;
|
|
1842
|
+
/**
|
|
1843
|
+
* The unit to use in unit formatting, Possible values are core unit identifiers, defined in UTS #35, Part 2, Section 6. A subset of units from the full list was selected for use in ECMAScript. Pairs of simple units can be concatenated with "-per-" to make a compound unit. There is no default value; if the style is "unit", the unit property must be provided.
|
|
1844
|
+
*/
|
|
1845
|
+
unit?: string;
|
|
1846
|
+
/**
|
|
1847
|
+
* The unit formatting style to use in unit formatting, the defaults is "short".
|
|
1848
|
+
*/
|
|
1849
|
+
unitDisplay?: string;
|
|
1850
|
+
/**
|
|
1851
|
+
* The currency to use in currency formatting. Possible values are the ISO 4217 currency codes, such as "USD" for the US dollar, "EUR" for the euro, or "CNY" for the Chinese RMB — see the Current currency & funds code list. There is no default value; if the style is "currency", the currency property must be provided. It is only used when [[Style]] has the value "currency".
|
|
1852
|
+
*/
|
|
1853
|
+
currency?: string;
|
|
1854
|
+
/**
|
|
1855
|
+
* How to display the currency in currency formatting. It is only used when [[Style]] has the value "currency". The default is "symbol".
|
|
1856
|
+
*
|
|
1857
|
+
* "symbol" to use a localized currency symbol such as €,
|
|
1858
|
+
*
|
|
1859
|
+
* "code" to use the ISO currency code,
|
|
1860
|
+
*
|
|
1861
|
+
* "name" to use a localized currency name such as "dollar"
|
|
1862
|
+
*/
|
|
1863
|
+
currencyDisplay?: string;
|
|
1864
|
+
/**
|
|
1865
|
+
* Whether to use grouping separators, such as thousands separators or thousand/lakh/crore separators. The default is true.
|
|
1866
|
+
*/
|
|
1867
|
+
useGrouping?: boolean;
|
|
1868
|
+
/**
|
|
1869
|
+
* The minimum number of integer digits to use. Possible values are from 1 to 21; the default is 1.
|
|
1870
|
+
*/
|
|
1871
|
+
minimumIntegerDigits?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21;
|
|
1872
|
+
/**
|
|
1873
|
+
* The minimum number of fraction digits to use. Possible values are from 0 to 20; the default for plain number and percent formatting is 0; the default for currency formatting is the number of minor unit digits provided by the {@link http://www.currency-iso.org/en/home/tables/table-a1.html ISO 4217 currency codes list} (2 if the list doesn't provide that information).
|
|
1874
|
+
*/
|
|
1875
|
+
minimumFractionDigits?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20;
|
|
1876
|
+
/**
|
|
1877
|
+
* The maximum number of fraction digits to use. Possible values are from 0 to 20; the default for plain number formatting is the larger of minimumFractionDigits and 3; the default for currency formatting is the larger of minimumFractionDigits and the number of minor unit digits provided by the {@link http://www.currency-iso.org/en/home/tables/table-a1.html ISO 4217 currency codes list} (2 if the list doesn't provide that information); the default for percent formatting is the larger of minimumFractionDigits and 0.
|
|
1878
|
+
*/
|
|
1879
|
+
maximumFractionDigits?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20;
|
|
1880
|
+
/**
|
|
1881
|
+
* The minimum number of significant digits to use. Possible values are from 1 to 21; the default is 1.
|
|
1882
|
+
*/
|
|
1883
|
+
minimumSignificantDigits?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21;
|
|
1884
|
+
/**
|
|
1885
|
+
* The maximum number of significant digits to use. Possible values are from 1 to 21; the default is 21.
|
|
1886
|
+
*/
|
|
1887
|
+
maximumSignificantDigits?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21;
|
|
1888
|
+
/**
|
|
1889
|
+
* The formatting that should be displayed for the number, the defaults is "standard"
|
|
1890
|
+
*
|
|
1891
|
+
* "standard" plain number formatting
|
|
1892
|
+
*
|
|
1893
|
+
* "scientific" return the order-of-magnitude for formatted number.
|
|
1894
|
+
*
|
|
1895
|
+
* "engineering" return the exponent of ten when divisible by three
|
|
1896
|
+
*
|
|
1897
|
+
* "compact" string representing exponent, defaults is using the "short" form
|
|
1898
|
+
*/
|
|
1899
|
+
notation?: string;
|
|
1900
|
+
/**
|
|
1901
|
+
* used only when notation is "compact"
|
|
1902
|
+
*/
|
|
1903
|
+
compactDisplay?: string;
|
|
1904
|
+
}
|
|
1905
|
+
/**
|
|
1906
|
+
* The `Any` class does not exist at runtime. It's used in type
|
|
1907
|
+
* definitions to detect an `any` type.
|
|
1908
|
+
*
|
|
1909
|
+
* ```ts
|
|
1910
|
+
* type IsAny<T> = [T] extends [Any] ? 'is any' : 'is not any'
|
|
1911
|
+
* ```
|
|
1912
|
+
*/
|
|
1913
|
+
declare class Any {
|
|
1914
|
+
private any;
|
|
1915
|
+
}
|
|
1916
|
+
/**
|
|
1917
|
+
* Represents a class constructor.
|
|
1918
|
+
*/
|
|
1919
|
+
|
|
1920
|
+
/**
|
|
1921
|
+
* Get all properties **not using** the `?:` type operator.
|
|
1922
|
+
*/
|
|
1923
|
+
type RequiredKeys<T> = T extends any ? keyof T extends infer K ? K extends keyof T ? Omit<T, K> extends T ? never : K : never : never : never;
|
|
1924
|
+
/**
|
|
1925
|
+
* Get all properties using the `?:` type operator.
|
|
1926
|
+
*/
|
|
1927
|
+
type OptionalKeys<T> = T extends any ? keyof T extends infer K ? K extends keyof T ? Omit<T, K> extends T ? K : never : never : never : never;
|
|
1928
|
+
/**
|
|
1929
|
+
* Resolves to `true` if `Left` and `Right` are exactly the same type.
|
|
1930
|
+
*
|
|
1931
|
+
* Otherwise false.
|
|
1932
|
+
*/
|
|
1933
|
+
type IsExactType<Left, Right> = [Left] extends [Any] ? [Right] extends [Any] ? true : false : (<U$1>() => U$1 extends Left ? 1 : 0) extends (<U$1>() => U$1 extends Right ? 1 : 0) ? true : false;
|
|
1934
|
+
type Primitive = number | string | boolean | symbol | bigint | null | undefined | void;
|
|
1935
|
+
/**
|
|
1936
|
+
* Coerce a primitive type to its boxed equivalent.
|
|
1937
|
+
*
|
|
1938
|
+
* @example
|
|
1939
|
+
* ```ts
|
|
1940
|
+
* type A = BoxedPrimitive<string>
|
|
1941
|
+
* // ^? String
|
|
1942
|
+
* type B = BoxedPrimitive<number>
|
|
1943
|
+
* // ^? Number
|
|
1944
|
+
* ```
|
|
1945
|
+
*/
|
|
1946
|
+
type BoxedPrimitive<T = any> = T extends string ? String : T extends number ? Number : T extends boolean ? Boolean : T extends bigint ? BigInt : T extends symbol ? Symbol : never;
|
|
1947
|
+
type TypedArray$1 = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array$1 | BigUint64Array$1 | DataView | ArrayBuffer | SharedArrayBuffer;
|
|
1948
|
+
/**
|
|
1949
|
+
* Add your own classes to this registry by extending its interface
|
|
1950
|
+
* with what's called “declaration merging” in TypeScript.
|
|
1951
|
+
*
|
|
1952
|
+
* All property types in this registry type may be treated specially
|
|
1953
|
+
* by any of Radashi's complex types. For example, `assign` will avoid
|
|
1954
|
+
* merging with types in this registry.
|
|
1955
|
+
*/
|
|
1956
|
+
interface CustomClassRegistry {}
|
|
1957
|
+
/**
|
|
1958
|
+
* This type represents any custom class that was "registered" through
|
|
1959
|
+
* the `CustomClassRegistry` type.
|
|
1960
|
+
*/
|
|
1961
|
+
type CustomClass = CustomClassRegistry[keyof CustomClassRegistry];
|
|
1962
|
+
/**
|
|
1963
|
+
* These types are implemented natively.
|
|
1964
|
+
*
|
|
1965
|
+
* Note that boxed primitives like `Boolean` (different from
|
|
1966
|
+
* `boolean`) are not included, because `boolean extends Boolean ? 1 :
|
|
1967
|
+
* 0` resolves to 1.
|
|
1968
|
+
*/
|
|
1969
|
+
type BuiltInType = ES2021.BuiltInType | WebAPI.BuiltInType | NodeJS.BuiltInType;
|
|
1970
|
+
declare namespace ES2020 {
|
|
1971
|
+
type BuiltInType = Primitive | Promise<any> | Date | RegExp | Error | readonly any[] | ReadonlyMap<any, any> | ReadonlySet<any> | WeakMap<WeakKey, any> | WeakSet<WeakKey> | TypedArray$1 | Function;
|
|
1972
|
+
}
|
|
1973
|
+
declare namespace ES2021 {
|
|
1974
|
+
type BuiltInType = ES2020.BuiltInType | GlobalObjectType<'FinalizationRegistry'> | GlobalObjectType<'WeakRef'>;
|
|
1975
|
+
}
|
|
1976
|
+
declare namespace NodeJS {
|
|
1977
|
+
type BuiltInType = GlobalObjectType<'Buffer'>;
|
|
1978
|
+
}
|
|
1979
|
+
declare namespace WebAPI {
|
|
1980
|
+
type BuiltInType = GlobalObjectType<'AbortController'> | GlobalObjectType<'AbortSignal'> | GlobalObjectType<'Blob'> | GlobalObjectType<'Body'> | GlobalObjectType<'CompressionStream'> | GlobalObjectType<'Crypto'> | GlobalObjectType<'CustomEvent'> | GlobalObjectType<'DecompressionStream'> | GlobalObjectType<'Event'> | GlobalObjectType<'EventTarget'> | GlobalObjectType<'FormData'> | GlobalObjectType<'Headers'> | GlobalObjectType<'MessageChannel'> | GlobalObjectType<'Navigator'> | GlobalObjectType<'ReadableStream'> | GlobalObjectType<'ReadableStreamBYOBReader'> | GlobalObjectType<'ReadableStreamDefaultController'> | GlobalObjectType<'ReadableStreamDefaultReader'> | GlobalObjectType<'SubtleCrypto'> | GlobalObjectType<'TextDecoder'> | GlobalObjectType<'TextDecoderStream'> | GlobalObjectType<'TextEncoder'> | GlobalObjectType<'TextEncoderStream'> | GlobalObjectType<'TransformStream'> | GlobalObjectType<'TransformStreamDefaultController'> | GlobalObjectType<'URL'> | GlobalObjectType<'URLSearchParams'> | GlobalObjectType<'WebSocket'> | GlobalObjectType<'WritableStream'> | GlobalObjectType<'WritableStreamDefaultController'> | GlobalObjectType<'WritableStreamDefaultWriter'> | WebDocumentAPI.BuiltInType;
|
|
1981
|
+
}
|
|
1982
|
+
declare namespace WebDocumentAPI {
|
|
1983
|
+
type BuiltInType = GlobalObjectType<'Node'> | GlobalObjectType<'NodeList'> | GlobalObjectType<'NodeIterator'> | GlobalObjectType<'HTMLCollection'> | GlobalObjectType<'CSSStyleDeclaration'> | GlobalObjectType<'DOMStringList'> | GlobalObjectType<'DOMTokenList'>;
|
|
1984
|
+
}
|
|
1985
|
+
type GlobalObjectType<Identifier extends string> = [Identifier] extends [Any] ? never : keyof Identifier extends never ? never : typeof globalThis extends { [P in Identifier]: any } ? InstanceType<(typeof globalThis)[Identifier]> : never;
|
|
1986
|
+
|
|
1987
|
+
/**
|
|
1988
|
+
* Converts a `PromiseLike` to a `Promise<Result>`.
|
|
1989
|
+
*
|
|
1990
|
+
* Note: If the given promise throws a non-Error value, it will be
|
|
1991
|
+
* rethrown.
|
|
1992
|
+
*
|
|
1993
|
+
* @see https://radashi.js.org/reference/async/toResult
|
|
1994
|
+
* @example
|
|
1995
|
+
* ```ts
|
|
1996
|
+
* import { toResult, Result } from 'radashi'
|
|
1997
|
+
*
|
|
1998
|
+
* const good = async (): Promise<number> => 1
|
|
1999
|
+
* const bad = async (): Promise<number> => { throw new Error('bad') }
|
|
2000
|
+
*
|
|
2001
|
+
* const goodResult = await toResult(good())
|
|
2002
|
+
* // => [undefined, 1]
|
|
2003
|
+
*
|
|
2004
|
+
* const badResult = await toResult(bad())
|
|
2005
|
+
* // => [Error('bad'), undefined]
|
|
2006
|
+
* ```
|
|
2007
|
+
* @version 12.4.0
|
|
2008
|
+
*/
|
|
2009
|
+
|
|
2010
|
+
/**
|
|
2011
|
+
* The return type for `assign`.
|
|
2012
|
+
*
|
|
2013
|
+
* It recursively merges object types that are not native objects. The
|
|
2014
|
+
* root objects are always merged.
|
|
2015
|
+
*
|
|
2016
|
+
* @see https://radashi.js.org/reference/object/assign
|
|
2017
|
+
*/
|
|
2018
|
+
type Assign<TInitial extends object, TOverride extends object> = TInitial extends any ? TOverride extends any ? SimplifyMutable<Omit<TInitial, keyof TOverride> & Omit<TOverride, keyof TInitial> & (Pick<TInitial, keyof TInitial & keyof TOverride> extends infer TConflictInitial ? Pick<TOverride, keyof TInitial & keyof TOverride> extends infer TConflictOverride ? { [K in RequiredKeys<TConflictOverride>]: AssignDeep<TConflictInitial[K & keyof TConflictInitial], TConflictOverride[K]> } & { [K in RequiredKeys<TConflictInitial> & OptionalKeys<TConflictOverride>]: AssignDeep<TConflictInitial[K], TConflictOverride[K], true> } & { [K in OptionalKeys<TConflictInitial> & OptionalKeys<TConflictOverride>]?: AssignDeep<TConflictInitial[K], TConflictOverride[K], true> } : unknown : unknown)> : never : never;
|
|
2019
|
+
/**
|
|
2020
|
+
* Mimic the `Simplify` type and also remove `readonly` modifiers.
|
|
2021
|
+
*/
|
|
2022
|
+
type SimplifyMutable<T> = {} & { -readonly [P in keyof T]: T[P] };
|
|
2023
|
+
/**
|
|
2024
|
+
* This represents a value that should only be replaced if it exists
|
|
2025
|
+
* as an initial value; never deeply assigned into.
|
|
2026
|
+
*/
|
|
2027
|
+
type AtomicValue = BuiltInType | CustomClass | BoxedPrimitive;
|
|
2028
|
+
/**
|
|
2029
|
+
* Handle mixed types when merging nested plain objects.
|
|
2030
|
+
*
|
|
2031
|
+
* For example, if the type `TOverride` includes both `string` and `{ n:
|
|
2032
|
+
* number }` in a union, `AssignDeep` will treat `string` as
|
|
2033
|
+
* unmergeable and `{ n: number }` as mergeable.
|
|
2034
|
+
*/
|
|
2035
|
+
type AssignDeep<TInitial, TOverride, IsOptional = false> = never
|
|
2036
|
+
/**
|
|
2037
|
+
* When a native type is found in TInitial, it will only exist in
|
|
2038
|
+
* the result type if the override is optional.
|
|
2039
|
+
*/ | (TInitial extends AtomicValue ? IsOptional extends true ? TInitial : never : never)
|
|
2040
|
+
/**
|
|
2041
|
+
* When a native type is found in TOverride, it will always exists
|
|
2042
|
+
* in the result type.
|
|
2043
|
+
*/ | (TOverride extends AtomicValue ? TOverride : never)
|
|
2044
|
+
/**
|
|
2045
|
+
* Deep assignment is handled in this branch.
|
|
2046
|
+
*
|
|
2047
|
+
* 1. Exclude any native types from TInitial and TOverride
|
|
2048
|
+
* 2. If a non-native object type is not found in TInitial, simply
|
|
2049
|
+
* replace TInitial (or use "A | B" if the override is optional)
|
|
2050
|
+
* 3. For each non-native object type in TOverride, deep assign to
|
|
2051
|
+
* every non-native object in TInitial
|
|
2052
|
+
* 4. For each non-object type in TOverride, simply replace TInitial
|
|
2053
|
+
* (or use "A | B" if the override is optional)
|
|
2054
|
+
*/ | (Exclude<TOverride, AtomicValue> extends infer TOverride ? Exclude<TInitial, Exclude<AtomicValue, void>> extends infer TInitial ? [Extract<TInitial, object>] extends [never] ? TOverride | (IsOptional extends true ? TInitial : never) : TInitial extends object ? TOverride extends object ? IsExactType<TOverride, TInitial> extends true ? TOverride : Assign<TInitial, TOverride> :
|
|
2055
|
+
// 4.
|
|
2056
|
+
TOverride | (IsOptional extends true ? TInitial : never) : Extract<TOverride, object> | (IsOptional extends true ? TInitial : never) : never : never);
|
|
2057
|
+
|
|
2058
|
+
/**
|
|
2059
|
+
* Creates a shallow copy of the given object/value.
|
|
2060
|
+
*
|
|
2061
|
+
* @see https://radashi.js.org/reference/object/clone
|
|
2062
|
+
* @example
|
|
2063
|
+
* ```ts
|
|
2064
|
+
* const original = { a: 1, b: { c: 3 } }
|
|
2065
|
+
* const cloned = clone(original)
|
|
2066
|
+
* // => { a: 1, b: { c: 3 } }
|
|
2067
|
+
* original !== cloned
|
|
2068
|
+
* // => true
|
|
2069
|
+
* original.b === cloned.b
|
|
2070
|
+
* // => true
|
|
2071
|
+
* ```
|
|
2072
|
+
* @version 12.1.0
|
|
2073
|
+
*/
|
|
2074
|
+
//#endregion
|
|
2075
|
+
//#region src/utils/object/objectAssign.d.ts
|
|
2076
|
+
/**
|
|
2077
|
+
* 递归地将第二个对象合并到第一个对象的副本中
|
|
2078
|
+
* - 只有普通对象才会递归合并
|
|
2079
|
+
*
|
|
2080
|
+
* @param initial 初始对象
|
|
2081
|
+
* @param override 待合并对象
|
|
2082
|
+
*/
|
|
2083
|
+
declare function objectAssign<I$1 extends PlainObject, O extends PlainObject>(initial: I$1, override: O): Assign<I$1, O>;
|
|
2084
|
+
//#endregion
|
|
2085
|
+
//#region src/utils/object/objectCrush.d.ts
|
|
2086
|
+
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>>;
|
|
2087
|
+
declare function objectCrush<T extends PlainObject>(value: T): Crush<T>;
|
|
2088
|
+
//#endregion
|
|
2089
|
+
//#region src/utils/object/objectEntries.d.ts
|
|
2090
|
+
/**
|
|
2091
|
+
* 返回对象的可枚举属性的键/值数组
|
|
2092
|
+
*
|
|
2093
|
+
* @param obj 对象
|
|
2094
|
+
*/
|
|
2095
|
+
declare function objectEntries<O extends AnyObject>(obj: O): [string & keyof O, O[keyof O]][];
|
|
2096
|
+
//#endregion
|
|
2097
|
+
//#region src/utils/object/objectKeys.d.ts
|
|
2098
|
+
/**
|
|
2099
|
+
* 返回对象的可枚举属性和方法的名称
|
|
2100
|
+
* - `Object.keys` 始终返回 `string[]` 类型,此函数可以返回具体类型
|
|
2101
|
+
*
|
|
2102
|
+
* @param obj 对象
|
|
2103
|
+
*/
|
|
2104
|
+
declare function objectKeys<O extends AnyObject>(obj: O): (keyof O)[];
|
|
2105
|
+
//#endregion
|
|
2106
|
+
//#region src/utils/object/objectPick.d.ts
|
|
2107
|
+
declare function objectPick<O extends AnyObject, K$1 extends keyof O>(obj: O, keys: readonly K$1[]): Pick<O, K$1>;
|
|
2108
|
+
//#endregion
|
|
2109
|
+
//#region src/utils/object/objectSwitch.d.ts
|
|
2110
|
+
/**
|
|
2111
|
+
* 对象反转
|
|
2112
|
+
* - 返回交换了对象的可枚举属性的值/键对象
|
|
2113
|
+
*
|
|
2114
|
+
* @param obj 对象
|
|
2115
|
+
*/
|
|
2116
|
+
declare function objectSwitch<O extends AnyObject>(obj: NonEmptyObject<O>): Record<O[keyof O], keyof O>;
|
|
2117
|
+
//#endregion
|
|
2118
|
+
//#region src/utils/object/objectValues.d.ts
|
|
2119
|
+
/**
|
|
2120
|
+
* 返回对象的可枚举属性的值数组
|
|
2121
|
+
*
|
|
2122
|
+
* @param obj 对象
|
|
2123
|
+
*/
|
|
2124
|
+
declare function objectValues<O extends AnyObject>(obj: O): UnionToTuple<ValueOf<O>>;
|
|
2125
|
+
//#endregion
|
|
2126
|
+
//#region src/utils/string/stringInitialCase.d.ts
|
|
2127
|
+
/**
|
|
2128
|
+
* 字符串首字母大小写
|
|
2129
|
+
* - 包含非西欧字母字符时,不处理
|
|
2130
|
+
* - 纯字母且全大写时,不处理
|
|
2131
|
+
* - 纯字母且非全大写时,首字母小写,其余保留
|
|
2132
|
+
* - 纯字母且非全大写时,首字母大写,其余保留
|
|
2133
|
+
*
|
|
2134
|
+
* @param input 待处理字符串
|
|
2135
|
+
* @param caseType 大小写类型
|
|
2136
|
+
*/
|
|
2137
|
+
declare function stringInitialCase(input: string, caseType?: "lower" | "upper" | undefined): string;
|
|
2138
|
+
//#endregion
|
|
2139
|
+
//#region src/utils/string/stringReplace.d.ts
|
|
2140
|
+
/**
|
|
2141
|
+
* 字符串替换
|
|
2142
|
+
* - 替换第一个匹配项
|
|
2143
|
+
*
|
|
2144
|
+
* @param input 待处理字符串
|
|
2145
|
+
* @param search 匹配项
|
|
2146
|
+
* @param replacement 替换项
|
|
2147
|
+
*/
|
|
2148
|
+
declare function stringReplace<I$1 extends string, S extends string, R$1 extends string>(input: I$1, search: S, replacement: R$1): Replace<I$1, S, R$1>;
|
|
2149
|
+
//#endregion
|
|
2150
|
+
//#region src/utils/string/stringTemplate.d.ts
|
|
2151
|
+
/**
|
|
2152
|
+
* 字符串模板替换
|
|
2153
|
+
*
|
|
2154
|
+
* @param input 待处理字符串
|
|
2155
|
+
* @param template 模板对象
|
|
2156
|
+
* @param regex 模板匹配正则
|
|
2157
|
+
*/
|
|
2158
|
+
declare function stringTemplate(input: string, template: PlainObject, regex?: RegExp): string;
|
|
2159
|
+
//#endregion
|
|
2160
|
+
//#region src/utils/string/stringToJson.d.ts
|
|
2161
|
+
/**
|
|
2162
|
+
* 处理 JSON 字符串
|
|
2163
|
+
*
|
|
2164
|
+
* @param input 待处理字符串
|
|
2165
|
+
* @param safeValue 安全值
|
|
2166
|
+
*/
|
|
2167
|
+
declare function stringToJson<R$1 extends AnyObject = AnyObject, D extends R$1 = R$1>(input: string | null | undefined, safeValue: D): R$1;
|
|
2168
|
+
//#endregion
|
|
2169
|
+
//#region src/utils/string/stringToNumber.d.ts
|
|
2170
|
+
/**
|
|
2171
|
+
* 从字符串中提取数字字符串
|
|
2172
|
+
*
|
|
2173
|
+
* @param input 待处理字符串
|
|
2174
|
+
*/
|
|
2175
|
+
declare function stringToNumber(input: string): string;
|
|
2176
|
+
//#endregion
|
|
2177
|
+
//#region src/utils/string/stringToPosix.d.ts
|
|
2178
|
+
/**
|
|
2179
|
+
* 将路径转换为 POSIX 风格
|
|
2180
|
+
*
|
|
2181
|
+
* @param input 待处理字符串
|
|
2182
|
+
*/
|
|
2183
|
+
declare function stringToPosix(input: string | null | undefined): string;
|
|
2184
|
+
//#endregion
|
|
2185
|
+
//#region src/utils/string/stringToValues.d.ts
|
|
2186
|
+
/**
|
|
2187
|
+
* 字符串分割为数组
|
|
2188
|
+
*
|
|
2189
|
+
* @param input 待处理字符串
|
|
2190
|
+
* @param valueType 数组中每一项的类型
|
|
2191
|
+
* @param splitSymbol 分隔符,默认为 `,`
|
|
2192
|
+
*/
|
|
2193
|
+
declare function stringToValues(input: string | null | undefined, valueType?: "number" | undefined, splitSymbol?: string | undefined): number[];
|
|
2194
|
+
declare function stringToValues(input: string | null | undefined, valueType: "string", splitSymbol?: string | undefined): string[];
|
|
2195
|
+
//#endregion
|
|
2196
|
+
//#region src/utils/string/stringTrim.d.ts
|
|
2197
|
+
/**
|
|
2198
|
+
* 从字符串中裁切掉所有的前缀和后缀字符
|
|
2199
|
+
*
|
|
2200
|
+
* @param input 待处理字符串
|
|
2201
|
+
* @param charsToTrim 裁切字符,默认为 `" "`
|
|
2202
|
+
*/
|
|
2203
|
+
declare function stringTrim(input: string | null | undefined, charsToTrim?: string): string;
|
|
2204
|
+
//#endregion
|
|
2205
|
+
//#region src/utils/string/stringTruncate.d.ts
|
|
2206
|
+
/**
|
|
2207
|
+
* 截取字符串
|
|
2208
|
+
* - 支持中英文混排,不会在汉字中间截断
|
|
2209
|
+
*
|
|
2210
|
+
* @param input 待处理字符串
|
|
2211
|
+
* @param maxLength 最大长度
|
|
2212
|
+
* @param ellipsis 省略符,默认为 `...`
|
|
2213
|
+
*/
|
|
2214
|
+
declare function stringTruncate(input: string, maxLength: number, ellipsis?: string): string;
|
|
2215
|
+
//#endregion
|
|
2216
|
+
//#region src/utils/tree/types.d.ts
|
|
2217
|
+
type RowKey = "id";
|
|
2218
|
+
type ParentIdKey = "parentId";
|
|
2219
|
+
type ChildrenKey = "children";
|
|
2220
|
+
type Strategy = "pre" | "post" | "breadth";
|
|
2221
|
+
interface BaseCallbackMeta<T> {
|
|
2222
|
+
depth: number;
|
|
2223
|
+
parents?: T[];
|
|
2224
|
+
}
|
|
2225
|
+
interface BaseOptions<T, CK extends string> {
|
|
2226
|
+
childrenKey?: CK;
|
|
2227
|
+
strategy?: Strategy;
|
|
2228
|
+
getChildrenKey?: ((row: T, meta: BaseCallbackMeta<T>) => CK) | undefined;
|
|
2229
|
+
}
|
|
2230
|
+
//#endregion
|
|
2231
|
+
//#region src/utils/tree/treeFilter.d.ts
|
|
2232
|
+
type TreeFilterOptions<T extends AnyObject, CK extends string = ChildrenKey> = BaseOptions<T, CK>;
|
|
2233
|
+
type TreeFilterCallback<T extends AnyObject> = (row: T, meta: BaseCallbackMeta<T>) => boolean;
|
|
2234
|
+
declare function treeFilter<T extends AnyObject, CK extends string = ChildrenKey>(tree: T[], callback: TreeFilterCallback<T>, options?: TreeFilterOptions<T, CK>): T[];
|
|
2235
|
+
declare function treeFilter<T extends AnyObject, CK extends string = ChildrenKey>(tree: T, callback: TreeFilterCallback<T>, options?: TreeFilterOptions<T, CK>): T;
|
|
2236
|
+
//#endregion
|
|
2237
|
+
//#region src/utils/tree/treeFind.d.ts
|
|
2238
|
+
type TreeFindOptions<T extends AnyObject, CK extends string = ChildrenKey> = BaseOptions<T, CK>;
|
|
2239
|
+
type TreeFindCallback<T extends AnyObject> = (row: T, meta: BaseCallbackMeta<T>) => boolean;
|
|
2240
|
+
/**
|
|
2241
|
+
* 查找树节点,找到第一个返回非空值的节点
|
|
2242
|
+
*/
|
|
2243
|
+
declare function treeFind<T extends AnyObject, CK extends string = ChildrenKey>(tree: T | T[], callback: TreeFindCallback<T>, options?: TreeFindOptions<T, CK>): T | undefined;
|
|
2244
|
+
//#endregion
|
|
2245
|
+
//#region src/utils/tree/treeForEach.d.ts
|
|
2246
|
+
type TreeForeachOptions<T extends AnyObject, CK extends string = ChildrenKey> = BaseOptions<T, CK>;
|
|
2247
|
+
type TreeForeachCallback<T extends AnyObject> = (row: T, meta: BaseCallbackMeta<T>) => void;
|
|
2248
|
+
declare function treeForEach<T extends AnyObject, CK extends string = ChildrenKey>(tree: T | T[], callback: TreeForeachCallback<T>, options?: TreeForeachOptions<T, CK>): void;
|
|
2249
|
+
//#endregion
|
|
2250
|
+
//#region src/utils/tree/treeMap.d.ts
|
|
2251
|
+
type TreeMapOptions<T extends AnyObject, CK extends string> = BaseOptions<T, CK>;
|
|
2252
|
+
type TreeMapCallback<R$1 extends AnyObject, T extends AnyObject> = (row: T, meta: BaseCallbackMeta<T>) => R$1;
|
|
2253
|
+
declare function treeMap<R$1 extends AnyObject, T extends AnyObject, CK extends string = ChildrenKey>(tree: T[], callback: TreeMapCallback<R$1, T>, options?: TreeMapOptions<T, CK>): TreeLike<R$1, CK>[];
|
|
2254
|
+
declare function treeMap<R$1 extends AnyObject, T extends AnyObject, CK extends string = ChildrenKey>(tree: T, callback: TreeMapCallback<R$1, T>, options?: TreeMapOptions<T, CK>): TreeLike<R$1, CK>;
|
|
2255
|
+
//#endregion
|
|
2256
|
+
//#region src/utils/tree/rowsToTree.d.ts
|
|
2257
|
+
interface RowsToTreeOptions<RK extends string = RowKey, PK extends string = ParentIdKey, CK extends string = ChildrenKey> {
|
|
2258
|
+
rowKey?: RK;
|
|
2259
|
+
parentIdKey?: PK;
|
|
2260
|
+
childrenKey?: CK;
|
|
2261
|
+
}
|
|
2262
|
+
/**
|
|
2263
|
+
* 行结构 转 树结构
|
|
2264
|
+
*/
|
|
2265
|
+
declare function rowsToTree<T extends AnyObject = AnyObject, CK extends string = ChildrenKey, R$1 = TreeLike<T, CK>, RK extends string = RowKey, PK extends string = ParentIdKey>(rows: T[], options?: RowsToTreeOptions<RK, PK, CK> | undefined): R$1[];
|
|
2266
|
+
//#endregion
|
|
2267
|
+
//#region src/utils/tree/treeToRows.d.ts
|
|
2268
|
+
type TreeToRowsOptions<T extends AnyObject, CK extends string = ChildrenKey> = TreeForeachOptions<T, CK>;
|
|
2269
|
+
/**
|
|
2270
|
+
* 树结构 转 行结构
|
|
2271
|
+
*/
|
|
2272
|
+
declare function treeToRows<T extends AnyObject, CK extends string = ChildrenKey, R$1 extends AnyObject = SetOptional<T, CK>>(tree: T | T[], options?: TreeToRowsOptions<T, CK>): R$1[];
|
|
2273
|
+
//#endregion
|
|
2274
|
+
//#region src/utils/typeof/isAbortSignal.d.ts
|
|
2275
|
+
declare function isAbortSignal(value: unknown): value is AbortSignal;
|
|
2276
|
+
//#endregion
|
|
2277
|
+
//#region src/utils/typeof/isArray.d.ts
|
|
2278
|
+
type TypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array;
|
|
2279
|
+
declare function isArray(value: unknown): value is unknown[];
|
|
2280
|
+
declare function isTypedArray(value: unknown): value is TypedArray;
|
|
2281
|
+
//#endregion
|
|
2282
|
+
//#region src/utils/typeof/isBigInt.d.ts
|
|
2283
|
+
declare function isBigInt(value: unknown): value is bigint;
|
|
2284
|
+
//#endregion
|
|
2285
|
+
//#region src/utils/typeof/isBlob.d.ts
|
|
2286
|
+
declare function isBlob(value: unknown): value is Blob;
|
|
2287
|
+
//#endregion
|
|
2288
|
+
//#region src/utils/typeof/isBoolean.d.ts
|
|
2289
|
+
declare function isBoolean(value: unknown): value is boolean;
|
|
2290
|
+
//#endregion
|
|
2291
|
+
//#region src/utils/typeof/isClass.d.ts
|
|
2292
|
+
declare function isClass(value: unknown): value is Class<AnyObject>;
|
|
2293
|
+
//#endregion
|
|
2294
|
+
//#region src/utils/typeof/isDate.d.ts
|
|
2295
|
+
declare function isDate(value: unknown): value is Date;
|
|
2296
|
+
//#endregion
|
|
2297
|
+
//#region src/utils/typeof/isEqual.d.ts
|
|
2298
|
+
/**
|
|
2299
|
+
* 检查给定的值是否相等
|
|
2300
|
+
* @reference https://github.com/radashi-org/radashi/blob/main/src/typed/isEqual.ts
|
|
2301
|
+
*
|
|
2302
|
+
* @param {T} x
|
|
2303
|
+
* @param {T} y
|
|
2304
|
+
*/
|
|
2305
|
+
declare function isEqual<T>(x: T, y: T): boolean;
|
|
2306
|
+
//#endregion
|
|
2307
|
+
//#region src/utils/typeof/isError.d.ts
|
|
2308
|
+
declare function isError(value: unknown): value is Error;
|
|
2309
|
+
//#endregion
|
|
2310
|
+
//#region src/utils/typeof/isFalsy.d.ts
|
|
2311
|
+
declare function isFalsy(value: unknown): boolean;
|
|
2312
|
+
declare function isFalsyLike(value: unknown): boolean;
|
|
2313
|
+
//#endregion
|
|
2314
|
+
//#region src/utils/typeof/isFile.d.ts
|
|
2315
|
+
declare function isFile(value: unknown): value is File;
|
|
2316
|
+
//#endregion
|
|
2317
|
+
//#region src/utils/typeof/isFunction.d.ts
|
|
2318
|
+
declare function isFunction(value: unknown): value is AnyFunction;
|
|
2319
|
+
declare function isAsyncFunction(value: unknown): value is AnyAsyncFunction;
|
|
2320
|
+
declare function isGeneratorFunction(value: unknown): value is AnyGeneratorFunction;
|
|
2321
|
+
declare function isAsyncGeneratorFunction(value: unknown): value is AnyAsyncGeneratorFunction;
|
|
2322
|
+
//#endregion
|
|
2323
|
+
//#region src/utils/typeof/isIterable.d.ts
|
|
2324
|
+
declare function isIterable(value: unknown): value is {
|
|
2325
|
+
[Symbol.iterator]: () => Iterator<unknown>;
|
|
2326
|
+
};
|
|
2327
|
+
//#endregion
|
|
2328
|
+
//#region src/utils/typeof/isMap.d.ts
|
|
2329
|
+
declare function isMap(value: unknown): value is Map<unknown, unknown>;
|
|
2330
|
+
declare function isWeakMap(value: unknown): value is WeakMap<AnyObject, unknown>;
|
|
2331
|
+
//#endregion
|
|
2332
|
+
//#region src/utils/typeof/isNull.d.ts
|
|
2333
|
+
declare function isNull(value: unknown): value is null;
|
|
2334
|
+
//#endregion
|
|
2335
|
+
//#region src/utils/typeof/isNumber.d.ts
|
|
2336
|
+
/**
|
|
2337
|
+
* 检查 value 是否为 number 类型
|
|
2338
|
+
*
|
|
2339
|
+
* @param value 待检查值
|
|
2340
|
+
* @param checkNaN 是否排除 `NaN`,默认为 `true`
|
|
2341
|
+
*/
|
|
2342
|
+
declare function isNumber(value: unknown, checkNaN?: boolean): value is number;
|
|
2343
|
+
/**
|
|
2344
|
+
* 检查 value 是否为 NaN
|
|
2345
|
+
*
|
|
2346
|
+
* @param value 待检查值
|
|
2347
|
+
*/
|
|
2348
|
+
declare function isNaN(value: unknown): value is number;
|
|
2349
|
+
/**
|
|
2350
|
+
* 检查 value 是否为整数
|
|
2351
|
+
*
|
|
2352
|
+
* @param value 待检查值
|
|
2353
|
+
* @param safeCheck 是否附加安全数检查
|
|
2354
|
+
*/
|
|
2355
|
+
declare function isInteger(value: unknown, safeCheck?: boolean): value is number;
|
|
2356
|
+
/**
|
|
2357
|
+
* 检查 value 是否为正整数
|
|
2358
|
+
* - 此函数中 `0` 不被视为正整数
|
|
2359
|
+
*
|
|
2360
|
+
* @param value 待检查值
|
|
2361
|
+
* @param safeCheck 是否附加安全数检查
|
|
2362
|
+
*/
|
|
2363
|
+
declare function isPositiveInteger(value: unknown, safeCheck?: boolean): value is number;
|
|
2364
|
+
/**
|
|
2365
|
+
* 检查 value 是否为负整数
|
|
2366
|
+
* - 此函数中 `0` 不被视为负整数
|
|
2367
|
+
*
|
|
2368
|
+
* @param value 待检查值
|
|
2369
|
+
* @param safeCheck 是否附加安全数检查
|
|
2370
|
+
*/
|
|
2371
|
+
declare function isNegativeInteger(value: unknown, safeCheck?: boolean): value is number;
|
|
2372
|
+
/**
|
|
2373
|
+
* 检查 value 是否为 Infinity
|
|
2374
|
+
* - 排除 `NaN`
|
|
2375
|
+
*
|
|
2376
|
+
* @param value 待检查值
|
|
2377
|
+
*/
|
|
2378
|
+
declare function isInfinity(value: unknown): value is number;
|
|
2379
|
+
/**
|
|
2380
|
+
* 检查 value 是否类似 Infinity
|
|
2381
|
+
* - 排除 `NaN`
|
|
2382
|
+
*
|
|
2383
|
+
* @param value 待检查值
|
|
2384
|
+
*/
|
|
2385
|
+
declare function isInfinityLike(value: unknown): boolean;
|
|
2386
|
+
//#endregion
|
|
2387
|
+
//#region src/utils/typeof/isObject.d.ts
|
|
2388
|
+
/**
|
|
2389
|
+
* 判断是否为对象类型
|
|
2390
|
+
* - 可选是否检查原型为 `Object.prototype`,防止原型链污染
|
|
2391
|
+
*
|
|
2392
|
+
* @param value 待检查值
|
|
2393
|
+
* @param prototypeCheck 是否进行原型检查,默认 `true`
|
|
2394
|
+
*/
|
|
2395
|
+
declare function isObject(value: unknown, prototypeCheck?: boolean): value is Record<PropertyKey, unknown>;
|
|
2396
|
+
//#endregion
|
|
2397
|
+
//#region src/utils/typeof/isPromise.d.ts
|
|
2398
|
+
declare function isPromise(value: unknown): value is Promise<unknown>;
|
|
2399
|
+
declare function isPromiseLike(value: unknown): value is PromiseLike<unknown>;
|
|
2400
|
+
//#endregion
|
|
2401
|
+
//#region src/utils/typeof/isReadableStream.d.ts
|
|
2402
|
+
/**
|
|
2403
|
+
* Checks if a value is a WHATWG ReadableStream instance.
|
|
2404
|
+
*
|
|
2405
|
+
* - Uses `Object.prototype.toString` where supported (modern browsers, Node.js ≥18).
|
|
2406
|
+
* - Falls back to duck-typing in older environments.
|
|
2407
|
+
* - Resistant to basic forgery, but not 100% secure in all polyfill scenarios.
|
|
2408
|
+
*
|
|
2409
|
+
* ⚠️ Note: In older Node.js (<18) or with non-compliant polyfills, this may return false positives or negatives.
|
|
2410
|
+
*/
|
|
2411
|
+
declare function isReadableStream(value: unknown): value is ReadableStream;
|
|
2412
|
+
//#endregion
|
|
2413
|
+
//#region src/utils/typeof/isRegExp.d.ts
|
|
2414
|
+
declare function isRegExp(value: unknown): value is RegExp;
|
|
2415
|
+
//#endregion
|
|
2416
|
+
//#region src/utils/typeof/isSet.d.ts
|
|
2417
|
+
declare function isSet(value: unknown): value is Set<unknown>;
|
|
2418
|
+
declare function isWeakSet(value: unknown): value is WeakSet<AnyObject>;
|
|
2419
|
+
//#endregion
|
|
2420
|
+
//#region src/utils/typeof/isString.d.ts
|
|
2421
|
+
/**
|
|
2422
|
+
* 检查 value 是否为 string 类型
|
|
2423
|
+
*
|
|
2424
|
+
* @param value 待检查值
|
|
2425
|
+
* @param checkEmpty 是否排除空字符串
|
|
2426
|
+
*/
|
|
2427
|
+
declare function isString(value: unknown, checkEmpty?: boolean): value is string;
|
|
2428
|
+
//#endregion
|
|
2429
|
+
//#region src/utils/typeof/isSymbol.d.ts
|
|
2430
|
+
declare function isSymbol(value: unknown): value is symbol;
|
|
2431
|
+
//#endregion
|
|
2432
|
+
//#region src/utils/typeof/isUndefined.d.ts
|
|
2433
|
+
declare function isUndefined(value: unknown): value is undefined;
|
|
2434
|
+
//#endregion
|
|
2435
|
+
//#region src/utils/typeof/isURLSearchParams.d.ts
|
|
2436
|
+
declare function isURLSearchParams(value: unknown): value is URLSearchParams;
|
|
2437
|
+
//#endregion
|
|
2438
|
+
//#region src/utils/typeof/isWebSocket.d.ts
|
|
2439
|
+
declare function isWebSocket(value: unknown): value is WebSocket;
|
|
2440
|
+
//#endregion
|
|
2441
|
+
//#region src/utils/typeof/isWindow.d.ts
|
|
2442
|
+
declare function isWindow(value: unknown): value is Window;
|
|
2443
|
+
//#endregion
|
|
2444
|
+
export { arrayCast, arrayCompete, arrayCounting, arrayDifference, arrayFirst, arrayFork, arrayIntersection, arrayLast, arrayMerge, arrayPick, arrayReplace, arraySplit, cloneDeep, enumEntries, enumKeys, enumTypeCheck, enumValues, isAbortSignal, isArray, isAsyncFunction, isAsyncGeneratorFunction, isBigInt, isBlob, isBoolean, isClass, isDate, isEqual, isError, isFalsy, isFalsyLike, isFile, isFunction, isGeneratorFunction, isInfinity, isInfinityLike, isInteger, isIterable, isMap, isNaN, isNegativeInteger, isNull, isNumber, isObject, isPositiveInteger, isPromise, isPromiseLike, isReadableStream, isRegExp, isSet, isString, isSymbol, isTypedArray, isURLSearchParams, isUndefined, isWeakMap, isWeakSet, isWebSocket, isWindow, mapEntries, objectAssign, objectCrush, objectEntries, objectKeys, objectPick, objectSwitch, objectValues, rowsToTree, stringInitialCase, stringReplace, stringTemplate, stringToJson, stringToNumber, stringToPosix, stringToValues, stringTrim, stringTruncate, to, toMathBignumber, toMathDecimal, toMathEvaluate, treeFilter, treeFind, treeForEach, treeMap, treeToRows };
|
|
2445
|
+
//# sourceMappingURL=index.d.ts.map
|