@pawover/kit 0.4.1 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +141 -30
- package/packages/hooks/dist/alova.cjs +53 -0
- package/packages/hooks/dist/alova.d.cts +1 -0
- package/packages/hooks/dist/index.cjs +0 -0
- package/packages/hooks/dist/index.d.cts +1 -0
- package/packages/hooks/dist/react.cjs +169 -0
- package/packages/hooks/dist/react.d.cts +1 -0
- package/packages/hooks/dist/react.d.ts +2 -60
- package/packages/hooks/dist/react.js +2 -2428
- package/packages/utils/dist/index.cjs +2300 -0
- package/packages/utils/dist/index.d.cts +1 -0
- package/packages/utils/dist/index.d.ts +157 -2712
- package/packages/utils/dist/index.js +122 -35
- package/packages/utils/dist/math-BznvO4qI.cjs +1029 -0
- package/packages/utils/dist/{math-Cvy9HBP0.js → math-DRbCtLQH.js} +44 -27
- package/packages/utils/dist/math.cjs +3 -0
- package/packages/utils/dist/math.d.cts +1 -0
- package/packages/utils/dist/math.d.ts +3 -0
- package/packages/utils/dist/math.js +1 -1
- package/packages/utils/dist/vite.cjs +44 -0
- package/packages/utils/dist/vite.d.cts +1 -0
- package/packages/utils/dist/vite.js +12 -8
- package/packages/zod/dist/index.cjs +91 -0
- package/packages/zod/dist/index.d.cts +1 -0
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import { MathJsInstance } from "mathjs";
|
|
2
|
+
import { Except, If, IsAny, Replace, Simplify, Split, Trim, TupleOf, TypedArray, UnionToIntersection, UnionToTuple, ValueOf } from "type-fest";
|
|
3
|
+
import { AnyAsyncFunction, AnyAsyncGeneratorFunction, AnyFunction, AnyGeneratorFunction, AnyObject, PlainObject, TreeLike, TreeLikeOptionalChildren } from "@pawover/types";
|
|
4
|
+
import { Any, List } from "ts-toolbelt";
|
|
2
5
|
//#region src/array/index.type.d.ts
|
|
3
6
|
type MatchFunction<T, R = unknown> = (row: T, index: number) => R;
|
|
7
|
+
/**
|
|
8
|
+
* `ArrayUtil.zip` / `ArrayUtil.unzip` 的配置项
|
|
9
|
+
* - `truncate`: 为 `true` 时按最短数组截断
|
|
10
|
+
*/
|
|
11
|
+
interface ZipOptions {
|
|
12
|
+
truncate?: boolean | undefined;
|
|
13
|
+
}
|
|
4
14
|
//#endregion
|
|
5
15
|
//#region src/array/arrayUtil.d.ts
|
|
6
16
|
/**
|
|
@@ -10,15 +20,15 @@ declare class ArrayUtil {
|
|
|
10
20
|
/**
|
|
11
21
|
* 构造数组
|
|
12
22
|
* @param candidate 待构造项
|
|
13
|
-
* @param
|
|
23
|
+
* @param checkNullish 是否检查 `undefined` 和 `null`,默认为 `true`
|
|
14
24
|
* @returns 构造后的数组
|
|
15
25
|
* @example
|
|
16
26
|
* ```ts
|
|
17
|
-
* // 重载 1:
|
|
27
|
+
* // 重载 1: checkNullish = true (默认)
|
|
18
28
|
* ArrayUtil.cast(1); // [1]
|
|
19
29
|
* ArrayUtil.cast(null); // []
|
|
20
30
|
*
|
|
21
|
-
* // 重载 2:
|
|
31
|
+
* // 重载 2: checkNullish = false
|
|
22
32
|
* ArrayUtil.cast(null, false); // [null]
|
|
23
33
|
*
|
|
24
34
|
* // 通用场景
|
|
@@ -26,8 +36,8 @@ declare class ArrayUtil {
|
|
|
26
36
|
* ArrayUtil.cast(undefined); // []
|
|
27
37
|
* ```
|
|
28
38
|
*/
|
|
29
|
-
static cast<T>(candidate: T | T[] | null | undefined,
|
|
30
|
-
static cast<T>(candidate: T | T[] | null | undefined,
|
|
39
|
+
static cast<T>(candidate: T | T[] | null | undefined, checkNullish?: true): NonNullable<T>[];
|
|
40
|
+
static cast<T>(candidate: T | T[] | null | undefined, checkNullish: false): T[];
|
|
31
41
|
/**
|
|
32
42
|
* 获取数组第一项
|
|
33
43
|
*
|
|
@@ -106,8 +116,13 @@ declare class ArrayUtil {
|
|
|
106
116
|
* @returns 差集数组
|
|
107
117
|
* @example
|
|
108
118
|
* ```ts
|
|
119
|
+
* // 重载 1: 按元素本身比较(自动去重)
|
|
109
120
|
* ArrayUtil.difference([1, 2, 3], [2, 3, 4]); // [1]
|
|
121
|
+
* ArrayUtil.difference([1, 1, 2], [2]); // [1],重复项会被去重
|
|
122
|
+
*
|
|
123
|
+
* // 重载 2: 按 match 结果比较(不去重,保留 initialList 原始重复项与顺序)
|
|
110
124
|
* ArrayUtil.difference([{ id: 1 }, { id: 2 }], [{ id: 2 }], (x) => x.id); // [{ id: 1 }]
|
|
125
|
+
* ArrayUtil.difference([{ id: 1 }, { id: 1 }], [{ id: 2 }], (x) => x.id); // [{ id: 1 }, { id: 1 }]
|
|
111
126
|
* ```
|
|
112
127
|
*/
|
|
113
128
|
static difference<T>(initialList: readonly T[], diffList: readonly T[], match?: (row: T, index: number) => unknown): T[];
|
|
@@ -152,7 +167,7 @@ declare class ArrayUtil {
|
|
|
152
167
|
* ```
|
|
153
168
|
*/
|
|
154
169
|
static merge<T>(initialList: readonly T[], mergeList: readonly T[]): T[];
|
|
155
|
-
static merge<T, D = T>(initialList: readonly T[], mergeList: readonly D[], match: MatchFunction<T>): T[];
|
|
170
|
+
static merge<T, D = T>(initialList: readonly T[], mergeList: readonly D[], match: MatchFunction<T>): (T | D)[];
|
|
156
171
|
/**
|
|
157
172
|
* 数组选择
|
|
158
173
|
* - 一次性应用 `filter` 和 `map` 操作
|
|
@@ -200,6 +215,7 @@ declare class ArrayUtil {
|
|
|
200
215
|
* - 在给定的数组中,替换并移动符合匹配函数结果的项目
|
|
201
216
|
* - 只替换和移动第一个匹配项
|
|
202
217
|
* - 未匹配时,根据 `position` 在指定位置插入 `newItem`
|
|
218
|
+
* - ⚠️ `position` 为负数或非正整数(如 `-1`、`2.5`)时不生效,静默回退为 `push`(追加到末尾)
|
|
203
219
|
*
|
|
204
220
|
* @param initialList 初始数组
|
|
205
221
|
* @param newItem 替换项
|
|
@@ -212,6 +228,9 @@ declare class ArrayUtil {
|
|
|
212
228
|
* ArrayUtil.replaceMove([1, 2, 3, 4], 5, (n) => n === 2, 2); // [1, 3, 5, 4]
|
|
213
229
|
* ArrayUtil.replaceMove([1, 2, 3, 4], 5, (n) => n === 2, "start"); // [5, 1, 3, 4]
|
|
214
230
|
* ArrayUtil.replaceMove([1, 2, 3, 4], 5, (n) => n === 2); // [1, 3, 4, 5]
|
|
231
|
+
*
|
|
232
|
+
* // position 为负数 → 静默回退为 push
|
|
233
|
+
* ArrayUtil.replaceMove([1, 2, 3, 4], 5, (n) => n === 2, -1); // [1, 3, 4, 5]
|
|
215
234
|
* ```
|
|
216
235
|
*/
|
|
217
236
|
static replaceMove<const T>(initialList: readonly T[], newItem: T, match: MatchFunction<T, boolean>, position?: "start" | "end" | number): T[];
|
|
@@ -244,25 +263,37 @@ declare class ArrayUtil {
|
|
|
244
263
|
/**
|
|
245
264
|
* 数组解压
|
|
246
265
|
* - `ArrayUtil.zip` 的反向操作
|
|
266
|
+
* - 默认按最长数组补齐 `undefined`
|
|
247
267
|
*
|
|
248
268
|
* @param arrayList 压缩后的数组
|
|
269
|
+
* @param options 配置项(`truncate` 为 `true` 时按最短数组截断)
|
|
249
270
|
* @returns 解压后的二维数组
|
|
250
271
|
* @example
|
|
251
272
|
* ```ts
|
|
252
273
|
* ArrayUtil.unzip([[1, "a"], [2, "b"]]); // [[1, 2], ["a", "b"]]
|
|
274
|
+
*
|
|
275
|
+
* // 补齐语义
|
|
276
|
+
* ArrayUtil.unzip([[1, 2], [3]]); // [[1, 3], [2, undefined]]
|
|
277
|
+
*
|
|
278
|
+
* // 截断语义
|
|
279
|
+
* ArrayUtil.unzip([[1, 2], [3]], { truncate: true }); // [[1, 3]]
|
|
253
280
|
* ```
|
|
254
281
|
*/
|
|
255
|
-
static unzip<T>(arrayList: readonly (readonly T[])[]): T[][];
|
|
282
|
+
static unzip<T>(arrayList: readonly (readonly T[])[], options?: ZipOptions): T[][];
|
|
256
283
|
/**
|
|
257
284
|
* 数组压缩
|
|
258
285
|
* - 将多个数组的元素按索引组合成元组
|
|
286
|
+
* - 默认按最长数组补齐 `undefined`
|
|
259
287
|
*
|
|
260
288
|
* @param arrays 多个数组
|
|
289
|
+
* @param options 配置项(`truncate` 为 `true` 时按最短数组截断)
|
|
261
290
|
* @returns 压缩后的元组数组
|
|
262
291
|
* @example
|
|
263
292
|
* ```ts
|
|
264
293
|
* // 重载 1: 两个数组
|
|
265
294
|
* ArrayUtil.zip([1, 2], ["a", "b"]); // [[1, "a"], [2, "b"]]
|
|
295
|
+
* // 长度不一致时默认补齐 undefined
|
|
296
|
+
* ArrayUtil.zip([1, 2, 3], ["a"]); // [[1, "a"], [2, undefined], [3, undefined]]
|
|
266
297
|
*
|
|
267
298
|
* // 重载 2: 三个数组
|
|
268
299
|
* ArrayUtil.zip([1, 2], ["a", "b"], [true, false]); // [[1, "a", true], [2, "b", false]]
|
|
@@ -275,8 +306,24 @@ declare class ArrayUtil {
|
|
|
275
306
|
*
|
|
276
307
|
* // 重载 5: 空参数
|
|
277
308
|
* ArrayUtil.zip(); // []
|
|
309
|
+
*
|
|
310
|
+
* // 重载 6: 两个数组 + options(truncate: true 截断到最短数组)
|
|
311
|
+
* ArrayUtil.zip([1, 2, 3], ["a"], { truncate: true }); // [[1, "a"]]
|
|
312
|
+
*
|
|
313
|
+
* // 重载 7: 三个数组 + options
|
|
314
|
+
* ArrayUtil.zip([1, 2], ["a"], [true], { truncate: true }); // [[1, "a", true]]
|
|
315
|
+
*
|
|
316
|
+
* // 重载 8: 四个数组 + options
|
|
317
|
+
* ArrayUtil.zip([1], ["a"], [true], ["x"], { truncate: true }); // [[1, "a", true, "x"]]
|
|
318
|
+
*
|
|
319
|
+
* // 重载 9: 五个数组 + options
|
|
320
|
+
* ArrayUtil.zip([1], ["a"], [true], ["x"], [9], { truncate: true }); // [[1, "a", true, "x", 9]]
|
|
278
321
|
* ```
|
|
279
322
|
*/
|
|
323
|
+
static zip<T1, T2, T3, T4, T5>(array1: readonly T1[], array2: readonly T2[], array3: readonly T3[], array4: readonly T4[], array5: readonly T5[], options: ZipOptions): [T1, T2, T3, T4, T5][];
|
|
324
|
+
static zip<T1, T2, T3, T4>(array1: readonly T1[], array2: readonly T2[], array3: readonly T3[], array4: readonly T4[], options: ZipOptions): [T1, T2, T3, T4][];
|
|
325
|
+
static zip<T1, T2, T3>(array1: readonly T1[], array2: readonly T2[], array3: readonly T3[], options: ZipOptions): [T1, T2, T3][];
|
|
326
|
+
static zip<T1, T2>(array1: readonly T1[], array2: readonly T2[], options: ZipOptions): [T1, T2][];
|
|
280
327
|
static zip<T1, T2, T3, T4, T5>(array1: readonly T1[], array2: readonly T2[], array3: readonly T3[], array4: readonly T4[], array5: readonly T5[]): [T1, T2, T3, T4, T5][];
|
|
281
328
|
static zip<T1, T2, T3, T4>(array1: readonly T1[], array2: readonly T2[], array3: readonly T3[], array4: readonly T4[]): [T1, T2, T3, T4][];
|
|
282
329
|
static zip<T1, T2, T3>(array1: readonly T1[], array2: readonly T2[], array3: readonly T3[]): [T1, T2, T3][];
|
|
@@ -306,2194 +353,14 @@ declare class ArrayUtil {
|
|
|
306
353
|
static zipToObject<const K extends PropertyKey, const V>(keys: readonly K[], value: V): Record<K, V>;
|
|
307
354
|
}
|
|
308
355
|
//#endregion
|
|
309
|
-
//#region ../../node_modules/.pnpm/type-fest@5.8.0/node_modules/type-fest/source/typed-array.d.ts
|
|
310
|
-
/**
|
|
311
|
-
Matches any [typed array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray), like `Uint8Array` or `Float64Array`.
|
|
312
|
-
|
|
313
|
-
@category Array
|
|
314
|
-
*/
|
|
315
|
-
type TypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array;
|
|
316
|
-
//#endregion
|
|
317
|
-
//#region ../../node_modules/.pnpm/type-fest@5.8.0/node_modules/type-fest/source/characters.d.ts
|
|
318
|
-
/**
|
|
319
|
-
Matches any digit as a string ('0'-'9').
|
|
320
|
-
|
|
321
|
-
@example
|
|
322
|
-
```
|
|
323
|
-
import type {DigitCharacter} from 'type-fest';
|
|
324
|
-
|
|
325
|
-
const a: DigitCharacter = '0'; // Valid
|
|
326
|
-
// @ts-expect-error
|
|
327
|
-
const b: DigitCharacter = 0; // Invalid
|
|
328
|
-
```
|
|
329
|
-
|
|
330
|
-
@category Type
|
|
331
|
-
*/
|
|
332
|
-
type DigitCharacter = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9';
|
|
333
|
-
//#endregion
|
|
334
|
-
//#region ../../node_modules/.pnpm/type-fest@5.8.0/node_modules/type-fest/source/union-to-intersection.d.ts
|
|
335
|
-
/**
|
|
336
|
-
Convert a union type to an intersection type.
|
|
337
|
-
|
|
338
|
-
Inspired by [this Stack Overflow answer](https://stackoverflow.com/a/50375286/2172153).
|
|
339
|
-
|
|
340
|
-
@example
|
|
341
|
-
```
|
|
342
|
-
import type {UnionToIntersection} from 'type-fest';
|
|
343
|
-
|
|
344
|
-
type Union = {the(): void} | {great(arg: string): void} | {escape: boolean};
|
|
345
|
-
|
|
346
|
-
type Intersection = UnionToIntersection<Union>;
|
|
347
|
-
//=> {the(): void} & {great(arg: string): void} & {escape: boolean}
|
|
348
|
-
```
|
|
349
|
-
|
|
350
|
-
@category Type
|
|
351
|
-
*/
|
|
352
|
-
type UnionToIntersection<Union> = (
|
|
353
|
-
// `extends unknown` is always going to be the case and is used to convert the
|
|
354
|
-
// `Union` into a [distributive conditional
|
|
355
|
-
// type](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types).
|
|
356
|
-
Union extends unknown ?
|
|
357
|
-
// The union type is used as the only argument to a function since the union
|
|
358
|
-
// of function arguments is an intersection.
|
|
359
|
-
(distributedUnion: Union) => void :
|
|
360
|
-
// This won't happen.
|
|
361
|
-
never
|
|
362
|
-
// Infer the `Intersection` type since TypeScript represents the positional
|
|
363
|
-
// arguments of unions of functions as an intersection of the union.
|
|
364
|
-
) extends ((mergedIntersection: infer Intersection) => void) ?
|
|
365
|
-
// The `& Union` is to ensure result of `UnionToIntersection<A | B>` is always assignable to `A | B`
|
|
366
|
-
Intersection & Union : never;
|
|
367
|
-
//#endregion
|
|
368
|
-
//#region ../../node_modules/.pnpm/type-fest@5.8.0/node_modules/type-fest/source/keys-of-union.d.ts
|
|
369
|
-
/**
|
|
370
|
-
Create a union of all keys from a given type, even those exclusive to specific union members.
|
|
371
|
-
|
|
372
|
-
Unlike the native `keyof` keyword, which returns keys present in **all** union members, this type returns keys from **any** member.
|
|
373
|
-
|
|
374
|
-
@link https://stackoverflow.com/a/49402091
|
|
375
|
-
|
|
376
|
-
@example
|
|
377
|
-
```
|
|
378
|
-
import type {KeysOfUnion} from 'type-fest';
|
|
379
|
-
|
|
380
|
-
type A = {
|
|
381
|
-
common: string;
|
|
382
|
-
a: number;
|
|
383
|
-
};
|
|
384
|
-
|
|
385
|
-
type B = {
|
|
386
|
-
common: string;
|
|
387
|
-
b: string;
|
|
388
|
-
};
|
|
389
|
-
|
|
390
|
-
type C = {
|
|
391
|
-
common: string;
|
|
392
|
-
c: boolean;
|
|
393
|
-
};
|
|
394
|
-
|
|
395
|
-
type Union = A | B | C;
|
|
396
|
-
|
|
397
|
-
type CommonKeys = keyof Union;
|
|
398
|
-
//=> 'common'
|
|
399
|
-
|
|
400
|
-
type AllKeys = KeysOfUnion<Union>;
|
|
401
|
-
//=> 'common' | 'a' | 'b' | 'c'
|
|
402
|
-
```
|
|
403
|
-
|
|
404
|
-
@category Object
|
|
405
|
-
*/
|
|
406
|
-
type KeysOfUnion<ObjectType> =
|
|
407
|
-
// Hack to fix https://github.com/sindresorhus/type-fest/issues/1008
|
|
408
|
-
keyof UnionToIntersection<ObjectType extends unknown ? Record<keyof ObjectType, never> : never>;
|
|
409
|
-
//#endregion
|
|
410
|
-
//#region ../../node_modules/.pnpm/type-fest@5.8.0/node_modules/type-fest/source/is-any.d.ts
|
|
411
|
-
/**
|
|
412
|
-
Returns a boolean for whether the given type is `any`.
|
|
413
|
-
|
|
414
|
-
@link https://stackoverflow.com/a/49928360/1490091
|
|
415
|
-
|
|
416
|
-
Useful in type utilities, such as disallowing `any`s to be passed to a function.
|
|
417
|
-
|
|
418
|
-
@example
|
|
419
|
-
```
|
|
420
|
-
import type {IsAny} from 'type-fest';
|
|
421
|
-
|
|
422
|
-
const typedObject = {a: 1, b: 2} as const;
|
|
423
|
-
const anyObject: any = {a: 1, b: 2};
|
|
424
|
-
|
|
425
|
-
function get<O extends (IsAny<O> extends true ? {} : Record<string, number>), K extends keyof O = keyof O>(object: O, key: K) {
|
|
426
|
-
return object[key];
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
const typedA = get(typedObject, 'a');
|
|
430
|
-
//=> 1
|
|
431
|
-
|
|
432
|
-
const anyA = get(anyObject, 'a');
|
|
433
|
-
//=> any
|
|
434
|
-
```
|
|
435
|
-
|
|
436
|
-
@category Type Guard
|
|
437
|
-
@category Utilities
|
|
438
|
-
*/
|
|
439
|
-
type IsAny<T> = 0 extends 1 & NoInfer<T> ? true : false;
|
|
440
|
-
//#endregion
|
|
441
|
-
//#region ../../node_modules/.pnpm/type-fest@5.8.0/node_modules/type-fest/source/is-optional-key-of.d.ts
|
|
442
|
-
/**
|
|
443
|
-
Returns a boolean for whether the given key is an optional key of type.
|
|
444
|
-
|
|
445
|
-
This is useful when writing utility types or schema validators that need to differentiate `optional` keys.
|
|
446
|
-
|
|
447
|
-
@example
|
|
448
|
-
```
|
|
449
|
-
import type {IsOptionalKeyOf} from 'type-fest';
|
|
450
|
-
|
|
451
|
-
type User = {
|
|
452
|
-
name: string;
|
|
453
|
-
surname: string;
|
|
454
|
-
|
|
455
|
-
luckyNumber?: number;
|
|
456
|
-
};
|
|
457
|
-
|
|
458
|
-
type Admin = {
|
|
459
|
-
name: string;
|
|
460
|
-
surname?: string;
|
|
461
|
-
};
|
|
462
|
-
|
|
463
|
-
type T1 = IsOptionalKeyOf<User, 'luckyNumber'>;
|
|
464
|
-
//=> true
|
|
465
|
-
|
|
466
|
-
type T2 = IsOptionalKeyOf<User, 'name'>;
|
|
467
|
-
//=> false
|
|
468
|
-
|
|
469
|
-
type T3 = IsOptionalKeyOf<User, 'name' | 'luckyNumber'>;
|
|
470
|
-
//=> boolean
|
|
471
|
-
|
|
472
|
-
type T4 = IsOptionalKeyOf<User | Admin, 'name'>;
|
|
473
|
-
//=> false
|
|
474
|
-
|
|
475
|
-
type T5 = IsOptionalKeyOf<User | Admin, 'surname'>;
|
|
476
|
-
//=> boolean
|
|
477
|
-
```
|
|
478
|
-
|
|
479
|
-
@category Type Guard
|
|
480
|
-
@category Utilities
|
|
481
|
-
*/
|
|
482
|
-
type IsOptionalKeyOf<Type extends object, Key extends keyof Type> = IsAny<Type | Key> extends true ? never : Key extends keyof Type ? Type extends Record<Key, Type[Key]> ? false : true : false;
|
|
483
|
-
//#endregion
|
|
484
|
-
//#region ../../node_modules/.pnpm/type-fest@5.8.0/node_modules/type-fest/source/optional-keys-of.d.ts
|
|
485
|
-
/**
|
|
486
|
-
Extract all optional keys from the given type.
|
|
487
|
-
|
|
488
|
-
This is useful when you want to create a new type that contains different type values for the optional keys only.
|
|
489
|
-
|
|
490
|
-
@example
|
|
491
|
-
```
|
|
492
|
-
import type {OptionalKeysOf, Except} from 'type-fest';
|
|
493
|
-
|
|
494
|
-
type User = {
|
|
495
|
-
name: string;
|
|
496
|
-
surname: string;
|
|
497
|
-
|
|
498
|
-
luckyNumber?: number;
|
|
499
|
-
};
|
|
500
|
-
|
|
501
|
-
const REMOVE_FIELD = Symbol('remove field symbol');
|
|
502
|
-
type UpdateOperation<Entity extends object> = Except<Partial<Entity>, OptionalKeysOf<Entity>> & {
|
|
503
|
-
[Key in OptionalKeysOf<Entity>]?: Entity[Key] | typeof REMOVE_FIELD;
|
|
504
|
-
};
|
|
505
|
-
|
|
506
|
-
const update1: UpdateOperation<User> = {
|
|
507
|
-
name: 'Alice',
|
|
508
|
-
};
|
|
509
|
-
|
|
510
|
-
const update2: UpdateOperation<User> = {
|
|
511
|
-
name: 'Bob',
|
|
512
|
-
luckyNumber: REMOVE_FIELD,
|
|
513
|
-
};
|
|
514
|
-
```
|
|
515
|
-
|
|
516
|
-
@category Utilities
|
|
517
|
-
*/
|
|
518
|
-
type OptionalKeysOf<Type extends object> = Type extends unknown // For distributing `Type`
|
|
519
|
-
? (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`
|
|
520
|
-
: never; // Should never happen
|
|
521
|
-
//#endregion
|
|
522
|
-
//#region ../../node_modules/.pnpm/type-fest@5.8.0/node_modules/type-fest/source/required-keys-of.d.ts
|
|
523
|
-
/**
|
|
524
|
-
Extract all required keys from the given type.
|
|
525
|
-
|
|
526
|
-
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...
|
|
527
|
-
|
|
528
|
-
@example
|
|
529
|
-
```
|
|
530
|
-
import type {RequiredKeysOf} from 'type-fest';
|
|
531
|
-
|
|
532
|
-
declare function createValidation<
|
|
533
|
-
Entity extends object,
|
|
534
|
-
Key extends RequiredKeysOf<Entity> = RequiredKeysOf<Entity>,
|
|
535
|
-
>(field: Key, validator: (value: Entity[Key]) => boolean): (entity: Entity) => boolean;
|
|
536
|
-
|
|
537
|
-
type User = {
|
|
538
|
-
name: string;
|
|
539
|
-
surname: string;
|
|
540
|
-
luckyNumber?: number;
|
|
541
|
-
};
|
|
542
|
-
|
|
543
|
-
const validator1 = createValidation<User>('name', value => value.length < 25);
|
|
544
|
-
const validator2 = createValidation<User>('surname', value => value.length < 25);
|
|
545
|
-
|
|
546
|
-
// @ts-expect-error
|
|
547
|
-
const validator3 = createValidation<User>('luckyNumber', value => value > 0);
|
|
548
|
-
// Error: Argument of type '"luckyNumber"' is not assignable to parameter of type '"name" | "surname"'.
|
|
549
|
-
```
|
|
550
|
-
|
|
551
|
-
@category Utilities
|
|
552
|
-
*/
|
|
553
|
-
type RequiredKeysOf<Type extends object> = Type extends unknown // For distributing `Type`
|
|
554
|
-
? Exclude<keyof Type, OptionalKeysOf<Type>> : never; // Should never happen
|
|
555
|
-
//#endregion
|
|
556
|
-
//#region ../../node_modules/.pnpm/type-fest@5.8.0/node_modules/type-fest/source/is-never.d.ts
|
|
557
|
-
/**
|
|
558
|
-
Returns a boolean for whether the given type is `never`.
|
|
559
|
-
|
|
560
|
-
@link https://github.com/microsoft/TypeScript/issues/31751#issuecomment-498526919
|
|
561
|
-
@link https://stackoverflow.com/a/53984913/10292952
|
|
562
|
-
@link https://www.zhenghao.io/posts/ts-never
|
|
563
|
-
|
|
564
|
-
Useful in type utilities, such as checking if something does not occur.
|
|
565
|
-
|
|
566
|
-
@example
|
|
567
|
-
```
|
|
568
|
-
import type {IsNever, And} from 'type-fest';
|
|
569
|
-
|
|
570
|
-
type A = IsNever<never>;
|
|
571
|
-
//=> true
|
|
572
|
-
|
|
573
|
-
type B = IsNever<any>;
|
|
574
|
-
//=> false
|
|
575
|
-
|
|
576
|
-
type C = IsNever<unknown>;
|
|
577
|
-
//=> false
|
|
578
|
-
|
|
579
|
-
type D = IsNever<never[]>;
|
|
580
|
-
//=> false
|
|
581
|
-
|
|
582
|
-
type E = IsNever<object>;
|
|
583
|
-
//=> false
|
|
584
|
-
|
|
585
|
-
type F = IsNever<string>;
|
|
586
|
-
//=> false
|
|
587
|
-
```
|
|
588
|
-
|
|
589
|
-
@example
|
|
590
|
-
```
|
|
591
|
-
import type {IsNever} from 'type-fest';
|
|
592
|
-
|
|
593
|
-
type IsTrue<T> = T extends true ? true : false;
|
|
594
|
-
|
|
595
|
-
// When a distributive conditional is instantiated with `never`, the entire conditional results in `never`.
|
|
596
|
-
type A = IsTrue<never>;
|
|
597
|
-
//=> never
|
|
598
|
-
|
|
599
|
-
// If you don't want that behaviour, you can explicitly add an `IsNever` check before the distributive conditional.
|
|
600
|
-
type IsTrueFixed<T> =
|
|
601
|
-
IsNever<T> extends true ? false : T extends true ? true : false;
|
|
602
|
-
|
|
603
|
-
type B = IsTrueFixed<never>;
|
|
604
|
-
//=> false
|
|
605
|
-
```
|
|
606
|
-
|
|
607
|
-
@category Type Guard
|
|
608
|
-
@category Utilities
|
|
609
|
-
*/
|
|
610
|
-
type IsNever<T> = [T] extends [never] ? true : false;
|
|
611
|
-
//#endregion
|
|
612
|
-
//#region ../../node_modules/.pnpm/type-fest@5.8.0/node_modules/type-fest/source/if.d.ts
|
|
613
|
-
/**
|
|
614
|
-
An if-else-like type that resolves depending on whether the given `boolean` type is `true` or `false`.
|
|
615
|
-
|
|
616
|
-
Use-cases:
|
|
617
|
-
- 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'>`.
|
|
618
|
-
|
|
619
|
-
Note:
|
|
620
|
-
- 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'`.
|
|
621
|
-
- Returns the else branch if the given type is `never`. For example, `If<never, 'Y', 'N'>` will return `'N'`.
|
|
622
|
-
|
|
623
|
-
@example
|
|
624
|
-
```
|
|
625
|
-
import type {If} from 'type-fest';
|
|
626
|
-
|
|
627
|
-
type A = If<true, 'yes', 'no'>;
|
|
628
|
-
//=> 'yes'
|
|
629
|
-
|
|
630
|
-
type B = If<false, 'yes', 'no'>;
|
|
631
|
-
//=> 'no'
|
|
632
|
-
|
|
633
|
-
type C = If<boolean, 'yes', 'no'>;
|
|
634
|
-
//=> 'yes' | 'no'
|
|
635
|
-
|
|
636
|
-
type D = If<any, 'yes', 'no'>;
|
|
637
|
-
//=> 'yes' | 'no'
|
|
638
|
-
|
|
639
|
-
type E = If<never, 'yes', 'no'>;
|
|
640
|
-
//=> 'no'
|
|
641
|
-
```
|
|
642
|
-
|
|
643
|
-
@example
|
|
644
|
-
```
|
|
645
|
-
import type {If, IsAny, IsNever} from 'type-fest';
|
|
646
|
-
|
|
647
|
-
type A = If<IsAny<unknown>, 'is any', 'not any'>;
|
|
648
|
-
//=> 'not any'
|
|
649
|
-
|
|
650
|
-
type B = If<IsNever<never>, 'is never', 'not never'>;
|
|
651
|
-
//=> 'is never'
|
|
652
|
-
```
|
|
653
|
-
|
|
654
|
-
@example
|
|
655
|
-
```
|
|
656
|
-
import type {If, IsEqual} from 'type-fest';
|
|
657
|
-
|
|
658
|
-
type IfEqual<T, U, IfBranch, ElseBranch> = If<IsEqual<T, U>, IfBranch, ElseBranch>;
|
|
659
|
-
|
|
660
|
-
type A = IfEqual<string, string, 'equal', 'not equal'>;
|
|
661
|
-
//=> 'equal'
|
|
662
|
-
|
|
663
|
-
type B = IfEqual<string, number, 'equal', 'not equal'>;
|
|
664
|
-
//=> 'not equal'
|
|
665
|
-
```
|
|
666
|
-
|
|
667
|
-
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:
|
|
668
|
-
|
|
669
|
-
@example
|
|
670
|
-
```
|
|
671
|
-
import type {If, IsEqual, StringRepeat} from 'type-fest';
|
|
672
|
-
|
|
673
|
-
type HundredZeroes = StringRepeat<'0', 100>;
|
|
674
|
-
|
|
675
|
-
// The following implementation is not tail recursive
|
|
676
|
-
type Includes<S extends string, Char extends string> =
|
|
677
|
-
S extends `${infer First}${infer Rest}`
|
|
678
|
-
? If<IsEqual<First, Char>,
|
|
679
|
-
'found',
|
|
680
|
-
Includes<Rest, Char>>
|
|
681
|
-
: 'not found';
|
|
682
|
-
|
|
683
|
-
// Hence, instantiations with long strings will fail
|
|
684
|
-
// @ts-expect-error
|
|
685
|
-
type Fails = Includes<HundredZeroes, '1'>;
|
|
686
|
-
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
687
|
-
// Error: Type instantiation is excessively deep and possibly infinite.
|
|
688
|
-
|
|
689
|
-
// However, if we use a simple conditional instead of `If`, the implementation becomes tail-recursive
|
|
690
|
-
type IncludesWithoutIf<S extends string, Char extends string> =
|
|
691
|
-
S extends `${infer First}${infer Rest}`
|
|
692
|
-
? IsEqual<First, Char> extends true
|
|
693
|
-
? 'found'
|
|
694
|
-
: IncludesWithoutIf<Rest, Char>
|
|
695
|
-
: 'not found';
|
|
696
|
-
|
|
697
|
-
// Now, instantiations with long strings will work
|
|
698
|
-
type Works = IncludesWithoutIf<HundredZeroes, '1'>;
|
|
699
|
-
//=> 'not found'
|
|
700
|
-
```
|
|
701
|
-
|
|
702
|
-
@category Type Guard
|
|
703
|
-
@category Utilities
|
|
704
|
-
*/
|
|
705
|
-
type If<Type extends boolean, IfBranch, ElseBranch> = IsNever<Type> extends true ? ElseBranch : Type extends true ? IfBranch : ElseBranch;
|
|
706
|
-
//#endregion
|
|
707
|
-
//#region ../../node_modules/.pnpm/type-fest@5.8.0/node_modules/type-fest/source/unknown-array.d.ts
|
|
708
|
-
/**
|
|
709
|
-
Represents an array with `unknown` value.
|
|
710
|
-
|
|
711
|
-
Use case: You want a type that all arrays can be assigned to, but you don't care about the value.
|
|
712
|
-
|
|
713
|
-
@example
|
|
714
|
-
```
|
|
715
|
-
import type {UnknownArray} from 'type-fest';
|
|
716
|
-
|
|
717
|
-
type IsArray<T> = T extends UnknownArray ? true : false;
|
|
718
|
-
|
|
719
|
-
type A = IsArray<['foo']>;
|
|
720
|
-
//=> true
|
|
721
|
-
|
|
722
|
-
type B = IsArray<readonly number[]>;
|
|
723
|
-
//=> true
|
|
724
|
-
|
|
725
|
-
type C = IsArray<string>;
|
|
726
|
-
//=> false
|
|
727
|
-
```
|
|
728
|
-
|
|
729
|
-
@category Type
|
|
730
|
-
@category Array
|
|
731
|
-
*/
|
|
732
|
-
type UnknownArray = readonly unknown[];
|
|
733
|
-
//#endregion
|
|
734
|
-
//#region ../../node_modules/.pnpm/type-fest@5.8.0/node_modules/type-fest/source/internal/type.d.ts
|
|
735
|
-
/**
|
|
736
|
-
Returns a boolean for whether A is false.
|
|
737
|
-
|
|
738
|
-
@example
|
|
739
|
-
```
|
|
740
|
-
type A = Not<true>;
|
|
741
|
-
//=> false
|
|
742
|
-
|
|
743
|
-
type B = Not<false>;
|
|
744
|
-
//=> true
|
|
745
|
-
```
|
|
746
|
-
*/
|
|
747
|
-
type Not<A extends boolean> = A extends true ? false : A extends false ? true : never;
|
|
748
|
-
/**
|
|
749
|
-
An if-else-like type that resolves depending on whether the given type is `any` or `never`.
|
|
750
|
-
|
|
751
|
-
@example
|
|
752
|
-
```
|
|
753
|
-
// When `T` is neither `any` nor `never` (like `string`) => Returns `IfNot` branch
|
|
754
|
-
type A = IfNotAnyOrNever<string, {ifNot: 'VALID'; ifAny: 'IS_ANY'; ifNever: 'IS_NEVER'}>;
|
|
755
|
-
//=> 'VALID'
|
|
756
|
-
|
|
757
|
-
// When `T` is `any` => Returns `IfAny` branch
|
|
758
|
-
type B = IfNotAnyOrNever<any, {ifNot: 'VALID'; ifAny: 'IS_ANY'; ifNever: 'IS_NEVER'}>;
|
|
759
|
-
//=> 'IS_ANY'
|
|
760
|
-
|
|
761
|
-
// When `T` is `never` => Returns `IfNever` branch
|
|
762
|
-
type C = IfNotAnyOrNever<never, {ifNot: 'VALID'; ifAny: 'IS_ANY'; ifNever: 'IS_NEVER'}>;
|
|
763
|
-
//=> 'IS_NEVER'
|
|
764
|
-
```
|
|
765
|
-
|
|
766
|
-
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:
|
|
767
|
-
|
|
768
|
-
@example
|
|
769
|
-
```ts
|
|
770
|
-
import type {StringRepeat} from 'type-fest';
|
|
771
|
-
|
|
772
|
-
type NineHundredNinetyNineSpaces = StringRepeat<' ', 999>;
|
|
773
|
-
|
|
774
|
-
// The following implementation is not tail recursive
|
|
775
|
-
type TrimLeft<S extends string> = IfNotAnyOrNever<S, {ifNot: S extends ` ${infer R}` ? TrimLeft<R> : S}>;
|
|
776
|
-
|
|
777
|
-
// Hence, instantiations with long strings will fail
|
|
778
|
-
// @ts-expect-error
|
|
779
|
-
type T1 = TrimLeft<NineHundredNinetyNineSpaces>;
|
|
780
|
-
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
781
|
-
// Error: Type instantiation is excessively deep and possibly infinite.
|
|
782
|
-
|
|
783
|
-
// To fix this, move the recursion into a helper type
|
|
784
|
-
type TrimLeftOptimised<S extends string> = IfNotAnyOrNever<S, {ifNot: _TrimLeftOptimised<S>}>;
|
|
785
|
-
|
|
786
|
-
type _TrimLeftOptimised<S extends string> = S extends ` ${infer R}` ? _TrimLeftOptimised<R> : S;
|
|
787
|
-
|
|
788
|
-
type T2 = TrimLeftOptimised<NineHundredNinetyNineSpaces>;
|
|
789
|
-
//=> ''
|
|
790
|
-
```
|
|
791
|
-
*/
|
|
792
|
-
type IfNotAnyOrNever<T, Cases extends {
|
|
793
|
-
ifNot: unknown;
|
|
794
|
-
ifAny?: unknown;
|
|
795
|
-
ifNever?: unknown;
|
|
796
|
-
}> = IsAny<T> extends true ? 'ifAny' extends keyof Cases ? Cases['ifAny'] : any : IsNever<T> extends true ? 'ifNever' extends keyof Cases ? Cases['ifNever'] : never : Cases['ifNot'];
|
|
797
|
-
/**
|
|
798
|
-
Indicates the value of `exactOptionalPropertyTypes` compiler option.
|
|
799
|
-
*/
|
|
800
|
-
type IsExactOptionalPropertyTypesEnabled = [(string | undefined)?] extends [string?] ? false : true;
|
|
801
|
-
//#endregion
|
|
802
|
-
//#region ../../node_modules/.pnpm/type-fest@5.8.0/node_modules/type-fest/source/internal/array.d.ts
|
|
803
|
-
/**
|
|
804
|
-
Transforms a tuple type by replacing it's rest element with a single element that has the same type as the rest element, while keeping all the non-rest elements intact.
|
|
805
|
-
|
|
806
|
-
@example
|
|
807
|
-
```
|
|
808
|
-
type A = CollapseRestElement<[string, string, ...number[]]>;
|
|
809
|
-
//=> [string, string, number]
|
|
810
|
-
|
|
811
|
-
type B = CollapseRestElement<[...string[], number, number]>;
|
|
812
|
-
//=> [string, number, number]
|
|
813
|
-
|
|
814
|
-
type C = CollapseRestElement<[string, string, ...Array<number | bigint>]>;
|
|
815
|
-
//=> [string, string, number | bigint]
|
|
816
|
-
|
|
817
|
-
type D = CollapseRestElement<[string, number]>;
|
|
818
|
-
//=> [string, number]
|
|
819
|
-
```
|
|
820
|
-
|
|
821
|
-
Note: Optional modifiers (`?`) are removed from elements unless the `exactOptionalPropertyTypes` compiler option is disabled. When disabled, there's an additional `| undefined` for optional elements.
|
|
822
|
-
|
|
823
|
-
@example
|
|
824
|
-
```
|
|
825
|
-
// `exactOptionalPropertyTypes` enabled
|
|
826
|
-
type A = CollapseRestElement<[string?, string?, ...number[]]>;
|
|
827
|
-
//=> [string, string, number]
|
|
828
|
-
|
|
829
|
-
// `exactOptionalPropertyTypes` disabled
|
|
830
|
-
type B = CollapseRestElement<[string?, string?, ...number[]]>;
|
|
831
|
-
//=> [string | undefined, string | undefined, number]
|
|
832
|
-
```
|
|
833
|
-
*/
|
|
834
|
-
type CollapseRestElement<TArray extends UnknownArray> = IfNotAnyOrNever<TArray, {
|
|
835
|
-
ifNot: _CollapseRestElement<TArray>;
|
|
836
|
-
}>;
|
|
837
|
-
type _CollapseRestElement<TArray extends UnknownArray, ForwardAccumulator extends UnknownArray = [], BackwardAccumulator extends UnknownArray = []> = TArray extends UnknownArray // For distributing `TArray`
|
|
838
|
-
? keyof TArray & `${number}` extends never ?
|
|
839
|
-
// Enters this branch, if `TArray` is empty (e.g., []),
|
|
840
|
-
// or `TArray` contains no non-rest elements preceding the rest element (e.g., `[...string[]]` or `[...string[], string]`).
|
|
841
|
-
TArray extends readonly [...infer Rest, infer Last] ? _CollapseRestElement<Rest, ForwardAccumulator, [Last, ...BackwardAccumulator]> // Accumulate elements that are present after the rest element.
|
|
842
|
-
: TArray extends readonly [] ? [...ForwardAccumulator, ...BackwardAccumulator] : [...ForwardAccumulator, TArray[number], ...BackwardAccumulator] // Add the rest element between the accumulated elements.
|
|
843
|
-
: TArray extends readonly [(infer First)?, ...infer Rest] ? _CollapseRestElement<Rest, [...ForwardAccumulator, '0' extends OptionalKeysOf<TArray> ? If<IsExactOptionalPropertyTypesEnabled, First, First | undefined> // Add `| undefined` for optional elements, if `exactOptionalPropertyTypes` is disabled.
|
|
844
|
-
: First], BackwardAccumulator> : never // Should never happen, since `[(infer First)?, ...infer Rest]` is a top-type for arrays.
|
|
845
|
-
: never; // Should never happen
|
|
846
|
-
//#endregion
|
|
847
|
-
//#region ../../node_modules/.pnpm/type-fest@5.8.0/node_modules/type-fest/source/numeric.d.ts
|
|
848
|
-
type _Numeric = number | bigint;
|
|
849
|
-
type Zero = 0 | 0n;
|
|
850
|
-
/**
|
|
851
|
-
A negative `number`/`bigint` (`-∞ < x < 0`)
|
|
852
|
-
|
|
853
|
-
Use-case: Validating and documenting parameters.
|
|
854
|
-
|
|
855
|
-
@see {@link NegativeInteger}
|
|
856
|
-
@see {@link NonNegative}
|
|
857
|
-
|
|
858
|
-
@category Numeric
|
|
859
|
-
*/
|
|
860
|
-
type Negative<T extends _Numeric> = T extends Zero ? never : `${T}` extends `-${string}` ? T : never;
|
|
861
|
-
/**
|
|
862
|
-
Returns a boolean for whether the given number is a negative number.
|
|
863
|
-
|
|
864
|
-
@see {@link Negative}
|
|
865
|
-
|
|
866
|
-
@example
|
|
867
|
-
```
|
|
868
|
-
import type {IsNegative} from 'type-fest';
|
|
869
|
-
|
|
870
|
-
type ShouldBeFalse = IsNegative<1>;
|
|
871
|
-
type ShouldBeTrue = IsNegative<-1>;
|
|
872
|
-
```
|
|
873
|
-
|
|
874
|
-
@category Numeric
|
|
875
|
-
*/
|
|
876
|
-
type IsNegative<T extends _Numeric> = T extends Negative<T> ? true : false;
|
|
877
|
-
//#endregion
|
|
878
|
-
//#region ../../node_modules/.pnpm/tagged-tag@1.0.0/node_modules/tagged-tag/index.d.ts
|
|
879
|
-
declare const tag: unique symbol;
|
|
880
|
-
//#endregion
|
|
881
|
-
//#region ../../node_modules/.pnpm/type-fest@5.8.0/node_modules/type-fest/source/tagged.d.ts
|
|
882
|
-
// eslint-disable-next-line type-fest/require-exported-types
|
|
883
|
-
type TagContainer<Token> = {
|
|
884
|
-
readonly [tag]: Token;
|
|
885
|
-
};
|
|
886
|
-
type Tag<Token extends PropertyKey, TagMetadata> = TagContainer<{ [K in Token]: TagMetadata; }>;
|
|
887
|
-
/**
|
|
888
|
-
Create a [tagged type](https://medium.com/@KevinBGreene/surviving-the-typescript-ecosystem-branding-and-type-tagging-6cf6e516523d) that can support [multiple tags](https://github.com/sindresorhus/type-fest/issues/665) and [per-tag metadata](https://medium.com/@ethanresnick/advanced-typescript-tagged-types-improved-with-type-level-metadata-5072fc125fcf).
|
|
889
|
-
|
|
890
|
-
A type returned by `Tagged` can be passed to `Tagged` again, to create a type with multiple tags.
|
|
891
|
-
|
|
892
|
-
A tag's name is usually a string (and must be a string, number, or symbol), but each application of a tag can also contain an arbitrary type as its "metadata". See {@link GetTagMetadata} for examples and explanation.
|
|
893
|
-
|
|
894
|
-
A type `A` returned by `Tagged` is assignable to another type `B` returned by `Tagged` if and only if:
|
|
895
|
-
- the underlying (untagged) type of `A` is assignable to the underlying type of `B`;
|
|
896
|
-
- `A` contains at least all the tags `B` has;
|
|
897
|
-
- and the metadata type for each of `A`'s tags is assignable to the metadata type of `B`'s corresponding tag.
|
|
898
|
-
|
|
899
|
-
There have been several discussions about adding similar features to TypeScript. Unfortunately, nothing has (yet) moved forward:
|
|
900
|
-
- [Microsoft/TypeScript#202](https://github.com/microsoft/TypeScript/issues/202)
|
|
901
|
-
- [Microsoft/TypeScript#4895](https://github.com/microsoft/TypeScript/issues/4895)
|
|
902
|
-
- [Microsoft/TypeScript#33290](https://github.com/microsoft/TypeScript/pull/33290)
|
|
903
|
-
|
|
904
|
-
@example
|
|
905
|
-
```
|
|
906
|
-
import type {Tagged} from 'type-fest';
|
|
907
|
-
|
|
908
|
-
type AccountNumber = Tagged<number, 'AccountNumber'>;
|
|
909
|
-
type AccountBalance = Tagged<number, 'AccountBalance'>;
|
|
910
|
-
|
|
911
|
-
function createAccountNumber(): AccountNumber {
|
|
912
|
-
// As you can see, casting from a `number` (the underlying type being tagged) is allowed.
|
|
913
|
-
return 2 as AccountNumber;
|
|
914
|
-
}
|
|
915
|
-
|
|
916
|
-
declare function getMoneyForAccount(accountNumber: AccountNumber): AccountBalance;
|
|
917
|
-
|
|
918
|
-
// This will compile successfully.
|
|
919
|
-
getMoneyForAccount(createAccountNumber());
|
|
920
|
-
|
|
921
|
-
// But this won't, because it has to be explicitly passed as an `AccountNumber` type!
|
|
922
|
-
// Critically, you could not accidentally use an `AccountBalance` as an `AccountNumber`.
|
|
923
|
-
// @ts-expect-error
|
|
924
|
-
getMoneyForAccount(2);
|
|
925
|
-
|
|
926
|
-
// You can also use tagged values like their underlying, untagged type.
|
|
927
|
-
// I.e., this will compile successfully because an `AccountNumber` can be used as a regular `number`.
|
|
928
|
-
// In this sense, the underlying base type is not hidden, which differentiates tagged types from opaque types in other languages.
|
|
929
|
-
const accountNumber = createAccountNumber() + 2;
|
|
930
|
-
```
|
|
931
|
-
|
|
932
|
-
@example
|
|
933
|
-
```
|
|
934
|
-
import type {Tagged} from 'type-fest';
|
|
935
|
-
|
|
936
|
-
// You can apply multiple tags to a type by using `Tagged` repeatedly.
|
|
937
|
-
type Url = Tagged<string, 'URL'>;
|
|
938
|
-
type SpecialCacheKey = Tagged<Url, 'SpecialCacheKey'>;
|
|
939
|
-
|
|
940
|
-
// You can also pass a union of tag names, so this is equivalent to the above, although it doesn't give you the ability to assign distinct metadata to each tag.
|
|
941
|
-
type SpecialCacheKey2 = Tagged<string, 'URL' | 'SpecialCacheKey'>;
|
|
942
|
-
```
|
|
943
|
-
|
|
944
|
-
@category Type
|
|
945
|
-
*/
|
|
946
|
-
type Tagged<Type, TagName extends PropertyKey, TagMetadata = never> = Type & Tag<TagName, TagMetadata>;
|
|
947
|
-
/**
|
|
948
|
-
Get the untagged portion of a tagged type created with `Tagged`.
|
|
949
|
-
|
|
950
|
-
Why is this necessary?
|
|
951
|
-
|
|
952
|
-
1. Use a `Tagged` type as object keys
|
|
953
|
-
2. Prevent TS4058 error: "Return type of exported function has or is using name X from external module Y but cannot be named"
|
|
954
|
-
|
|
955
|
-
@example
|
|
956
|
-
```
|
|
957
|
-
import type {Tagged, UnwrapTagged} from 'type-fest';
|
|
958
|
-
|
|
959
|
-
type AccountType = Tagged<'SAVINGS' | 'CHECKING', 'AccountType'>;
|
|
960
|
-
|
|
961
|
-
const moneyByAccountType: Record<UnwrapTagged<AccountType>, number> = {
|
|
962
|
-
SAVINGS: 99,
|
|
963
|
-
CHECKING: 0.1,
|
|
964
|
-
};
|
|
965
|
-
|
|
966
|
-
// Without UnwrapTagged, the following expression would throw a type error.
|
|
967
|
-
const money = moneyByAccountType.SAVINGS; // TS error: Property 'SAVINGS' does not exist
|
|
968
|
-
|
|
969
|
-
// Attempting to pass a non-Tagged type to UnwrapTagged will raise a type error.
|
|
970
|
-
// @ts-expect-error
|
|
971
|
-
type WontWork = UnwrapTagged<string>;
|
|
972
|
-
```
|
|
973
|
-
|
|
974
|
-
@category Type
|
|
975
|
-
*/
|
|
976
|
-
type UnwrapTagged<TaggedType extends Tag<PropertyKey, any>> = RemoveAllTags<TaggedType>;
|
|
977
|
-
type RemoveAllTags<T> = T extends Tag<PropertyKey, any> ? { [ThisTag in keyof T[typeof tag]]: T extends Tagged<infer Type, ThisTag, T[typeof tag][ThisTag]> ? RemoveAllTags<Type> : never; }[keyof T[typeof tag]] : T;
|
|
978
|
-
//#endregion
|
|
979
|
-
//#region ../../node_modules/.pnpm/type-fest@5.8.0/node_modules/type-fest/source/is-literal.d.ts
|
|
980
|
-
/**
|
|
981
|
-
Returns a boolean for whether the given type is a `string` [literal type](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#literal-types).
|
|
982
|
-
|
|
983
|
-
Useful for:
|
|
984
|
-
- providing strongly-typed string manipulation functions
|
|
985
|
-
- constraining strings to be a string literal
|
|
986
|
-
- type utilities, such as when constructing parsers and ASTs
|
|
987
|
-
|
|
988
|
-
The implementation of this type is inspired by the trick mentioned in this [StackOverflow answer](https://stackoverflow.com/a/68261113/420747).
|
|
989
|
-
|
|
990
|
-
@example
|
|
991
|
-
```
|
|
992
|
-
import type {IsStringLiteral} from 'type-fest';
|
|
993
|
-
|
|
994
|
-
type CapitalizedString<T extends string> = IsStringLiteral<T> extends true ? Capitalize<T> : string;
|
|
995
|
-
|
|
996
|
-
// https://github.com/yankeeinlondon/native-dash/blob/master/src/capitalize.ts
|
|
997
|
-
function capitalize<T extends Readonly<string>>(input: T): CapitalizedString<T> {
|
|
998
|
-
return (input.slice(0, 1).toUpperCase() + input.slice(1)) as CapitalizedString<T>;
|
|
999
|
-
}
|
|
1000
|
-
|
|
1001
|
-
const output = capitalize('hello, world!');
|
|
1002
|
-
//=> 'Hello, world!'
|
|
1003
|
-
```
|
|
1004
|
-
|
|
1005
|
-
@example
|
|
1006
|
-
```
|
|
1007
|
-
// String types with infinite set of possible values return `false`.
|
|
1008
|
-
|
|
1009
|
-
import type {IsStringLiteral} from 'type-fest';
|
|
1010
|
-
|
|
1011
|
-
type AllUppercaseStrings = IsStringLiteral<Uppercase<string>>;
|
|
1012
|
-
//=> false
|
|
1013
|
-
|
|
1014
|
-
type StringsStartingWithOn = IsStringLiteral<`on${string}`>;
|
|
1015
|
-
//=> false
|
|
1016
|
-
|
|
1017
|
-
// This behaviour is particularly useful in string manipulation utilities, as infinite string types often require separate handling.
|
|
1018
|
-
|
|
1019
|
-
type Length<S extends string, Counter extends never[] = []> =
|
|
1020
|
-
IsStringLiteral<S> extends false
|
|
1021
|
-
? number // return `number` for infinite string types
|
|
1022
|
-
: S extends `${string}${infer Tail}`
|
|
1023
|
-
? Length<Tail, [...Counter, never]>
|
|
1024
|
-
: Counter['length'];
|
|
1025
|
-
|
|
1026
|
-
type L1 = Length<Lowercase<string>>;
|
|
1027
|
-
//=> number
|
|
1028
|
-
|
|
1029
|
-
type L2 = Length<`${number}`>;
|
|
1030
|
-
//=> number
|
|
1031
|
-
```
|
|
1032
|
-
|
|
1033
|
-
@category Type Guard
|
|
1034
|
-
@category Utilities
|
|
1035
|
-
*/
|
|
1036
|
-
type IsStringLiteral<S> = IfNotAnyOrNever<S, {
|
|
1037
|
-
ifNot: _IsStringLiteral<CollapseLiterals<S extends TagContainer<any> ? UnwrapTagged<S> : S>>;
|
|
1038
|
-
ifAny: false;
|
|
1039
|
-
ifNever: false;
|
|
1040
|
-
}>;
|
|
1041
|
-
type _IsStringLiteral<S> =
|
|
1042
|
-
// If `T` is an infinite string type (e.g., `on${string}`), `Record<T, never>` produces an index signature,
|
|
1043
|
-
// and since `{}` extends index signatures, the result becomes `false`.
|
|
1044
|
-
S extends string ? {} extends Record<S, never> ? false : true : false;
|
|
1045
|
-
//#endregion
|
|
1046
|
-
//#region ../../node_modules/.pnpm/type-fest@5.8.0/node_modules/type-fest/source/tuple-of.d.ts
|
|
1047
|
-
/**
|
|
1048
|
-
Create a tuple type of the specified length with elements of the specified type.
|
|
1049
|
-
|
|
1050
|
-
@example
|
|
1051
|
-
```
|
|
1052
|
-
import type {TupleOf} from 'type-fest';
|
|
1053
|
-
|
|
1054
|
-
type RGB = TupleOf<3, number>;
|
|
1055
|
-
//=> [number, number, number]
|
|
1056
|
-
|
|
1057
|
-
type Line = TupleOf<2, {x: number; y: number}>;
|
|
1058
|
-
//=> [{x: number; y: number}, {x: number; y: number}]
|
|
1059
|
-
|
|
1060
|
-
type TicTacToeBoard = TupleOf<3, TupleOf<3, 'X' | 'O' | null>>;
|
|
1061
|
-
//=> [['X' | 'O' | null, 'X' | 'O' | null, 'X' | 'O' | null], ['X' | 'O' | null, 'X' | 'O' | null, 'X' | 'O' | null], ['X' | 'O' | null, 'X' | 'O' | null, 'X' | 'O' | null]]
|
|
1062
|
-
```
|
|
1063
|
-
|
|
1064
|
-
@example
|
|
1065
|
-
```
|
|
1066
|
-
import type {TupleOf} from 'type-fest';
|
|
1067
|
-
|
|
1068
|
-
type Range<Start extends number, End extends number> = Exclude<keyof TupleOf<End>, keyof TupleOf<Start>>;
|
|
1069
|
-
|
|
1070
|
-
type ZeroToFour = Range<0, 5>;
|
|
1071
|
-
//=> '0' | '1' | '2' | '3' | '4'
|
|
1072
|
-
|
|
1073
|
-
type ThreeToEight = Range<3, 9>;
|
|
1074
|
-
//=> '3' | '4' | '5' | '6' | '7' | '8'
|
|
1075
|
-
```
|
|
1076
|
-
|
|
1077
|
-
Note: If the specified length is the non-literal `number` type, the result will not be a tuple but a regular array.
|
|
1078
|
-
|
|
1079
|
-
@example
|
|
1080
|
-
```
|
|
1081
|
-
import type {TupleOf} from 'type-fest';
|
|
1082
|
-
|
|
1083
|
-
type StringArray = TupleOf<number, string>;
|
|
1084
|
-
//=> string[]
|
|
1085
|
-
```
|
|
1086
|
-
|
|
1087
|
-
Note: If the type for elements is not specified, it will default to `unknown`.
|
|
1088
|
-
|
|
1089
|
-
@example
|
|
1090
|
-
```
|
|
1091
|
-
import type {TupleOf} from 'type-fest';
|
|
1092
|
-
|
|
1093
|
-
type UnknownTriplet = TupleOf<3>;
|
|
1094
|
-
//=> [unknown, unknown, unknown]
|
|
1095
|
-
```
|
|
1096
|
-
|
|
1097
|
-
Note: If the specified length is negative, the result will be an empty tuple.
|
|
1098
|
-
|
|
1099
|
-
@example
|
|
1100
|
-
```
|
|
1101
|
-
import type {TupleOf} from 'type-fest';
|
|
1102
|
-
|
|
1103
|
-
type EmptyTuple = TupleOf<-3, string>;
|
|
1104
|
-
//=> []
|
|
1105
|
-
```
|
|
1106
|
-
|
|
1107
|
-
Note: If the specified length has a decimal part, the decimal part will be ignored.
|
|
1108
|
-
|
|
1109
|
-
@example
|
|
1110
|
-
```
|
|
1111
|
-
import type {TupleOf} from 'type-fest';
|
|
1112
|
-
|
|
1113
|
-
type DecimalLength = TupleOf<3.5, string>;
|
|
1114
|
-
//=> [string, string, string]
|
|
1115
|
-
```
|
|
1116
|
-
|
|
1117
|
-
Note: If you need a readonly tuple, simply wrap this type with `Readonly`, for example, to create `readonly [number, number, number]` use `Readonly<TupleOf<3, number>>`.
|
|
1118
|
-
|
|
1119
|
-
@category Array
|
|
1120
|
-
*/
|
|
1121
|
-
type TupleOf<Length extends number, Fill = unknown> = IfNotAnyOrNever<Length, {
|
|
1122
|
-
ifNot: _TupleOf<If<IsNegative<Length>, 0, Length>, Fill>;
|
|
1123
|
-
ifAny: Fill[];
|
|
1124
|
-
ifNever: [];
|
|
1125
|
-
}>;
|
|
1126
|
-
type _TupleOf<Length extends number, Fill> = number extends Length ? Fill[] : BuildTupleDigitByDigit<`${Length}`, Fill>;
|
|
1127
|
-
type BuildTupleDigitByDigit<Length extends string, Fill, Accumulator extends UnknownArray = []> = Length extends `${infer First extends DigitCharacter}${infer Rest}` ? BuildTupleDigitByDigit<Rest, Fill, [...RepeatTupleTenTimes<Accumulator>, ...DigitTupleOf<First, Fill>]> : Accumulator;
|
|
1128
|
-
type RepeatTupleTenTimes<Tuple extends UnknownArray> = [...Tuple, ...Tuple, ...Tuple, ...Tuple, ...Tuple, ...Tuple, ...Tuple, ...Tuple, ...Tuple, ...Tuple];
|
|
1129
|
-
type DigitTupleOf<Digit extends DigitCharacter, Fill> = [[], [Fill], [Fill, Fill], [Fill, Fill, Fill], [Fill, Fill, Fill, Fill], [Fill, Fill, Fill, Fill, Fill], [Fill, Fill, Fill, Fill, Fill, Fill], [Fill, Fill, Fill, Fill, Fill, Fill, Fill], [Fill, Fill, Fill, Fill, Fill, Fill, Fill, Fill], [Fill, Fill, Fill, Fill, Fill, Fill, Fill, Fill, Fill]][Digit];
|
|
1130
|
-
//#endregion
|
|
1131
|
-
//#region ../../node_modules/.pnpm/type-fest@5.8.0/node_modules/type-fest/source/simplify.d.ts
|
|
1132
|
-
/**
|
|
1133
|
-
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.
|
|
1134
|
-
|
|
1135
|
-
@example
|
|
1136
|
-
```
|
|
1137
|
-
import type {Simplify} from 'type-fest';
|
|
1138
|
-
|
|
1139
|
-
type PositionProps = {
|
|
1140
|
-
top: number;
|
|
1141
|
-
left: number;
|
|
1142
|
-
};
|
|
1143
|
-
|
|
1144
|
-
type SizeProps = {
|
|
1145
|
-
width: number;
|
|
1146
|
-
height: number;
|
|
1147
|
-
};
|
|
1148
|
-
|
|
1149
|
-
// In your editor, hovering over `Props` will show a flattened object with all the properties.
|
|
1150
|
-
type Props = Simplify<PositionProps & SizeProps>;
|
|
1151
|
-
```
|
|
1152
|
-
|
|
1153
|
-
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.
|
|
1154
|
-
|
|
1155
|
-
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`.
|
|
1156
|
-
|
|
1157
|
-
@example
|
|
1158
|
-
```
|
|
1159
|
-
import type {Simplify} from 'type-fest';
|
|
1160
|
-
|
|
1161
|
-
interface SomeInterface {
|
|
1162
|
-
foo: number;
|
|
1163
|
-
bar?: string;
|
|
1164
|
-
baz: number | undefined;
|
|
1165
|
-
}
|
|
1166
|
-
|
|
1167
|
-
type SomeType = {
|
|
1168
|
-
foo: number;
|
|
1169
|
-
bar?: string;
|
|
1170
|
-
baz: number | undefined;
|
|
1171
|
-
};
|
|
1172
|
-
|
|
1173
|
-
const literal = {foo: 123, bar: 'hello', baz: 456};
|
|
1174
|
-
const someType: SomeType = literal;
|
|
1175
|
-
const someInterface: SomeInterface = literal;
|
|
1176
|
-
|
|
1177
|
-
declare function fn(object: Record<string, unknown>): void;
|
|
1178
|
-
|
|
1179
|
-
fn(literal); // Good: literal object type is sealed
|
|
1180
|
-
fn(someType); // Good: type is sealed
|
|
1181
|
-
// @ts-expect-error
|
|
1182
|
-
fn(someInterface); // Error: Index signature for type 'string' is missing in type 'someInterface'. Because `interface` can be re-opened
|
|
1183
|
-
fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface` into a `type`
|
|
1184
|
-
```
|
|
1185
|
-
|
|
1186
|
-
@link https://github.com/microsoft/TypeScript/issues/15300
|
|
1187
|
-
@see {@link SimplifyDeep}
|
|
1188
|
-
@category Object
|
|
1189
|
-
*/
|
|
1190
|
-
type Simplify<T> = { [KeyType in keyof T]: T[KeyType]; } & {};
|
|
1191
|
-
//#endregion
|
|
1192
|
-
//#region ../../node_modules/.pnpm/type-fest@5.8.0/node_modules/type-fest/source/is-equal.d.ts
|
|
1193
|
-
/**
|
|
1194
|
-
Returns a boolean for whether the two given types are equal.
|
|
1195
|
-
|
|
1196
|
-
@link https://github.com/microsoft/TypeScript/issues/27024#issuecomment-421529650
|
|
1197
|
-
@link https://stackoverflow.com/questions/68961864/how-does-the-equals-work-in-typescript/68963796#68963796
|
|
1198
|
-
|
|
1199
|
-
Use-cases:
|
|
1200
|
-
- If you want to make a conditional branch based on the result of a comparison of two types.
|
|
1201
|
-
|
|
1202
|
-
@example
|
|
1203
|
-
```
|
|
1204
|
-
import type {IsEqual} from 'type-fest';
|
|
1205
|
-
|
|
1206
|
-
// This type returns a boolean for whether the given array includes the given item.
|
|
1207
|
-
// `IsEqual` is used to compare the given array at position 0 and the given item and then return true if they are equal.
|
|
1208
|
-
type Includes<Value extends readonly any[], Item> =
|
|
1209
|
-
Value extends readonly [Value[0], ...infer rest]
|
|
1210
|
-
? IsEqual<Value[0], Item> extends true
|
|
1211
|
-
? true
|
|
1212
|
-
: Includes<rest, Item>
|
|
1213
|
-
: false;
|
|
1214
|
-
```
|
|
1215
|
-
|
|
1216
|
-
@category Type Guard
|
|
1217
|
-
@category Utilities
|
|
1218
|
-
*/
|
|
1219
|
-
type IsEqual<A, B> = [A] extends [B] ? [B] extends [A] ? _IsEqual<A, B> : false : false;
|
|
1220
|
-
// This version fails the `equalWrappedTupleIntersectionToBeNeverAndNeverExpanded` test in `test-d/is-equal.ts`.
|
|
1221
|
-
type _IsEqual<A, B> = (<G>() => G extends A & G | G ? 1 : 2) extends (<G>() => G extends B & G | G ? 1 : 2) ? true : false;
|
|
1222
|
-
//#endregion
|
|
1223
|
-
//#region ../../node_modules/.pnpm/type-fest@5.8.0/node_modules/type-fest/source/omit-index-signature.d.ts
|
|
1224
|
-
/**
|
|
1225
|
-
Omit any index signatures from the given object type, leaving only explicitly defined properties.
|
|
1226
|
-
|
|
1227
|
-
This is the counterpart of `PickIndexSignature`.
|
|
1228
|
-
|
|
1229
|
-
Use-cases:
|
|
1230
|
-
- Remove overly permissive signatures from third-party types.
|
|
1231
|
-
|
|
1232
|
-
This type was taken from this [StackOverflow answer](https://stackoverflow.com/a/68261113/420747).
|
|
1233
|
-
|
|
1234
|
-
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>`.
|
|
1235
|
-
|
|
1236
|
-
(The actual value type, `unknown`, is irrelevant and could be any type. Only the key type matters.)
|
|
1237
|
-
|
|
1238
|
-
```
|
|
1239
|
-
const indexed: Record<string, unknown> = {}; // Allowed
|
|
1240
|
-
|
|
1241
|
-
// @ts-expect-error
|
|
1242
|
-
const keyed: Record<'foo', unknown> = {}; // Error
|
|
1243
|
-
// TS2739: Type '{}' is missing the following properties from type 'Record<"foo" | "bar", unknown>': foo, bar
|
|
1244
|
-
```
|
|
1245
|
-
|
|
1246
|
-
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:
|
|
1247
|
-
|
|
1248
|
-
```
|
|
1249
|
-
type Indexed = {} extends Record<string, unknown>
|
|
1250
|
-
? '✅ `{}` is assignable to `Record<string, unknown>`'
|
|
1251
|
-
: '❌ `{}` is NOT assignable to `Record<string, unknown>`';
|
|
1252
|
-
|
|
1253
|
-
type IndexedResult = Indexed;
|
|
1254
|
-
//=> '✅ `{}` is assignable to `Record<string, unknown>`'
|
|
1255
|
-
|
|
1256
|
-
type Keyed = {} extends Record<'foo' | 'bar', unknown>
|
|
1257
|
-
? '✅ `{}` is assignable to `Record<\'foo\' | \'bar\', unknown>`'
|
|
1258
|
-
: '❌ `{}` is NOT assignable to `Record<\'foo\' | \'bar\', unknown>`';
|
|
1259
|
-
|
|
1260
|
-
type KeyedResult = Keyed;
|
|
1261
|
-
//=> '❌ `{}` is NOT assignable to `Record<\'foo\' | \'bar\', unknown>`'
|
|
1262
|
-
```
|
|
1263
|
-
|
|
1264
|
-
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`...
|
|
1265
|
-
|
|
1266
|
-
```
|
|
1267
|
-
type OmitIndexSignature<ObjectType> = {
|
|
1268
|
-
[KeyType in keyof ObjectType // Map each key of `ObjectType`...
|
|
1269
|
-
]: ObjectType[KeyType]; // ...to its original value, i.e. `OmitIndexSignature<Foo> == Foo`.
|
|
1270
|
-
};
|
|
1271
|
-
```
|
|
1272
|
-
|
|
1273
|
-
...whether an empty object (`{}`) would be assignable to an object with that `KeyType` (`Record<KeyType, unknown>`)...
|
|
1274
|
-
|
|
1275
|
-
```
|
|
1276
|
-
type OmitIndexSignature<ObjectType> = {
|
|
1277
|
-
[KeyType in keyof ObjectType
|
|
1278
|
-
// Is `{}` assignable to `Record<KeyType, unknown>`?
|
|
1279
|
-
as {} extends Record<KeyType, unknown>
|
|
1280
|
-
? never // ✅ `{}` is assignable to `Record<KeyType, unknown>`
|
|
1281
|
-
: KeyType // ❌ `{}` is NOT assignable to `Record<KeyType, unknown>`
|
|
1282
|
-
]: ObjectType[KeyType];
|
|
1283
|
-
};
|
|
1284
|
-
```
|
|
1285
|
-
|
|
1286
|
-
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.
|
|
1287
|
-
|
|
1288
|
-
@example
|
|
1289
|
-
```
|
|
1290
|
-
import type {OmitIndexSignature} from 'type-fest';
|
|
1291
|
-
|
|
1292
|
-
type Example = {
|
|
1293
|
-
// These index signatures will be removed.
|
|
1294
|
-
[x: string]: any;
|
|
1295
|
-
[x: number]: any;
|
|
1296
|
-
[x: symbol]: any;
|
|
1297
|
-
[x: `head-${string}`]: string;
|
|
1298
|
-
[x: `${string}-tail`]: string;
|
|
1299
|
-
[x: `head-${string}-tail`]: string;
|
|
1300
|
-
[x: `${bigint}`]: string;
|
|
1301
|
-
[x: `embedded-${number}`]: string;
|
|
1302
|
-
|
|
1303
|
-
// These explicitly defined keys will remain.
|
|
1304
|
-
foo: 'bar';
|
|
1305
|
-
qux?: 'baz';
|
|
1306
|
-
};
|
|
1307
|
-
|
|
1308
|
-
type ExampleWithoutIndexSignatures = OmitIndexSignature<Example>;
|
|
1309
|
-
//=> {foo: 'bar'; qux?: 'baz'}
|
|
1310
|
-
```
|
|
1311
|
-
|
|
1312
|
-
@see {@link PickIndexSignature}
|
|
1313
|
-
@category Object
|
|
1314
|
-
*/
|
|
1315
|
-
type OmitIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? never : KeyType]: ObjectType[KeyType]; };
|
|
1316
|
-
//#endregion
|
|
1317
|
-
//#region ../../node_modules/.pnpm/type-fest@5.8.0/node_modules/type-fest/source/pick-index-signature.d.ts
|
|
1318
|
-
/**
|
|
1319
|
-
Pick only index signatures from the given object type, leaving out all explicitly defined properties.
|
|
1320
|
-
|
|
1321
|
-
This is the counterpart of `OmitIndexSignature`.
|
|
1322
|
-
|
|
1323
|
-
@example
|
|
1324
|
-
```
|
|
1325
|
-
import type {PickIndexSignature} from 'type-fest';
|
|
1326
|
-
|
|
1327
|
-
declare const symbolKey: unique symbol;
|
|
1328
|
-
|
|
1329
|
-
type Example = {
|
|
1330
|
-
// These index signatures will remain.
|
|
1331
|
-
[x: string]: unknown;
|
|
1332
|
-
[x: number]: unknown;
|
|
1333
|
-
[x: symbol]: unknown;
|
|
1334
|
-
[x: `head-${string}`]: string;
|
|
1335
|
-
[x: `${string}-tail`]: string;
|
|
1336
|
-
[x: `head-${string}-tail`]: string;
|
|
1337
|
-
[x: `${bigint}`]: string;
|
|
1338
|
-
[x: `embedded-${number}`]: string;
|
|
1339
|
-
|
|
1340
|
-
// These explicitly defined keys will be removed.
|
|
1341
|
-
['kebab-case-key']: string;
|
|
1342
|
-
[symbolKey]: string;
|
|
1343
|
-
foo: 'bar';
|
|
1344
|
-
qux?: 'baz';
|
|
1345
|
-
};
|
|
1346
|
-
|
|
1347
|
-
type ExampleIndexSignature = PickIndexSignature<Example>;
|
|
1348
|
-
// {
|
|
1349
|
-
// [x: string]: unknown;
|
|
1350
|
-
// [x: number]: unknown;
|
|
1351
|
-
// [x: symbol]: unknown;
|
|
1352
|
-
// [x: `head-${string}`]: string;
|
|
1353
|
-
// [x: `${string}-tail`]: string;
|
|
1354
|
-
// [x: `head-${string}-tail`]: string;
|
|
1355
|
-
// [x: `${bigint}`]: string;
|
|
1356
|
-
// [x: `embedded-${number}`]: string;
|
|
1357
|
-
// }
|
|
1358
|
-
```
|
|
1359
|
-
|
|
1360
|
-
@see {@link OmitIndexSignature}
|
|
1361
|
-
@category Object
|
|
1362
|
-
*/
|
|
1363
|
-
type PickIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? KeyType : never]: ObjectType[KeyType]; };
|
|
1364
|
-
//#endregion
|
|
1365
|
-
//#region ../../node_modules/.pnpm/type-fest@5.8.0/node_modules/type-fest/source/merge.d.ts
|
|
1366
|
-
// Merges two objects without worrying about index signatures.
|
|
1367
|
-
type SimpleMerge<Destination, Source> = Simplify<{ [Key in keyof Destination as Key extends keyof Source ? never : Key]: Destination[Key]; } & Source>;
|
|
1368
|
-
/**
|
|
1369
|
-
Merge two types into a new type. Keys of the second type overrides keys of the first type.
|
|
1370
|
-
|
|
1371
|
-
This is different from the TypeScript `&` (intersection) operator. With `&`, conflicting property types are intersected, which often results in `never`. For example, `{a: string} & {a: number}` makes `a` become `string & number`, which resolves to `never`. With `Merge`, the second type's keys cleanly override the first, so `Merge<{a: string}, {a: number}>` gives `{a: number}` as expected. `Merge` also produces a flattened type (via `Simplify`), making it more readable in IDE tooltips compared to `A & B`.
|
|
1372
|
-
|
|
1373
|
-
@example
|
|
1374
|
-
```
|
|
1375
|
-
import type {Merge} from 'type-fest';
|
|
1376
|
-
|
|
1377
|
-
type Foo = {
|
|
1378
|
-
a: string;
|
|
1379
|
-
b: number;
|
|
1380
|
-
};
|
|
1381
|
-
|
|
1382
|
-
type Bar = {
|
|
1383
|
-
a: number; // Conflicts with Foo['a']
|
|
1384
|
-
c: boolean;
|
|
1385
|
-
};
|
|
1386
|
-
|
|
1387
|
-
// With `&`, `a` becomes `string & number` which is `never`. Not what you want.
|
|
1388
|
-
type WithIntersection = (Foo & Bar)['a'];
|
|
1389
|
-
//=> never
|
|
1390
|
-
|
|
1391
|
-
// With `Merge`, `a` is cleanly overridden to `number`.
|
|
1392
|
-
type WithMerge = Merge<Foo, Bar>['a'];
|
|
1393
|
-
//=> number
|
|
1394
|
-
```
|
|
1395
|
-
|
|
1396
|
-
@example
|
|
1397
|
-
```
|
|
1398
|
-
import type {Merge} from 'type-fest';
|
|
1399
|
-
|
|
1400
|
-
type Foo = {
|
|
1401
|
-
[x: string]: unknown;
|
|
1402
|
-
[x: number]: unknown;
|
|
1403
|
-
foo: string;
|
|
1404
|
-
bar: symbol;
|
|
1405
|
-
};
|
|
1406
|
-
|
|
1407
|
-
type Bar = {
|
|
1408
|
-
[x: number]: number;
|
|
1409
|
-
[x: symbol]: unknown;
|
|
1410
|
-
bar: Date;
|
|
1411
|
-
baz: boolean;
|
|
1412
|
-
};
|
|
1413
|
-
|
|
1414
|
-
export type FooBar = Merge<Foo, Bar>;
|
|
1415
|
-
//=> {
|
|
1416
|
-
// [x: string]: unknown;
|
|
1417
|
-
// [x: number]: number;
|
|
1418
|
-
// [x: symbol]: unknown;
|
|
1419
|
-
// foo: string;
|
|
1420
|
-
// bar: Date;
|
|
1421
|
-
// baz: boolean;
|
|
1422
|
-
// }
|
|
1423
|
-
```
|
|
1424
|
-
|
|
1425
|
-
Note: If you want a merge type that more accurately reflects the runtime behavior of object spread or `Object.assign`, refer to the {@link ObjectMerge} type.
|
|
1426
|
-
|
|
1427
|
-
@see {@link ObjectMerge}
|
|
1428
|
-
@category Object
|
|
1429
|
-
*/
|
|
1430
|
-
type Merge<Destination, Source> = Destination extends unknown // For distributing `Destination`
|
|
1431
|
-
? Source extends unknown // For distributing `Source`
|
|
1432
|
-
? If<IsEqual<Destination, Source>, Destination, _Merge<Destination, Source>> : never // Should never happen
|
|
1433
|
-
: never; // Should never happen
|
|
1434
|
-
type _Merge<Destination, Source> = Simplify<SimpleMerge<PickIndexSignature<Destination>, PickIndexSignature<Source>> & SimpleMerge<OmitIndexSignature<Destination>, OmitIndexSignature<Source>>>;
|
|
1435
|
-
//#endregion
|
|
1436
|
-
//#region ../../node_modules/.pnpm/type-fest@5.8.0/node_modules/type-fest/source/internal/object.d.ts
|
|
1437
|
-
/**
|
|
1438
|
-
Works similar to the built-in `Pick` utility type, except for the following differences:
|
|
1439
|
-
- Distributes over union types and allows picking keys from any member of the union type.
|
|
1440
|
-
- Primitives types are returned as-is.
|
|
1441
|
-
- Picks all keys if `Keys` is `any`.
|
|
1442
|
-
- Doesn't pick `number` from a `string` index signature.
|
|
1443
|
-
|
|
1444
|
-
@example
|
|
1445
|
-
```
|
|
1446
|
-
type ImageUpload = {
|
|
1447
|
-
url: string;
|
|
1448
|
-
size: number;
|
|
1449
|
-
thumbnailUrl: string;
|
|
1450
|
-
};
|
|
1451
|
-
|
|
1452
|
-
type VideoUpload = {
|
|
1453
|
-
url: string;
|
|
1454
|
-
duration: number;
|
|
1455
|
-
encodingFormat: string;
|
|
1456
|
-
};
|
|
1457
|
-
|
|
1458
|
-
// Distributes over union types and allows picking keys from any member of the union type
|
|
1459
|
-
type MediaDisplay = HomomorphicPick<ImageUpload | VideoUpload, "url" | "size" | "duration">;
|
|
1460
|
-
//=> {url: string; size: number} | {url: string; duration: number}
|
|
1461
|
-
|
|
1462
|
-
// Primitive types are returned as-is
|
|
1463
|
-
type Primitive = HomomorphicPick<string | number, 'toUpperCase' | 'toString'>;
|
|
1464
|
-
//=> string | number
|
|
1465
|
-
|
|
1466
|
-
// Picks all keys if `Keys` is `any`
|
|
1467
|
-
type Any = HomomorphicPick<{a: 1; b: 2} | {c: 3}, any>;
|
|
1468
|
-
//=> {a: 1; b: 2} | {c: 3}
|
|
1469
|
-
|
|
1470
|
-
// Doesn't pick `number` from a `string` index signature
|
|
1471
|
-
type IndexSignature = HomomorphicPick<{[k: string]: unknown}, number>;
|
|
1472
|
-
//=> {}
|
|
1473
|
-
*/
|
|
1474
|
-
type HomomorphicPick<T, Keys extends KeysOfUnion<T>> = { [P in keyof T as Extract<P, Keys>]: T[P]; };
|
|
1475
|
-
/**
|
|
1476
|
-
Merges user specified options with default options.
|
|
1477
|
-
|
|
1478
|
-
@example
|
|
1479
|
-
```
|
|
1480
|
-
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
1481
|
-
type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
|
|
1482
|
-
type SpecifiedOptions = {leavesOnly: true};
|
|
1483
|
-
|
|
1484
|
-
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
1485
|
-
//=> {maxRecursionDepth: 10; leavesOnly: true}
|
|
1486
|
-
```
|
|
1487
|
-
|
|
1488
|
-
@example
|
|
1489
|
-
```
|
|
1490
|
-
// Complains if default values are not provided for optional options
|
|
1491
|
-
|
|
1492
|
-
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
1493
|
-
type DefaultPathsOptions = {maxRecursionDepth: 10};
|
|
1494
|
-
type SpecifiedOptions = {};
|
|
1495
|
-
|
|
1496
|
-
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
1497
|
-
// ~~~~~~~~~~~~~~~~~~~
|
|
1498
|
-
// Property 'leavesOnly' is missing in type 'DefaultPathsOptions' but required in type '{ maxRecursionDepth: number; leavesOnly: boolean; }'.
|
|
1499
|
-
```
|
|
1500
|
-
|
|
1501
|
-
@example
|
|
1502
|
-
```
|
|
1503
|
-
// Complains if an option's default type does not conform to the expected type
|
|
1504
|
-
|
|
1505
|
-
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
1506
|
-
type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: 'no'};
|
|
1507
|
-
type SpecifiedOptions = {};
|
|
1508
|
-
|
|
1509
|
-
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
1510
|
-
// ~~~~~~~~~~~~~~~~~~~
|
|
1511
|
-
// Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
|
|
1512
|
-
```
|
|
1513
|
-
|
|
1514
|
-
@example
|
|
1515
|
-
```
|
|
1516
|
-
// Complains if an option's specified type does not conform to the expected type
|
|
1517
|
-
|
|
1518
|
-
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
1519
|
-
type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
|
|
1520
|
-
type SpecifiedOptions = {leavesOnly: 'yes'};
|
|
1521
|
-
|
|
1522
|
-
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
1523
|
-
// ~~~~~~~~~~~~~~~~
|
|
1524
|
-
// Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
|
|
1525
|
-
```
|
|
1526
|
-
*/
|
|
1527
|
-
type ApplyDefaultOptions<Options extends object, Defaults extends Simplify<Omit<Required<Options>, RequiredKeysOf<Options>> & Partial<Record<RequiredKeysOf<Options>, never>>>, SpecifiedOptions extends Options> = _ApplyDefaultOptions<Options, Defaults, SpecifiedOptions> extends (infer Result extends Required<Options> // `extends Required<Options>` ensures that `ApplyDefaultOptions<SomeOption, ...>` is always assignable to `Required<SomeOption>`
|
|
1528
|
-
) ? Result : never;
|
|
1529
|
-
type _ApplyDefaultOptions<Options, Defaults, SpecifiedOptions> = If<IsAny<SpecifiedOptions>, Defaults, If<IsNever<SpecifiedOptions>, Defaults, Merge<Defaults, { [Key in keyof SpecifiedOptions as undefined extends Required<Options>[Key & keyof Options] ? Key : undefined extends SpecifiedOptions[Key] ? never : Key]: SpecifiedOptions[Key]; }>>>;
|
|
1530
|
-
/**
|
|
1531
|
-
Collapses literal types in a union into their corresponding primitive types, when possible. For example, `CollapseLiterals<'foo' | 'bar' | (string & {})>` returns `string`.
|
|
1532
|
-
|
|
1533
|
-
Note: This doesn't collapse literals within tagged types. For example, `CollapseLiterals<Tagged<'foo' | (string & {}), 'Tag'>>` returns `("foo" & Tag<"Tag", never>) | (string & Tag<"Tag", never>)` and not `string & Tag<"Tag", never>`.
|
|
1534
|
-
|
|
1535
|
-
Use-case: For collapsing unions created using {@link LiteralUnion}.
|
|
1536
|
-
|
|
1537
|
-
@example
|
|
1538
|
-
```
|
|
1539
|
-
import type {LiteralUnion} from 'type-fest';
|
|
1540
|
-
|
|
1541
|
-
type A = CollapseLiterals<'foo' | 'bar' | (string & {})>;
|
|
1542
|
-
//=> string
|
|
1543
|
-
|
|
1544
|
-
type B = CollapseLiterals<LiteralUnion<1 | 2 | 3, number>>;
|
|
1545
|
-
//=> number
|
|
1546
|
-
|
|
1547
|
-
type C = CollapseLiterals<LiteralUnion<'onClick' | 'onChange', `on${string}`>>;
|
|
1548
|
-
//=> `on${string}`
|
|
1549
|
-
|
|
1550
|
-
type D = CollapseLiterals<'click' | 'change' | (`on${string}` & {})>;
|
|
1551
|
-
//=> 'click' | 'change' | `on${string}`
|
|
1552
|
-
|
|
1553
|
-
type E = CollapseLiterals<LiteralUnion<'foo' | 'bar', string> | null | undefined>;
|
|
1554
|
-
//=> string | null | undefined
|
|
1555
|
-
```
|
|
1556
|
-
*/
|
|
1557
|
-
type CollapseLiterals<T> = {} extends T ? T : T extends (infer U) & {} ? U : T;
|
|
1558
|
-
//#endregion
|
|
1559
|
-
//#region ../../node_modules/.pnpm/type-fest@5.8.0/node_modules/type-fest/source/some-extend.d.ts
|
|
1560
|
-
/**
|
|
1561
|
-
@see {@link SomeExtend}
|
|
1562
|
-
*/
|
|
1563
|
-
type SomeExtendOptions = {
|
|
1564
|
-
/**
|
|
1565
|
-
Consider `never` elements to match the target type only if the target type itself is `never` (or `any`).
|
|
1566
|
-
|
|
1567
|
-
- When set to `true` (default), `never` is _not_ treated as a bottom type, instead, it is treated as a type that matches only itself (or `any`).
|
|
1568
|
-
- When set to `false`, `never` is treated as a bottom type, and behaves as it normally would.
|
|
1569
|
-
|
|
1570
|
-
@default true
|
|
1571
|
-
|
|
1572
|
-
@example
|
|
1573
|
-
```
|
|
1574
|
-
import type {SomeExtend} from 'type-fest';
|
|
1575
|
-
|
|
1576
|
-
type A = SomeExtend<[1, 2, never], string, {strictNever: true}>;
|
|
1577
|
-
//=> false
|
|
1578
|
-
|
|
1579
|
-
type B = SomeExtend<[1, 2, never], string, {strictNever: false}>;
|
|
1580
|
-
//=> true
|
|
1581
|
-
|
|
1582
|
-
type C = SomeExtend<[1, never], never, {strictNever: true}>;
|
|
1583
|
-
//=> true
|
|
1584
|
-
|
|
1585
|
-
type D = SomeExtend<[1, never], never, {strictNever: false}>;
|
|
1586
|
-
//=> true
|
|
1587
|
-
|
|
1588
|
-
type E = SomeExtend<[never], any, {strictNever: true}>;
|
|
1589
|
-
//=> true
|
|
1590
|
-
|
|
1591
|
-
type F = SomeExtend<[never], any, {strictNever: false}>;
|
|
1592
|
-
//=> true
|
|
1593
|
-
```
|
|
1594
|
-
*/
|
|
1595
|
-
strictNever?: boolean;
|
|
1596
|
-
};
|
|
1597
|
-
type DefaultSomeExtendOptions = {
|
|
1598
|
-
strictNever: true;
|
|
1599
|
-
};
|
|
1600
|
-
/**
|
|
1601
|
-
Returns a boolean for whether some element in an array type extends another type.
|
|
1602
|
-
|
|
1603
|
-
@example
|
|
1604
|
-
```
|
|
1605
|
-
import type {SomeExtend} from 'type-fest';
|
|
1606
|
-
|
|
1607
|
-
type A = SomeExtend<['1', '2', 3], number>;
|
|
1608
|
-
//=> true
|
|
1609
|
-
|
|
1610
|
-
type B = SomeExtend<[1, 2, 3], string>;
|
|
1611
|
-
//=> false
|
|
1612
|
-
|
|
1613
|
-
type C = SomeExtend<[string, number | string], number>;
|
|
1614
|
-
//=> boolean
|
|
1615
|
-
|
|
1616
|
-
type D = SomeExtend<[true, boolean, true], false>;
|
|
1617
|
-
//=> boolean
|
|
1618
|
-
```
|
|
1619
|
-
|
|
1620
|
-
Note: Behaviour of optional elements depend on the `exactOptionalPropertyTypes` compiler option. When the option is disabled, the target type must include `undefined` for a successful match.
|
|
1621
|
-
|
|
1622
|
-
```
|
|
1623
|
-
// @exactOptionalPropertyTypes: true
|
|
1624
|
-
import type {SomeExtend} from 'type-fest';
|
|
1625
|
-
|
|
1626
|
-
type A = SomeExtend<[1?, 2?, '3'?], string>;
|
|
1627
|
-
//=> true
|
|
1628
|
-
```
|
|
1629
|
-
|
|
1630
|
-
```
|
|
1631
|
-
// @exactOptionalPropertyTypes: false
|
|
1632
|
-
import type {SomeExtend} from 'type-fest';
|
|
1633
|
-
|
|
1634
|
-
type A = SomeExtend<[1?, 2?, '3'?], string>;
|
|
1635
|
-
//=> boolean
|
|
1636
|
-
|
|
1637
|
-
type B = SomeExtend<[1?, 2?, '3'?], string | undefined>;
|
|
1638
|
-
//=> true
|
|
1639
|
-
```
|
|
1640
|
-
|
|
1641
|
-
@see {@link SomeExtendOptions}
|
|
1642
|
-
|
|
1643
|
-
@category Utilities
|
|
1644
|
-
@category Array
|
|
1645
|
-
*/
|
|
1646
|
-
type SomeExtend<TArray extends UnknownArray, Type, Options extends SomeExtendOptions = {}> = _SomeExtend<CollapseRestElement<TArray>, Type, ApplyDefaultOptions<SomeExtendOptions, DefaultSomeExtendOptions, Options>>;
|
|
1647
|
-
type _SomeExtend<TArray extends UnknownArray, Type, Options extends Required<SomeExtendOptions>> = IfNotAnyOrNever<TArray, {
|
|
1648
|
-
ifNot: TArray extends readonly [infer First, ...infer Rest] ? IsNever<First> extends true ? Or<Or<IsNever<Type>, IsAny<Type>>, Not<Options['strictNever']>> extends true ?
|
|
1649
|
-
// If target `Type` is also `never`, or is `any`, or `strictNever` is disabled, return `true`.
|
|
1650
|
-
true : _SomeExtend<Rest, Type, Options> : First extends Type ? true : _SomeExtend<Rest, Type, Options> : false;
|
|
1651
|
-
ifAny: false;
|
|
1652
|
-
ifNever: false;
|
|
1653
|
-
}>;
|
|
1654
|
-
//#endregion
|
|
1655
|
-
//#region ../../node_modules/.pnpm/type-fest@5.8.0/node_modules/type-fest/source/or-all.d.ts
|
|
1656
|
-
/**
|
|
1657
|
-
Returns a boolean for whether any of the given elements is `true`.
|
|
1658
|
-
|
|
1659
|
-
Use-cases:
|
|
1660
|
-
- Check if at least one condition in a list of booleans is met.
|
|
1661
|
-
|
|
1662
|
-
@example
|
|
1663
|
-
```
|
|
1664
|
-
import type {OrAll} from 'type-fest';
|
|
1665
|
-
|
|
1666
|
-
type FFT = OrAll<[false, false, true]>;
|
|
1667
|
-
//=> true
|
|
1668
|
-
|
|
1669
|
-
type FFF = OrAll<[false, false, false]>;
|
|
1670
|
-
//=> false
|
|
1671
|
-
```
|
|
1672
|
-
|
|
1673
|
-
Note: When `boolean` is passed as an element, it is distributed into separate cases, and the final result is a union of those cases.
|
|
1674
|
-
For example, `OrAll<[false, boolean]>` expands to `OrAll<[false, true]> | OrAll<[false, false]>`, which simplifies to `true | false` (i.e., `boolean`).
|
|
1675
|
-
|
|
1676
|
-
@example
|
|
1677
|
-
```
|
|
1678
|
-
import type {OrAll} from 'type-fest';
|
|
1679
|
-
|
|
1680
|
-
type A = OrAll<[false, boolean]>;
|
|
1681
|
-
//=> boolean
|
|
1682
|
-
|
|
1683
|
-
type B = OrAll<[true, boolean]>;
|
|
1684
|
-
//=> true
|
|
1685
|
-
```
|
|
1686
|
-
|
|
1687
|
-
Note: If `never` is passed as an element, it is treated as `false` and the result is computed accordingly.
|
|
1688
|
-
|
|
1689
|
-
@example
|
|
1690
|
-
```
|
|
1691
|
-
import type {OrAll} from 'type-fest';
|
|
1692
|
-
|
|
1693
|
-
type A = OrAll<[never, never, true]>;
|
|
1694
|
-
//=> true
|
|
1695
|
-
|
|
1696
|
-
type B = OrAll<[never, never, false]>;
|
|
1697
|
-
//=> false
|
|
1698
|
-
|
|
1699
|
-
type C = OrAll<[never, never, never]>;
|
|
1700
|
-
//=> false
|
|
1701
|
-
|
|
1702
|
-
type D = OrAll<[never, never, boolean]>;
|
|
1703
|
-
//=> boolean
|
|
1704
|
-
```
|
|
1705
|
-
|
|
1706
|
-
Note: If `any` is passed as an element, it is treated as `boolean` and the result is computed accordingly.
|
|
1707
|
-
|
|
1708
|
-
@example
|
|
1709
|
-
```
|
|
1710
|
-
import type {OrAll} from 'type-fest';
|
|
1711
|
-
|
|
1712
|
-
type A = OrAll<[false, any]>;
|
|
1713
|
-
//=> boolean
|
|
1714
|
-
|
|
1715
|
-
type B = OrAll<[true, any]>;
|
|
1716
|
-
//=> true
|
|
1717
|
-
```
|
|
1718
|
-
|
|
1719
|
-
Note: `OrAll<[]>` evaluates to `false` because there are no `true` elements in an empty tuple. See [Wikipedia: Clause (logic) > Empty clauses](https://en.wikipedia.org/wiki/Clause_(logic)#Empty_clauses:~:text=The%20truth%20evaluation%20of%20an%20empty%20disjunctive%20clause%20is%20always%20false.).
|
|
1720
|
-
|
|
1721
|
-
@see {@link Or}
|
|
1722
|
-
@see {@link AndAll}
|
|
1723
|
-
*/
|
|
1724
|
-
type OrAll<T extends readonly boolean[]> = SomeExtend<T, true>;
|
|
1725
|
-
//#endregion
|
|
1726
|
-
//#region ../../node_modules/.pnpm/type-fest@5.8.0/node_modules/type-fest/source/or.d.ts
|
|
1727
|
-
/**
|
|
1728
|
-
Returns a boolean for whether either of two given types is `true`.
|
|
1729
|
-
|
|
1730
|
-
Use-case: Constructing complex conditional types where at least one condition must be satisfied.
|
|
1731
|
-
|
|
1732
|
-
@example
|
|
1733
|
-
```
|
|
1734
|
-
import type {Or} from 'type-fest';
|
|
1735
|
-
|
|
1736
|
-
type TT = Or<true, true>;
|
|
1737
|
-
//=> true
|
|
1738
|
-
|
|
1739
|
-
type TF = Or<true, false>;
|
|
1740
|
-
//=> true
|
|
1741
|
-
|
|
1742
|
-
type FT = Or<false, true>;
|
|
1743
|
-
//=> true
|
|
1744
|
-
|
|
1745
|
-
type FF = Or<false, false>;
|
|
1746
|
-
//=> false
|
|
1747
|
-
```
|
|
1748
|
-
|
|
1749
|
-
Note: When `boolean` is passed as an argument, it is distributed into separate cases, and the final result is a union of those cases.
|
|
1750
|
-
For example, `Or<false, boolean>` expands to `Or<false, true> | Or<false, false>`, which simplifies to `true | false` (i.e., `boolean`).
|
|
1751
|
-
|
|
1752
|
-
@example
|
|
1753
|
-
```
|
|
1754
|
-
import type {Or} from 'type-fest';
|
|
1755
|
-
|
|
1756
|
-
type A = Or<false, boolean>;
|
|
1757
|
-
//=> boolean
|
|
1758
|
-
|
|
1759
|
-
type B = Or<boolean, false>;
|
|
1760
|
-
//=> boolean
|
|
1761
|
-
|
|
1762
|
-
type C = Or<true, boolean>;
|
|
1763
|
-
//=> true
|
|
1764
|
-
|
|
1765
|
-
type D = Or<boolean, true>;
|
|
1766
|
-
//=> true
|
|
1767
|
-
|
|
1768
|
-
type E = Or<boolean, boolean>;
|
|
1769
|
-
//=> boolean
|
|
1770
|
-
```
|
|
1771
|
-
|
|
1772
|
-
Note: If `never` is passed as an argument, it is treated as `false` and the result is computed accordingly.
|
|
1773
|
-
|
|
1774
|
-
@example
|
|
1775
|
-
```
|
|
1776
|
-
import type {Or} from 'type-fest';
|
|
1777
|
-
|
|
1778
|
-
type A = Or<true, never>;
|
|
1779
|
-
//=> true
|
|
1780
|
-
|
|
1781
|
-
type B = Or<never, true>;
|
|
1782
|
-
//=> true
|
|
1783
|
-
|
|
1784
|
-
type C = Or<false, never>;
|
|
1785
|
-
//=> false
|
|
1786
|
-
|
|
1787
|
-
type D = Or<never, false>;
|
|
1788
|
-
//=> false
|
|
1789
|
-
|
|
1790
|
-
type E = Or<boolean, never>;
|
|
1791
|
-
//=> boolean
|
|
1792
|
-
|
|
1793
|
-
type F = Or<never, boolean>;
|
|
1794
|
-
//=> boolean
|
|
1795
|
-
|
|
1796
|
-
type G = Or<never, never>;
|
|
1797
|
-
//=> false
|
|
1798
|
-
```
|
|
1799
|
-
|
|
1800
|
-
@see {@link OrAll}
|
|
1801
|
-
@see {@link And}
|
|
1802
|
-
@see {@link Xor}
|
|
1803
|
-
*/
|
|
1804
|
-
type Or<A extends boolean, B extends boolean> = OrAll<[A, B]>;
|
|
1805
|
-
//#endregion
|
|
1806
|
-
//#region ../../node_modules/.pnpm/type-fest@5.8.0/node_modules/type-fest/source/all-extend.d.ts
|
|
1807
|
-
/**
|
|
1808
|
-
@see {@link AllExtend}
|
|
1809
|
-
*/
|
|
1810
|
-
type AllExtendOptions = {
|
|
1811
|
-
/**
|
|
1812
|
-
Consider `never` elements to match the target type only if the target type itself is `never` (or `any`).
|
|
1813
|
-
|
|
1814
|
-
- When set to `true` (default), `never` is _not_ treated as a bottom type, instead, it is treated as a type that matches only itself (or `any`).
|
|
1815
|
-
- When set to `false`, `never` is treated as a bottom type, and behaves as it normally would.
|
|
1816
|
-
|
|
1817
|
-
@default true
|
|
1818
|
-
|
|
1819
|
-
@example
|
|
1820
|
-
```
|
|
1821
|
-
import type {AllExtend} from 'type-fest';
|
|
1822
|
-
|
|
1823
|
-
type A = AllExtend<[1, 2, never], number, {strictNever: true}>;
|
|
1824
|
-
//=> false
|
|
1825
|
-
|
|
1826
|
-
type B = AllExtend<[1, 2, never], number, {strictNever: false}>;
|
|
1827
|
-
//=> true
|
|
1828
|
-
|
|
1829
|
-
type C = AllExtend<[never, never], never, {strictNever: true}>;
|
|
1830
|
-
//=> true
|
|
1831
|
-
|
|
1832
|
-
type D = AllExtend<[never, never], never, {strictNever: false}>;
|
|
1833
|
-
//=> true
|
|
1834
|
-
|
|
1835
|
-
type E = AllExtend<['a', 'b', never], any, {strictNever: true}>;
|
|
1836
|
-
//=> true
|
|
1837
|
-
|
|
1838
|
-
type F = AllExtend<['a', 'b', never], any, {strictNever: false}>;
|
|
1839
|
-
//=> true
|
|
1840
|
-
|
|
1841
|
-
type G = AllExtend<[never, 1], never, {strictNever: true}>;
|
|
1842
|
-
//=> false
|
|
1843
|
-
|
|
1844
|
-
type H = AllExtend<[never, 1], never, {strictNever: false}>;
|
|
1845
|
-
//=> false
|
|
1846
|
-
```
|
|
1847
|
-
*/
|
|
1848
|
-
strictNever?: boolean;
|
|
1849
|
-
};
|
|
1850
|
-
type DefaultAllExtendOptions = {
|
|
1851
|
-
strictNever: true;
|
|
1852
|
-
};
|
|
1853
|
-
/**
|
|
1854
|
-
Returns a boolean for whether every element in an array type extends another type.
|
|
1855
|
-
|
|
1856
|
-
@example
|
|
1857
|
-
```
|
|
1858
|
-
import type {AllExtend} from 'type-fest';
|
|
1859
|
-
|
|
1860
|
-
type A = AllExtend<[1, 2, 3], number>;
|
|
1861
|
-
//=> true
|
|
1862
|
-
|
|
1863
|
-
type B = AllExtend<[1, 2, '3'], number>;
|
|
1864
|
-
//=> false
|
|
1865
|
-
|
|
1866
|
-
type C = AllExtend<[number, number | string], number>;
|
|
1867
|
-
//=> boolean
|
|
1868
|
-
|
|
1869
|
-
type D = AllExtend<[true, boolean, true], true>;
|
|
1870
|
-
//=> boolean
|
|
1871
|
-
```
|
|
1872
|
-
|
|
1873
|
-
Note: Behaviour of optional elements depend on the `exactOptionalPropertyTypes` compiler option. When the option is disabled, the target type must include `undefined` for a successful match.
|
|
1874
|
-
|
|
1875
|
-
```
|
|
1876
|
-
// @exactOptionalPropertyTypes: true
|
|
1877
|
-
import type {AllExtend} from 'type-fest';
|
|
1878
|
-
|
|
1879
|
-
type A = AllExtend<[1?, 2?, 3?], number>;
|
|
1880
|
-
//=> true
|
|
1881
|
-
```
|
|
1882
|
-
|
|
1883
|
-
```
|
|
1884
|
-
// @exactOptionalPropertyTypes: false
|
|
1885
|
-
import type {AllExtend} from 'type-fest';
|
|
1886
|
-
|
|
1887
|
-
type A = AllExtend<[1?, 2?, 3?], number>;
|
|
1888
|
-
//=> boolean
|
|
1889
|
-
|
|
1890
|
-
type B = AllExtend<[1?, 2?, 3?], number | undefined>;
|
|
1891
|
-
//=> true
|
|
1892
|
-
```
|
|
1893
|
-
|
|
1894
|
-
@see {@link AllExtendOptions}
|
|
1895
|
-
|
|
1896
|
-
@category Utilities
|
|
1897
|
-
@category Array
|
|
1898
|
-
*/
|
|
1899
|
-
type AllExtend<TArray extends UnknownArray, Type, Options extends AllExtendOptions = {}> = _AllExtend<CollapseRestElement<TArray>, Type, ApplyDefaultOptions<AllExtendOptions, DefaultAllExtendOptions, Options>>;
|
|
1900
|
-
type _AllExtend<TArray extends UnknownArray, Type, Options extends Required<AllExtendOptions>> = IfNotAnyOrNever<TArray, {
|
|
1901
|
-
ifNot: TArray extends readonly [infer First, ...infer Rest] ? IsNever<First> extends true ? Or<Or<IsNever<Type>, IsAny<Type>>, Not<Options['strictNever']>> extends true ?
|
|
1902
|
-
// If target `Type` is also `never`, or is `any`, or `strictNever` is disabled, recurse further.
|
|
1903
|
-
_AllExtend<Rest, Type, Options> : false : First extends Type ? _AllExtend<Rest, Type, Options> : false : true;
|
|
1904
|
-
ifAny: false;
|
|
1905
|
-
ifNever: false;
|
|
1906
|
-
}>;
|
|
1907
|
-
//#endregion
|
|
1908
|
-
//#region ../../node_modules/.pnpm/type-fest@5.8.0/node_modules/type-fest/source/and-all.d.ts
|
|
1909
|
-
/**
|
|
1910
|
-
Returns a boolean for whether all of the given elements are `true`.
|
|
1911
|
-
|
|
1912
|
-
Use-cases:
|
|
1913
|
-
- Check if all conditions in a list of booleans are met.
|
|
1914
|
-
|
|
1915
|
-
@example
|
|
1916
|
-
```
|
|
1917
|
-
import type {AndAll} from 'type-fest';
|
|
1918
|
-
|
|
1919
|
-
type TTT = AndAll<[true, true, true]>;
|
|
1920
|
-
//=> true
|
|
1921
|
-
|
|
1922
|
-
type TTF = AndAll<[true, true, false]>;
|
|
1923
|
-
//=> false
|
|
1924
|
-
|
|
1925
|
-
type TFT = AndAll<[true, false, true]>;
|
|
1926
|
-
//=> false
|
|
1927
|
-
```
|
|
1928
|
-
|
|
1929
|
-
Note: When `boolean` is passed as an element, it is distributed into separate cases, and the final result is a union of those cases.
|
|
1930
|
-
For example, `AndAll<[true, boolean]>` expands to `AndAll<[true, true]> | AndAll<[true, false]>`, which simplifies to `true | false` (i.e., `boolean`).
|
|
1931
|
-
|
|
1932
|
-
@example
|
|
1933
|
-
```
|
|
1934
|
-
import type {AndAll} from 'type-fest';
|
|
1935
|
-
|
|
1936
|
-
type A = AndAll<[true, boolean]>;
|
|
1937
|
-
//=> boolean
|
|
1938
|
-
|
|
1939
|
-
type B = AndAll<[false, boolean]>;
|
|
1940
|
-
//=> false
|
|
1941
|
-
```
|
|
1942
|
-
|
|
1943
|
-
Note: If any of the elements is `never`, the result becomes `false`.
|
|
1944
|
-
|
|
1945
|
-
@example
|
|
1946
|
-
```
|
|
1947
|
-
import type {AndAll} from 'type-fest';
|
|
1948
|
-
|
|
1949
|
-
type A = AndAll<[true, true, never]>;
|
|
1950
|
-
//=> false
|
|
1951
|
-
|
|
1952
|
-
type B = AndAll<[false, never, never]>;
|
|
1953
|
-
//=> false
|
|
1954
|
-
|
|
1955
|
-
type C = AndAll<[never, never, never]>;
|
|
1956
|
-
//=> false
|
|
1957
|
-
|
|
1958
|
-
type D = AndAll<[boolean, true, never]>;
|
|
1959
|
-
//=> false
|
|
1960
|
-
```
|
|
1961
|
-
|
|
1962
|
-
Note: If `any` is passed as an element, it is treated as `boolean` and the result is computed accordingly.
|
|
1963
|
-
|
|
1964
|
-
@example
|
|
1965
|
-
```
|
|
1966
|
-
import type {AndAll} from 'type-fest';
|
|
1967
|
-
|
|
1968
|
-
type A = AndAll<[false, any]>;
|
|
1969
|
-
//=> false
|
|
1970
|
-
|
|
1971
|
-
type B = AndAll<[true, any]>;
|
|
1972
|
-
//=> boolean
|
|
1973
|
-
```
|
|
1974
|
-
|
|
1975
|
-
Note: `AndAll<[]>` evaluates to `true` due to the concept of [vacuous truth](https://en.wikipedia.org/wiki/Logical_conjunction#:~:text=In%20keeping%20with%20the%20concept%20of%20vacuous%20truth%2C%20when%20conjunction%20is%20defined%20as%20an%20operator%20or%20function%20of%20arbitrary%20arity%2C%20the%20empty%20conjunction%20(AND%2Ding%20over%20an%20empty%20set%20of%20operands)%20is%20often%20defined%20as%20having%20the%20result%20true.), i.e., there are no `false` elements in an empty tuple.
|
|
1976
|
-
|
|
1977
|
-
@see {@link And}
|
|
1978
|
-
@see {@link OrAll}
|
|
1979
|
-
*/
|
|
1980
|
-
type AndAll<T extends readonly boolean[]> = AllExtend<T, true>;
|
|
1981
|
-
//#endregion
|
|
1982
|
-
//#region ../../node_modules/.pnpm/type-fest@5.8.0/node_modules/type-fest/source/and.d.ts
|
|
1983
|
-
/**
|
|
1984
|
-
Returns a boolean for whether two given types are both `true`.
|
|
1985
|
-
|
|
1986
|
-
Use-case: Constructing complex conditional types where multiple conditions must be satisfied.
|
|
1987
|
-
|
|
1988
|
-
@example
|
|
1989
|
-
```
|
|
1990
|
-
import type {And} from 'type-fest';
|
|
1991
|
-
|
|
1992
|
-
type TT = And<true, true>;
|
|
1993
|
-
//=> true
|
|
1994
|
-
|
|
1995
|
-
type TF = And<true, false>;
|
|
1996
|
-
//=> false
|
|
1997
|
-
|
|
1998
|
-
type FT = And<false, true>;
|
|
1999
|
-
//=> false
|
|
2000
|
-
|
|
2001
|
-
type FF = And<false, false>;
|
|
2002
|
-
//=> false
|
|
2003
|
-
```
|
|
2004
|
-
|
|
2005
|
-
Note: When `boolean` is passed as an argument, it is distributed into separate cases, and the final result is a union of those cases.
|
|
2006
|
-
For example, `And<true, boolean>` expands to `And<true, true> | And<true, false>`, which simplifies to `true | false` (i.e., `boolean`).
|
|
2007
|
-
|
|
2008
|
-
@example
|
|
2009
|
-
```
|
|
2010
|
-
import type {And} from 'type-fest';
|
|
2011
|
-
|
|
2012
|
-
type A = And<true, boolean>;
|
|
2013
|
-
//=> boolean
|
|
2014
|
-
|
|
2015
|
-
type B = And<boolean, true>;
|
|
2016
|
-
//=> boolean
|
|
2017
|
-
|
|
2018
|
-
type C = And<false, boolean>;
|
|
2019
|
-
//=> false
|
|
2020
|
-
|
|
2021
|
-
type D = And<boolean, false>;
|
|
2022
|
-
//=> false
|
|
2023
|
-
|
|
2024
|
-
type E = And<boolean, boolean>;
|
|
2025
|
-
//=> boolean
|
|
2026
|
-
```
|
|
2027
|
-
|
|
2028
|
-
Note: If either of the types is `never`, the result becomes `false`.
|
|
2029
|
-
|
|
2030
|
-
@example
|
|
2031
|
-
```
|
|
2032
|
-
import type {And} from 'type-fest';
|
|
2033
|
-
|
|
2034
|
-
type A = And<true, never>;
|
|
2035
|
-
//=> false
|
|
2036
|
-
|
|
2037
|
-
type B = And<never, true>;
|
|
2038
|
-
//=> false
|
|
2039
|
-
|
|
2040
|
-
type C = And<false, never>;
|
|
2041
|
-
//=> false
|
|
2042
|
-
|
|
2043
|
-
type D = And<never, false>;
|
|
2044
|
-
//=> false
|
|
2045
|
-
|
|
2046
|
-
type E = And<boolean, never>;
|
|
2047
|
-
//=> false
|
|
2048
|
-
|
|
2049
|
-
type F = And<never, boolean>;
|
|
2050
|
-
//=> false
|
|
2051
|
-
|
|
2052
|
-
type G = And<never, never>;
|
|
2053
|
-
//=> false
|
|
2054
|
-
```
|
|
2055
|
-
|
|
2056
|
-
@see {@link AndAll}
|
|
2057
|
-
@see {@link Or}
|
|
2058
|
-
@see {@link Xor}
|
|
2059
|
-
*/
|
|
2060
|
-
type And<A extends boolean, B extends boolean> = AndAll<[A, B]>;
|
|
2061
|
-
//#endregion
|
|
2062
|
-
//#region ../../node_modules/.pnpm/type-fest@5.8.0/node_modules/type-fest/source/except.d.ts
|
|
2063
|
-
/**
|
|
2064
|
-
Filter out keys from an object.
|
|
2065
|
-
|
|
2066
|
-
Returns `never` if `Exclude` is strictly equal to `Key`.
|
|
2067
|
-
Returns `never` if `Key` extends `Exclude`.
|
|
2068
|
-
Returns `Key` otherwise.
|
|
2069
|
-
|
|
2070
|
-
@example
|
|
2071
|
-
```
|
|
2072
|
-
type Filtered = Filter<'foo', 'foo'>;
|
|
2073
|
-
//=> never
|
|
2074
|
-
```
|
|
2075
|
-
|
|
2076
|
-
@example
|
|
2077
|
-
```
|
|
2078
|
-
type Filtered = Filter<'bar', string>;
|
|
2079
|
-
//=> never
|
|
2080
|
-
```
|
|
2081
|
-
|
|
2082
|
-
@example
|
|
2083
|
-
```
|
|
2084
|
-
type Filtered = Filter<'bar', 'foo'>;
|
|
2085
|
-
//=> 'bar'
|
|
2086
|
-
```
|
|
2087
|
-
|
|
2088
|
-
@see {Except}
|
|
2089
|
-
*/
|
|
2090
|
-
type Filter<KeyType, ExcludeType> = IsEqual<KeyType, ExcludeType> extends true ? never : (KeyType extends ExcludeType ? never : KeyType);
|
|
2091
|
-
type ExceptOptions = {
|
|
2092
|
-
/**
|
|
2093
|
-
Disallow assigning non-specified properties.
|
|
2094
|
-
|
|
2095
|
-
Note that any omitted properties in the resulting type will be present in autocomplete as `undefined`.
|
|
2096
|
-
|
|
2097
|
-
@default false
|
|
2098
|
-
*/
|
|
2099
|
-
requireExactProps?: boolean;
|
|
2100
|
-
};
|
|
2101
|
-
type DefaultExceptOptions = {
|
|
2102
|
-
requireExactProps: false;
|
|
2103
|
-
};
|
|
2104
|
-
/**
|
|
2105
|
-
Create a type from an object type without certain keys.
|
|
2106
|
-
|
|
2107
|
-
We recommend setting the `requireExactProps` option to `true`.
|
|
2108
|
-
|
|
2109
|
-
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.
|
|
2110
|
-
|
|
2111
|
-
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)).
|
|
2112
|
-
|
|
2113
|
-
@example
|
|
2114
|
-
```
|
|
2115
|
-
import type {Except} from 'type-fest';
|
|
2116
|
-
|
|
2117
|
-
type Foo = {
|
|
2118
|
-
a: number;
|
|
2119
|
-
b: string;
|
|
2120
|
-
};
|
|
2121
|
-
|
|
2122
|
-
type FooWithoutA = Except<Foo, 'a'>;
|
|
2123
|
-
//=> {b: string}
|
|
2124
|
-
|
|
2125
|
-
// @ts-expect-error
|
|
2126
|
-
const fooWithoutA: FooWithoutA = {a: 1, b: '2'};
|
|
2127
|
-
// errors: 'a' does not exist in type '{ b: string; }'
|
|
2128
|
-
|
|
2129
|
-
type FooWithoutB = Except<Foo, 'b', {requireExactProps: true}>;
|
|
2130
|
-
//=> {a: number} & Partial<Record<'b', never>>
|
|
2131
|
-
|
|
2132
|
-
// @ts-expect-error
|
|
2133
|
-
const fooWithoutB: FooWithoutB = {a: 1, b: '2'};
|
|
2134
|
-
// errors at 'b': Type 'string' is not assignable to type 'undefined'.
|
|
2135
|
-
|
|
2136
|
-
// The `Omit` utility type doesn't work when omitting specific keys from objects containing index signatures.
|
|
2137
|
-
|
|
2138
|
-
// Consider the following example:
|
|
2139
|
-
|
|
2140
|
-
type UserData = {
|
|
2141
|
-
[metadata: string]: string;
|
|
2142
|
-
email: string;
|
|
2143
|
-
name: string;
|
|
2144
|
-
role: 'admin' | 'user';
|
|
2145
|
-
};
|
|
2146
|
-
|
|
2147
|
-
// `Omit` clearly doesn't behave as expected in this case:
|
|
2148
|
-
type PostPayload = Omit<UserData, 'email'>;
|
|
2149
|
-
//=> {[x: string]: string; [x: number]: string}
|
|
2150
|
-
|
|
2151
|
-
// In situations like this, `Except` works better.
|
|
2152
|
-
// It simply removes the `email` key while preserving all the other keys.
|
|
2153
|
-
type PostPayloadFixed = Except<UserData, 'email'>;
|
|
2154
|
-
//=> {[x: string]: string; name: string; role: 'admin' | 'user'}
|
|
2155
|
-
```
|
|
2156
|
-
|
|
2157
|
-
@category Object
|
|
2158
|
-
*/
|
|
2159
|
-
type Except<ObjectType, KeysType extends keyof ObjectType, Options extends ExceptOptions = {}> = _Except<ObjectType, KeysType, ApplyDefaultOptions<ExceptOptions, DefaultExceptOptions, Options>>;
|
|
2160
|
-
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>> : {});
|
|
2161
|
-
//#endregion
|
|
2162
|
-
//#region ../../node_modules/.pnpm/type-fest@5.8.0/node_modules/type-fest/source/exclude-exactly.d.ts
|
|
2163
|
-
/**
|
|
2164
|
-
A stricter version of `Exclude<T, U>` that excludes types only when they are exactly identical.
|
|
2165
|
-
|
|
2166
|
-
@example
|
|
2167
|
-
```
|
|
2168
|
-
import type {ExcludeExactly} from 'type-fest';
|
|
2169
|
-
|
|
2170
|
-
type TestExclude1 = Exclude<'a' | 'b' | 'c' | 1 | 2 | 3, string>;
|
|
2171
|
-
//=> 1 | 2 | 3
|
|
2172
|
-
|
|
2173
|
-
type TestExcludeExactly1 = ExcludeExactly<'a' | 'b' | 'c' | 1 | 2 | 3, string>;
|
|
2174
|
-
//=> 'a' | 'b' | 'c' | 1 | 2 | 3
|
|
2175
|
-
|
|
2176
|
-
type TestExclude2 = Exclude<'a' | 'b' | 'c' | 1 | 2 | 3, any>;
|
|
2177
|
-
//=> never
|
|
2178
|
-
|
|
2179
|
-
type TestExcludeExactly2 = ExcludeExactly<'a' | 'b' | 'c' | 1 | 2 | 3, any>;
|
|
2180
|
-
//=> 'a' | 'b' | 'c' | 1 | 2 | 3
|
|
2181
|
-
|
|
2182
|
-
type TestExclude3 = Exclude<{a: string} | {a: string; b: string}, {a: string}>;
|
|
2183
|
-
//=> never
|
|
2184
|
-
|
|
2185
|
-
type TestExcludeExactly3 = ExcludeExactly<{a: string} | {a: string; b: string}, {a: string}>;
|
|
2186
|
-
//=> {a: string; b: string}
|
|
2187
|
-
```
|
|
2188
|
-
|
|
2189
|
-
@category Improved Built-in
|
|
2190
|
-
*/
|
|
2191
|
-
type ExcludeExactly<Union, Delete> = IfNotAnyOrNever<Union, {
|
|
2192
|
-
ifNot: _ExcludeExactly<Union, Delete>;
|
|
2193
|
-
// If `Union` is `any`, then if `Delete` is `any`, return `never`, else return `Union`.
|
|
2194
|
-
ifAny: If<IsAny<Delete>, never, Union>;
|
|
2195
|
-
// If `Union` is `never`, then if `Delete` is `never`, return `never`, else return `Union`.
|
|
2196
|
-
ifNever: If<IsNever<Delete>, never, Union>;
|
|
2197
|
-
}>;
|
|
2198
|
-
type _ExcludeExactly<Union, Delete> = IfNotAnyOrNever<Delete, {
|
|
2199
|
-
ifNot: Union extends unknown // For distributing `Union`
|
|
2200
|
-
? [Delete extends unknown // For distributing `Delete`
|
|
2201
|
-
? If<IsEqual<Union, Delete>, true, never> : never] extends [never] ? Union : never : never;
|
|
2202
|
-
// If `Delete` is `any` or `never`, then return `Union`,
|
|
2203
|
-
// because `Union` cannot be `any` or `never` here.
|
|
2204
|
-
ifAny: Union;
|
|
2205
|
-
ifNever: Union;
|
|
2206
|
-
}>;
|
|
2207
|
-
//#endregion
|
|
2208
|
-
//#region ../../node_modules/.pnpm/type-fest@5.8.0/node_modules/type-fest/source/union-member.d.ts
|
|
2209
|
-
/**
|
|
2210
|
-
Returns an arbitrary member of a union type.
|
|
2211
|
-
|
|
2212
|
-
Use-cases:
|
|
2213
|
-
- Implementing recursive type functions that accept a union type.
|
|
2214
|
-
|
|
2215
|
-
@example
|
|
2216
|
-
```
|
|
2217
|
-
import type {UnionMember, IsNever} from 'type-fest';
|
|
2218
|
-
|
|
2219
|
-
type UnionLength<T, Acc extends any[] = []> =
|
|
2220
|
-
UnionMember<T> extends infer Member
|
|
2221
|
-
? IsNever<Member> extends false
|
|
2222
|
-
? UnionLength<Exclude<T, Member>, [...Acc, Member]>
|
|
2223
|
-
: Acc['length']
|
|
2224
|
-
: never;
|
|
2225
|
-
|
|
2226
|
-
type T1 = UnionLength<'foo' | 'bar' | 'baz'>;
|
|
2227
|
-
//=> 3
|
|
2228
|
-
|
|
2229
|
-
type T2 = UnionLength<{a: string}>;
|
|
2230
|
-
//=> 1
|
|
2231
|
-
```
|
|
2232
|
-
|
|
2233
|
-
- Picking an arbitrary member from a union
|
|
2234
|
-
|
|
2235
|
-
@example
|
|
2236
|
-
```
|
|
2237
|
-
import type {UnionMember, Primitive, LiteralToPrimitive} from 'type-fest';
|
|
2238
|
-
|
|
2239
|
-
type IsHomogenous<T extends Primitive> = [T] extends [LiteralToPrimitive<UnionMember<T>>] ? true : false;
|
|
2240
|
-
|
|
2241
|
-
type T1 = IsHomogenous<1 | 2 | 3 | 4>;
|
|
2242
|
-
//=> true
|
|
2243
|
-
|
|
2244
|
-
type T2 = IsHomogenous<'foo' | 'bar'>;
|
|
2245
|
-
//=> true
|
|
2246
|
-
|
|
2247
|
-
type T3 = IsHomogenous<'foo' | 'bar' | 1>;
|
|
2248
|
-
//=> false
|
|
2249
|
-
```
|
|
2250
|
-
|
|
2251
|
-
Returns `never` when the input is `never`.
|
|
2252
|
-
|
|
2253
|
-
@example
|
|
2254
|
-
```
|
|
2255
|
-
import type {UnionMember} from 'type-fest';
|
|
2256
|
-
|
|
2257
|
-
type LastNever = UnionMember<never>;
|
|
2258
|
-
//=> never
|
|
2259
|
-
```
|
|
2260
|
-
|
|
2261
|
-
@category Type
|
|
2262
|
-
*/
|
|
2263
|
-
type UnionMember<T> = IsNever<T> extends true ? never : UnionToIntersection<T extends any ? () => T : never> extends (() => (infer R)) ? R : never;
|
|
2264
|
-
//#endregion
|
|
2265
|
-
//#region ../../node_modules/.pnpm/type-fest@5.8.0/node_modules/type-fest/source/union-to-tuple.d.ts
|
|
2266
|
-
/**
|
|
2267
|
-
Convert a union type into an unordered tuple type of its elements.
|
|
2268
|
-
|
|
2269
|
-
"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.
|
|
2270
|
-
|
|
2271
|
-
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.
|
|
2272
|
-
|
|
2273
|
-
@example
|
|
2274
|
-
```
|
|
2275
|
-
import type {UnionToTuple} from 'type-fest';
|
|
2276
|
-
|
|
2277
|
-
type Numbers = 1 | 2 | 3;
|
|
2278
|
-
type NumbersTuple = UnionToTuple<Numbers>;
|
|
2279
|
-
//=> [1, 2, 3]
|
|
2280
|
-
```
|
|
2281
|
-
|
|
2282
|
-
@example
|
|
2283
|
-
```
|
|
2284
|
-
import type {UnionToTuple} from 'type-fest';
|
|
2285
|
-
|
|
2286
|
-
const pets = {
|
|
2287
|
-
dog: '🐶',
|
|
2288
|
-
cat: '🐱',
|
|
2289
|
-
snake: '🐍',
|
|
2290
|
-
};
|
|
2291
|
-
|
|
2292
|
-
type Pet = keyof typeof pets;
|
|
2293
|
-
//=> 'dog' | 'cat' | 'snake'
|
|
2294
|
-
|
|
2295
|
-
const petList = Object.keys(pets) as UnionToTuple<Pet>;
|
|
2296
|
-
//=> ['dog', 'cat', 'snake']
|
|
2297
|
-
```
|
|
2298
|
-
|
|
2299
|
-
@category Array
|
|
2300
|
-
*/
|
|
2301
|
-
type UnionToTuple<Union> = _UnionToTuple<Union> extends (infer Result extends UnknownArray) ? Result : never; // Nudges the compiler that `UnionToTuple` always yields an array.
|
|
2302
|
-
type _UnionToTuple<Union, Accumulator extends UnknownArray = [], Member = UnionMember<Union>> = IsNever<Union> extends true ? Accumulator : _UnionToTuple<ExcludeExactly<Union, Member>, [Member, ...Accumulator]>;
|
|
2303
|
-
//#endregion
|
|
2304
|
-
//#region ../../node_modules/.pnpm/type-fest@5.8.0/node_modules/type-fest/source/set-optional.d.ts
|
|
2305
|
-
/**
|
|
2306
|
-
Create a type that makes the given keys optional, while keeping the remaining keys as is.
|
|
2307
|
-
|
|
2308
|
-
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.
|
|
2309
|
-
|
|
2310
|
-
@example
|
|
2311
|
-
```
|
|
2312
|
-
import type {SetOptional} from 'type-fest';
|
|
2313
|
-
|
|
2314
|
-
type Foo = {
|
|
2315
|
-
a: number;
|
|
2316
|
-
b?: string;
|
|
2317
|
-
c: boolean;
|
|
2318
|
-
};
|
|
2319
|
-
|
|
2320
|
-
type SomeOptional = SetOptional<Foo, 'b' | 'c'>;
|
|
2321
|
-
//=> {a: number; b?: string; c?: boolean}
|
|
2322
|
-
```
|
|
2323
|
-
|
|
2324
|
-
@category Object
|
|
2325
|
-
*/
|
|
2326
|
-
type SetOptional<BaseType, Keys extends keyof BaseType> = (BaseType extends ((...arguments_: never) => any) ? (...arguments_: Parameters<BaseType>) => ReturnType<BaseType> : unknown) & _SetOptional<BaseType, Keys>;
|
|
2327
|
-
type _SetOptional<BaseType, Keys extends keyof BaseType> = BaseType extends unknown // To distribute `BaseType` when it's a union type.
|
|
2328
|
-
? Simplify<
|
|
2329
|
-
// Pick just the keys that are readonly from the base type.
|
|
2330
|
-
Except<BaseType, Keys> &
|
|
2331
|
-
// Pick the keys that should be mutable from the base type and make them mutable.
|
|
2332
|
-
Partial<HomomorphicPick<BaseType, Keys>>> : never;
|
|
2333
|
-
//#endregion
|
|
2334
|
-
//#region ../../node_modules/.pnpm/type-fest@5.8.0/node_modules/type-fest/source/value-of.d.ts
|
|
2335
|
-
/**
|
|
2336
|
-
Create a union of the given object's values, and optionally specify which keys to get the values from.
|
|
2337
|
-
|
|
2338
|
-
Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/31438) if you want to have this type as a built-in in TypeScript.
|
|
2339
|
-
|
|
2340
|
-
@example
|
|
2341
|
-
```
|
|
2342
|
-
import type {ValueOf} from 'type-fest';
|
|
2343
|
-
|
|
2344
|
-
type A = ValueOf<{id: number; name: string; active: boolean}>;
|
|
2345
|
-
//=> string | number | boolean
|
|
2346
|
-
|
|
2347
|
-
type B = ValueOf<{id: number; name: string; active: boolean}, 'name'>;
|
|
2348
|
-
//=> string
|
|
2349
|
-
|
|
2350
|
-
type C = ValueOf<{id: number; name: string; active: boolean}, 'id' | 'name'>;
|
|
2351
|
-
//=> string | number
|
|
2352
|
-
```
|
|
2353
|
-
|
|
2354
|
-
@category Object
|
|
2355
|
-
*/
|
|
2356
|
-
type ValueOf<ObjectType, ValueType extends keyof ObjectType = keyof ObjectType> = ObjectType[ValueType];
|
|
2357
|
-
//#endregion
|
|
2358
|
-
//#region ../../node_modules/.pnpm/type-fest@5.8.0/node_modules/type-fest/source/split.d.ts
|
|
2359
|
-
/**
|
|
2360
|
-
Split options.
|
|
2361
|
-
|
|
2362
|
-
@see {@link Split}
|
|
2363
|
-
*/
|
|
2364
|
-
type SplitOptions = {
|
|
2365
|
-
/**
|
|
2366
|
-
When enabled, instantiations with non-literal string types (e.g., `string`, `Uppercase<string>`, `on${string}`) simply return back `string[]` without performing any splitting, as the exact structure cannot be statically determined.
|
|
2367
|
-
|
|
2368
|
-
@default true
|
|
2369
|
-
|
|
2370
|
-
@example
|
|
2371
|
-
```ts
|
|
2372
|
-
import type {Split} from 'type-fest';
|
|
2373
|
-
|
|
2374
|
-
type Example1 = Split<`foo.${string}.bar`, '.', {strictLiteralChecks: false}>;
|
|
2375
|
-
//=> ['foo', string, 'bar']
|
|
2376
|
-
|
|
2377
|
-
type Example2 = Split<`foo.${string}`, '.', {strictLiteralChecks: true}>;
|
|
2378
|
-
//=> string[]
|
|
2379
|
-
|
|
2380
|
-
type Example3 = Split<'foobarbaz', `b${string}`, {strictLiteralChecks: false}>;
|
|
2381
|
-
//=> ['foo', 'r', 'z']
|
|
2382
|
-
|
|
2383
|
-
type Example4 = Split<'foobarbaz', `b${string}`, {strictLiteralChecks: true}>;
|
|
2384
|
-
//=> string[]
|
|
2385
|
-
```
|
|
2386
|
-
*/
|
|
2387
|
-
strictLiteralChecks?: boolean;
|
|
2388
|
-
};
|
|
2389
|
-
type DefaultSplitOptions = {
|
|
2390
|
-
strictLiteralChecks: true;
|
|
2391
|
-
};
|
|
2392
|
-
/**
|
|
2393
|
-
Represents an array of strings split using a given character or character set.
|
|
2394
|
-
|
|
2395
|
-
Use-case: Defining the return type of a method like `String.prototype.split`.
|
|
2396
|
-
|
|
2397
|
-
@example
|
|
2398
|
-
```
|
|
2399
|
-
import type {Split} from 'type-fest';
|
|
2400
|
-
|
|
2401
|
-
declare function split<S extends string, D extends string>(string: S, separator: D): Split<S, D>;
|
|
2402
|
-
|
|
2403
|
-
type Item = 'foo' | 'bar' | 'baz' | 'waldo';
|
|
2404
|
-
const items = 'foo,bar,baz,waldo';
|
|
2405
|
-
const array: Item[] = split(items, ',');
|
|
2406
|
-
```
|
|
2407
|
-
|
|
2408
|
-
@see {@link SplitOptions}
|
|
2409
|
-
|
|
2410
|
-
@category String
|
|
2411
|
-
@category Template literal
|
|
2412
|
-
*/
|
|
2413
|
-
type Split<S extends string, Delimiter extends string, Options extends SplitOptions = {}> = SplitHelper<S, Delimiter, ApplyDefaultOptions<SplitOptions, DefaultSplitOptions, Options>>;
|
|
2414
|
-
type SplitHelper<S extends string, Delimiter extends string, Options extends Required<SplitOptions>, Accumulator extends string[] = []> = S extends string // For distributing `S`
|
|
2415
|
-
? Delimiter extends string // For distributing `Delimiter`
|
|
2416
|
-
?
|
|
2417
|
-
// If `strictLiteralChecks` is `false` OR `S` and `Delimiter` both are string literals, then perform the split
|
|
2418
|
-
Or<Not<Options['strictLiteralChecks']>, And<IsStringLiteral<S>, IsStringLiteral<Delimiter>>> extends true ? S extends `${infer Head}${Delimiter}${infer Tail}` ? SplitHelper<Tail, Delimiter, Options, [...Accumulator, Head]> : Delimiter extends '' ? S extends '' ? Accumulator : [...Accumulator, S] : [...Accumulator, S] :
|
|
2419
|
-
// Otherwise, return `string[]`
|
|
2420
|
-
string[] : never // Should never happen
|
|
2421
|
-
: never; // Should never happen
|
|
2422
|
-
//#endregion
|
|
2423
|
-
//#region ../../node_modules/.pnpm/type-fest@5.8.0/node_modules/type-fest/source/replace.d.ts
|
|
2424
|
-
type ReplaceOptions = {
|
|
2425
|
-
all?: boolean;
|
|
2426
|
-
};
|
|
2427
|
-
type DefaultReplaceOptions = {
|
|
2428
|
-
all: false;
|
|
2429
|
-
};
|
|
2430
|
-
/**
|
|
2431
|
-
Represents a string with some or all matches replaced by a replacement.
|
|
2432
|
-
|
|
2433
|
-
Use-case:
|
|
2434
|
-
- `kebab-case-path` to `dotted.path.notation`
|
|
2435
|
-
- Changing date/time format: `01-08-2042` → `01/08/2042`
|
|
2436
|
-
- Manipulation of type properties, for example, removal of prefixes
|
|
2437
|
-
|
|
2438
|
-
@example
|
|
2439
|
-
```
|
|
2440
|
-
import type {Replace} from 'type-fest';
|
|
2441
|
-
|
|
2442
|
-
declare function replace<
|
|
2443
|
-
Input extends string,
|
|
2444
|
-
Search extends string,
|
|
2445
|
-
Replacement extends string,
|
|
2446
|
-
>(
|
|
2447
|
-
input: Input,
|
|
2448
|
-
search: Search,
|
|
2449
|
-
replacement: Replacement,
|
|
2450
|
-
): Replace<Input, Search, Replacement>;
|
|
2451
|
-
|
|
2452
|
-
declare function replaceAll<
|
|
2453
|
-
Input extends string,
|
|
2454
|
-
Search extends string,
|
|
2455
|
-
Replacement extends string,
|
|
2456
|
-
>(
|
|
2457
|
-
input: Input,
|
|
2458
|
-
search: Search,
|
|
2459
|
-
replacement: Replacement,
|
|
2460
|
-
): Replace<Input, Search, Replacement, {all: true}>;
|
|
2461
|
-
|
|
2462
|
-
// The return type is the exact string literal, not just `string`.
|
|
2463
|
-
|
|
2464
|
-
replace('hello ?', '?', '🦄');
|
|
2465
|
-
//=> 'hello 🦄'
|
|
2466
|
-
|
|
2467
|
-
replace('hello ??', '?', '❓');
|
|
2468
|
-
//=> 'hello ❓?'
|
|
2469
|
-
|
|
2470
|
-
replaceAll('10:42:00', ':', '-');
|
|
2471
|
-
//=> '10-42-00'
|
|
2472
|
-
|
|
2473
|
-
replaceAll('__userName__', '__', '');
|
|
2474
|
-
//=> 'userName'
|
|
2475
|
-
|
|
2476
|
-
replaceAll('My Cool Title', ' ', '');
|
|
2477
|
-
//=> 'MyCoolTitle'
|
|
2478
|
-
```
|
|
2479
|
-
|
|
2480
|
-
@category String
|
|
2481
|
-
@category Template literal
|
|
2482
|
-
*/
|
|
2483
|
-
type Replace<Input extends string, Search extends string, Replacement extends string, Options extends ReplaceOptions = {}> = _Replace<Input, Search, Replacement, ApplyDefaultOptions<ReplaceOptions, DefaultReplaceOptions, Options>>;
|
|
2484
|
-
type _Replace<Input extends string, Search extends string, Replacement extends string, Options extends Required<ReplaceOptions>, Accumulator extends string = ''> = Search extends string // For distributing `Search`
|
|
2485
|
-
? Replacement extends string // For distributing `Replacement`
|
|
2486
|
-
? 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;
|
|
2487
|
-
//#endregion
|
|
2488
356
|
//#region src/currency/index.type.d.ts
|
|
2489
357
|
type CurrencyCode = keyof typeof CurrencyUtil.CURRENCY_ENUM;
|
|
2490
358
|
type CurrencyLocale = ValueOf<typeof CurrencyUtil.CURRENCY_ENUM>;
|
|
2491
359
|
interface FormatterOptions {
|
|
2492
360
|
locales: [CurrencyLocale, CurrencyLocale];
|
|
2493
361
|
currencySign: string;
|
|
2494
|
-
currencySignPosition: "
|
|
362
|
+
currencySignPosition: "start" | "end";
|
|
2495
363
|
currencyFormatOptions: Intl.NumberFormatOptions;
|
|
2496
|
-
precision?: number | undefined;
|
|
2497
364
|
}
|
|
2498
365
|
//#endregion
|
|
2499
366
|
//#region src/currency/currencyUtil.d.ts
|
|
@@ -2623,7 +490,7 @@ declare class CurrencyUtil {
|
|
|
2623
490
|
/**
|
|
2624
491
|
* 货币格式化
|
|
2625
492
|
* - 使用 `Intl.NumberFormat` 进行本地化数字格式化
|
|
2626
|
-
* -
|
|
493
|
+
* - 支持自定义货币符号及位置(首/尾)
|
|
2627
494
|
* - 当值为 `null` 或 `undefined` 时返回 `null`
|
|
2628
495
|
*
|
|
2629
496
|
* @param value 待格式化的数值
|
|
@@ -2642,7 +509,7 @@ declare class CurrencyUtil {
|
|
|
2642
509
|
* CurrencyUtil.currencyFormatter(1234.56, {
|
|
2643
510
|
* locales: [CurrencyUtil.CURRENCY_ENUM.CNY, CurrencyUtil.CURRENCY_ENUM.USD],
|
|
2644
511
|
* currencySign: "¥",
|
|
2645
|
-
* currencySignPosition: "
|
|
512
|
+
* currencySignPosition: "start",
|
|
2646
513
|
* currencyFormatOptions: { style: "currency", currency: "CNY" },
|
|
2647
514
|
* }); // "¥ 1,234.56"
|
|
2648
515
|
*
|
|
@@ -2651,7 +518,7 @@ declare class CurrencyUtil {
|
|
|
2651
518
|
* CurrencyUtil.currencyFormatter(undefined, options); // null
|
|
2652
519
|
* ```
|
|
2653
520
|
*/
|
|
2654
|
-
static currencyFormatter(value: string | number, options: FormatterOptions): string;
|
|
521
|
+
static currencyFormatter(value: string | number, options: FormatterOptions): string | null;
|
|
2655
522
|
static currencyFormatter(value: string | number | null | undefined, options: FormatterOptions): string | null;
|
|
2656
523
|
/**
|
|
2657
524
|
* 将任意数值转换为精确的十进制值
|
|
@@ -2678,12 +545,19 @@ declare class CurrencyUtil {
|
|
|
2678
545
|
* // 重载 2: stringMode = false → number
|
|
2679
546
|
* CurrencyUtil.toRealValue(math, "0.1", undefined, false); // 0.1
|
|
2680
547
|
*
|
|
2681
|
-
* // 重载 3: null / undefined
|
|
548
|
+
* // 重载 3: null / undefined(含 stringMode 显式组合)
|
|
2682
549
|
* CurrencyUtil.toRealValue(math, null); // null
|
|
550
|
+
* CurrencyUtil.toRealValue(math, undefined); // null
|
|
551
|
+
* CurrencyUtil.toRealValue(math, null, 2, true); // null
|
|
552
|
+
* CurrencyUtil.toRealValue(math, null, 2, false); // null
|
|
2683
553
|
* ```
|
|
2684
554
|
*/
|
|
2685
|
-
static toRealValue(mathJsInstance: MathJsInstance, value: string | number, precision
|
|
2686
|
-
static toRealValue(mathJsInstance: MathJsInstance, value: string | number
|
|
555
|
+
static toRealValue(mathJsInstance: MathJsInstance, value: string | number, precision: number | undefined, stringMode: true): string;
|
|
556
|
+
static toRealValue(mathJsInstance: MathJsInstance, value: string | number, precision: number | undefined, stringMode: false): number;
|
|
557
|
+
static toRealValue(mathJsInstance: MathJsInstance, value: string | number, precision?: number | undefined): string;
|
|
558
|
+
static toRealValue(mathJsInstance: MathJsInstance, value: string | number | null | undefined, precision: number | undefined, stringMode: true): string | null;
|
|
559
|
+
static toRealValue(mathJsInstance: MathJsInstance, value: string | number | null | undefined, precision: number | undefined, stringMode: false): number | null;
|
|
560
|
+
static toRealValue(mathJsInstance: MathJsInstance, value: string | number | null | undefined, precision?: number | undefined): string | null;
|
|
2687
561
|
}
|
|
2688
562
|
//#endregion
|
|
2689
563
|
//#region src/dateTime/dateTimeUtil.d.ts
|
|
@@ -2847,6 +721,8 @@ declare class DateTimeUtil {
|
|
|
2847
721
|
//#region src/env/envUtil.d.ts
|
|
2848
722
|
/**
|
|
2849
723
|
* 环境检查工具类
|
|
724
|
+
* - ⚠️ `isBrowser` / `isWebWorker` / `isReactNative` 基于静态字段判定,在**模块加载时**求值一次。
|
|
725
|
+
* SSR 场景下若在 Node 端 import(此时 `window` 未定义),结果会永久为 `false`,不会随运行时环境变化重算。
|
|
2850
726
|
*/
|
|
2851
727
|
declare class EnvUtil {
|
|
2852
728
|
private static readonly _isBrowser;
|
|
@@ -2970,6 +846,7 @@ declare class EnvUtil {
|
|
|
2970
846
|
* @param maxWidth - 平板最大宽度(默认 1200px)
|
|
2971
847
|
* @param dpi - 标准 DPI 基准(默认 160)
|
|
2972
848
|
* @returns 是否为平板设备
|
|
849
|
+
* - 宽度命中 `[minWidth, maxWidth]` 区间,或 CSS/DPI 折算尺寸落在 `[7, 13)` 英寸(排除 DPR=1 的 1920×1080 桌面)
|
|
2973
850
|
* @example
|
|
2974
851
|
* ```ts
|
|
2975
852
|
* // 假设 window.innerWidth = 1000
|
|
@@ -2979,22 +856,6 @@ declare class EnvUtil {
|
|
|
2979
856
|
static isTablet(minWidth?: number, maxWidth?: number, dpi?: number): boolean;
|
|
2980
857
|
}
|
|
2981
858
|
//#endregion
|
|
2982
|
-
//#region ../../node_modules/.pnpm/@pawover+types@0.0.4_@types+react@19.2.15_typescript@6.0.3/node_modules/@pawover/types/dist/index.d.ts
|
|
2983
|
-
/** 任意对象类型 */
|
|
2984
|
-
type AnyObject<K extends PropertyKey = PropertyKey, T = any> = Record<K, T>;
|
|
2985
|
-
/** 普通对象类型 */
|
|
2986
|
-
type PlainObject<K extends PropertyKey = PropertyKey, T = unknown> = Record<K, T>;
|
|
2987
|
-
/** 描述树类型 */
|
|
2988
|
-
type TreeLike<T extends AnyObject, CK extends string = "children"> = T & Record<CK, TreeLike<T, CK>[]>;
|
|
2989
|
-
/** 描述函数类型 */
|
|
2990
|
-
type AnyFunction<P extends any[] = any[], R = any> = (...arg: P) => R;
|
|
2991
|
-
/** 描述异步函数类型 */
|
|
2992
|
-
type AnyAsyncFunction<P extends any[] = any[], R = any> = (...args: P) => Promise<R>;
|
|
2993
|
-
/** 描述生成器函数类型 */
|
|
2994
|
-
type AnyGeneratorFunction<P extends any[] = any[], T = any, R = any, N = any> = (...args: P) => Generator<T, R, N>;
|
|
2995
|
-
/** 描述异步生成器函数类型 */
|
|
2996
|
-
type AnyAsyncGeneratorFunction<P extends any[] = any[], T = any, R = any, N = any> = (...args: P) => AsyncGenerator<T, R, N>;
|
|
2997
|
-
//#endregion
|
|
2998
859
|
//#region src/function/functionUtil.d.ts
|
|
2999
860
|
/**
|
|
3000
861
|
* 函数工具类
|
|
@@ -3356,478 +1217,15 @@ declare class NumberUtil {
|
|
|
3356
1217
|
static within(input: number, interval: [number, number], includeLeft?: boolean, includeRight?: boolean): boolean;
|
|
3357
1218
|
}
|
|
3358
1219
|
//#endregion
|
|
3359
|
-
//#region ../../node_modules/.pnpm/ts-toolbelt@9.6.0/node_modules/ts-toolbelt/out/List/List.d.ts
|
|
3360
|
-
/**
|
|
3361
|
-
* A [[List]]
|
|
3362
|
-
* @param A its type
|
|
3363
|
-
* @returns [[List]]
|
|
3364
|
-
* @example
|
|
3365
|
-
* ```ts
|
|
3366
|
-
* type list0 = [1, 2, 3]
|
|
3367
|
-
* type list1 = number[]
|
|
3368
|
-
* ```
|
|
3369
|
-
*/
|
|
3370
|
-
declare type List<A = any> = ReadonlyArray<A>;
|
|
3371
|
-
//#endregion
|
|
3372
|
-
//#region ../../node_modules/.pnpm/ts-toolbelt@9.6.0/node_modules/ts-toolbelt/out/Any/Cast.d.ts
|
|
3373
|
-
/**
|
|
3374
|
-
* Ask TS to re-check that `A1` extends `A2`.
|
|
3375
|
-
* And if it fails, `A2` will be enforced anyway.
|
|
3376
|
-
* Can also be used to add constraints on parameters.
|
|
3377
|
-
* @param A1 to check against
|
|
3378
|
-
* @param A2 to cast to
|
|
3379
|
-
* @returns `A1 | A2`
|
|
3380
|
-
* @example
|
|
3381
|
-
* ```ts
|
|
3382
|
-
* import {A} from 'ts-toolbelt'
|
|
3383
|
-
*
|
|
3384
|
-
* type test0 = A.Cast<'42', string> // '42'
|
|
3385
|
-
* type test1 = A.Cast<'42', number> // number
|
|
3386
|
-
* ```
|
|
3387
|
-
*/
|
|
3388
|
-
declare type Cast<A1 extends any, A2 extends any> = A1 extends A2 ? A1 : A2;
|
|
3389
|
-
//#endregion
|
|
3390
|
-
//#region ../../node_modules/.pnpm/ts-toolbelt@9.6.0/node_modules/ts-toolbelt/out/Any/Extends.d.ts
|
|
3391
|
-
/**
|
|
3392
|
-
* Check whether `A1` is part of `A2` or not. The difference with
|
|
3393
|
-
* `extends` is that it forces a [[Boolean]] return.
|
|
3394
|
-
* @param A1
|
|
3395
|
-
* @param A2
|
|
3396
|
-
* @returns [[Boolean]]
|
|
3397
|
-
* @example
|
|
3398
|
-
* ```ts
|
|
3399
|
-
* import {A} from 'ts-toolbelt'
|
|
3400
|
-
*
|
|
3401
|
-
* type test0 = A.Extends<'a' | 'b', 'b'> // Boolean
|
|
3402
|
-
* type test1 = A.Extends<'a', 'a' | 'b'> // True
|
|
3403
|
-
*
|
|
3404
|
-
* type test2 = A.Extends<{a: string}, {a: any}> // True
|
|
3405
|
-
* type test3 = A.Extends<{a: any}, {a: any, b: any}> // False
|
|
3406
|
-
*
|
|
3407
|
-
* type test4 = A.Extends<never, never> // False
|
|
3408
|
-
* /// Nothing cannot extend nothing, use `A.Equals`
|
|
3409
|
-
* ```
|
|
3410
|
-
*/
|
|
3411
|
-
declare type Extends<A1 extends any, A2 extends any> = [A1] extends [never] ? 0 : A1 extends A2 ? 1 : 0;
|
|
3412
|
-
//#endregion
|
|
3413
|
-
//#region ../../node_modules/.pnpm/ts-toolbelt@9.6.0/node_modules/ts-toolbelt/out/Iteration/Iteration.d.ts
|
|
3414
|
-
/**
|
|
3415
|
-
* An entry of `IterationMap`
|
|
3416
|
-
*/
|
|
3417
|
-
declare type Iteration = [value: number, sign: '-' | '0' | '+', prev: keyof IterationMap, next: keyof IterationMap, oppo: keyof IterationMap];
|
|
3418
|
-
declare type IterationMap = {
|
|
3419
|
-
'__': [number, '-' | '0' | '+', '__', '__', '__'];
|
|
3420
|
-
'-100': [-100, '-', '__', '-99', '100'];
|
|
3421
|
-
'-99': [-99, '-', '-100', '-98', '99'];
|
|
3422
|
-
'-98': [-98, '-', '-99', '-97', '98'];
|
|
3423
|
-
'-97': [-97, '-', '-98', '-96', '97'];
|
|
3424
|
-
'-96': [-96, '-', '-97', '-95', '96'];
|
|
3425
|
-
'-95': [-95, '-', '-96', '-94', '95'];
|
|
3426
|
-
'-94': [-94, '-', '-95', '-93', '94'];
|
|
3427
|
-
'-93': [-93, '-', '-94', '-92', '93'];
|
|
3428
|
-
'-92': [-92, '-', '-93', '-91', '92'];
|
|
3429
|
-
'-91': [-91, '-', '-92', '-90', '91'];
|
|
3430
|
-
'-90': [-90, '-', '-91', '-89', '90'];
|
|
3431
|
-
'-89': [-89, '-', '-90', '-88', '89'];
|
|
3432
|
-
'-88': [-88, '-', '-89', '-87', '88'];
|
|
3433
|
-
'-87': [-87, '-', '-88', '-86', '87'];
|
|
3434
|
-
'-86': [-86, '-', '-87', '-85', '86'];
|
|
3435
|
-
'-85': [-85, '-', '-86', '-84', '85'];
|
|
3436
|
-
'-84': [-84, '-', '-85', '-83', '84'];
|
|
3437
|
-
'-83': [-83, '-', '-84', '-82', '83'];
|
|
3438
|
-
'-82': [-82, '-', '-83', '-81', '82'];
|
|
3439
|
-
'-81': [-81, '-', '-82', '-80', '81'];
|
|
3440
|
-
'-80': [-80, '-', '-81', '-79', '80'];
|
|
3441
|
-
'-79': [-79, '-', '-80', '-78', '79'];
|
|
3442
|
-
'-78': [-78, '-', '-79', '-77', '78'];
|
|
3443
|
-
'-77': [-77, '-', '-78', '-76', '77'];
|
|
3444
|
-
'-76': [-76, '-', '-77', '-75', '76'];
|
|
3445
|
-
'-75': [-75, '-', '-76', '-74', '75'];
|
|
3446
|
-
'-74': [-74, '-', '-75', '-73', '74'];
|
|
3447
|
-
'-73': [-73, '-', '-74', '-72', '73'];
|
|
3448
|
-
'-72': [-72, '-', '-73', '-71', '72'];
|
|
3449
|
-
'-71': [-71, '-', '-72', '-70', '71'];
|
|
3450
|
-
'-70': [-70, '-', '-71', '-69', '70'];
|
|
3451
|
-
'-69': [-69, '-', '-70', '-68', '69'];
|
|
3452
|
-
'-68': [-68, '-', '-69', '-67', '68'];
|
|
3453
|
-
'-67': [-67, '-', '-68', '-66', '67'];
|
|
3454
|
-
'-66': [-66, '-', '-67', '-65', '66'];
|
|
3455
|
-
'-65': [-65, '-', '-66', '-64', '65'];
|
|
3456
|
-
'-64': [-64, '-', '-65', '-63', '64'];
|
|
3457
|
-
'-63': [-63, '-', '-64', '-62', '63'];
|
|
3458
|
-
'-62': [-62, '-', '-63', '-61', '62'];
|
|
3459
|
-
'-61': [-61, '-', '-62', '-60', '61'];
|
|
3460
|
-
'-60': [-60, '-', '-61', '-59', '60'];
|
|
3461
|
-
'-59': [-59, '-', '-60', '-58', '59'];
|
|
3462
|
-
'-58': [-58, '-', '-59', '-57', '58'];
|
|
3463
|
-
'-57': [-57, '-', '-58', '-56', '57'];
|
|
3464
|
-
'-56': [-56, '-', '-57', '-55', '56'];
|
|
3465
|
-
'-55': [-55, '-', '-56', '-54', '55'];
|
|
3466
|
-
'-54': [-54, '-', '-55', '-53', '54'];
|
|
3467
|
-
'-53': [-53, '-', '-54', '-52', '53'];
|
|
3468
|
-
'-52': [-52, '-', '-53', '-51', '52'];
|
|
3469
|
-
'-51': [-51, '-', '-52', '-50', '51'];
|
|
3470
|
-
'-50': [-50, '-', '-51', '-49', '50'];
|
|
3471
|
-
'-49': [-49, '-', '-50', '-48', '49'];
|
|
3472
|
-
'-48': [-48, '-', '-49', '-47', '48'];
|
|
3473
|
-
'-47': [-47, '-', '-48', '-46', '47'];
|
|
3474
|
-
'-46': [-46, '-', '-47', '-45', '46'];
|
|
3475
|
-
'-45': [-45, '-', '-46', '-44', '45'];
|
|
3476
|
-
'-44': [-44, '-', '-45', '-43', '44'];
|
|
3477
|
-
'-43': [-43, '-', '-44', '-42', '43'];
|
|
3478
|
-
'-42': [-42, '-', '-43', '-41', '42'];
|
|
3479
|
-
'-41': [-41, '-', '-42', '-40', '41'];
|
|
3480
|
-
'-40': [-40, '-', '-41', '-39', '40'];
|
|
3481
|
-
'-39': [-39, '-', '-40', '-38', '39'];
|
|
3482
|
-
'-38': [-38, '-', '-39', '-37', '38'];
|
|
3483
|
-
'-37': [-37, '-', '-38', '-36', '37'];
|
|
3484
|
-
'-36': [-36, '-', '-37', '-35', '36'];
|
|
3485
|
-
'-35': [-35, '-', '-36', '-34', '35'];
|
|
3486
|
-
'-34': [-34, '-', '-35', '-33', '34'];
|
|
3487
|
-
'-33': [-33, '-', '-34', '-32', '33'];
|
|
3488
|
-
'-32': [-32, '-', '-33', '-31', '32'];
|
|
3489
|
-
'-31': [-31, '-', '-32', '-30', '31'];
|
|
3490
|
-
'-30': [-30, '-', '-31', '-29', '30'];
|
|
3491
|
-
'-29': [-29, '-', '-30', '-28', '29'];
|
|
3492
|
-
'-28': [-28, '-', '-29', '-27', '28'];
|
|
3493
|
-
'-27': [-27, '-', '-28', '-26', '27'];
|
|
3494
|
-
'-26': [-26, '-', '-27', '-25', '26'];
|
|
3495
|
-
'-25': [-25, '-', '-26', '-24', '25'];
|
|
3496
|
-
'-24': [-24, '-', '-25', '-23', '24'];
|
|
3497
|
-
'-23': [-23, '-', '-24', '-22', '23'];
|
|
3498
|
-
'-22': [-22, '-', '-23', '-21', '22'];
|
|
3499
|
-
'-21': [-21, '-', '-22', '-20', '21'];
|
|
3500
|
-
'-20': [-20, '-', '-21', '-19', '20'];
|
|
3501
|
-
'-19': [-19, '-', '-20', '-18', '19'];
|
|
3502
|
-
'-18': [-18, '-', '-19', '-17', '18'];
|
|
3503
|
-
'-17': [-17, '-', '-18', '-16', '17'];
|
|
3504
|
-
'-16': [-16, '-', '-17', '-15', '16'];
|
|
3505
|
-
'-15': [-15, '-', '-16', '-14', '15'];
|
|
3506
|
-
'-14': [-14, '-', '-15', '-13', '14'];
|
|
3507
|
-
'-13': [-13, '-', '-14', '-12', '13'];
|
|
3508
|
-
'-12': [-12, '-', '-13', '-11', '12'];
|
|
3509
|
-
'-11': [-11, '-', '-12', '-10', '11'];
|
|
3510
|
-
'-10': [-10, '-', '-11', '-9', '10'];
|
|
3511
|
-
'-9': [-9, '-', '-10', '-8', '9'];
|
|
3512
|
-
'-8': [-8, '-', '-9', '-7', '8'];
|
|
3513
|
-
'-7': [-7, '-', '-8', '-6', '7'];
|
|
3514
|
-
'-6': [-6, '-', '-7', '-5', '6'];
|
|
3515
|
-
'-5': [-5, '-', '-6', '-4', '5'];
|
|
3516
|
-
'-4': [-4, '-', '-5', '-3', '4'];
|
|
3517
|
-
'-3': [-3, '-', '-4', '-2', '3'];
|
|
3518
|
-
'-2': [-2, '-', '-3', '-1', '2'];
|
|
3519
|
-
'-1': [-1, '-', '-2', '0', '1'];
|
|
3520
|
-
'0': [0, '0', '-1', '1', '0'];
|
|
3521
|
-
'1': [1, '+', '0', '2', '-1'];
|
|
3522
|
-
'2': [2, '+', '1', '3', '-2'];
|
|
3523
|
-
'3': [3, '+', '2', '4', '-3'];
|
|
3524
|
-
'4': [4, '+', '3', '5', '-4'];
|
|
3525
|
-
'5': [5, '+', '4', '6', '-5'];
|
|
3526
|
-
'6': [6, '+', '5', '7', '-6'];
|
|
3527
|
-
'7': [7, '+', '6', '8', '-7'];
|
|
3528
|
-
'8': [8, '+', '7', '9', '-8'];
|
|
3529
|
-
'9': [9, '+', '8', '10', '-9'];
|
|
3530
|
-
'10': [10, '+', '9', '11', '-10'];
|
|
3531
|
-
'11': [11, '+', '10', '12', '-11'];
|
|
3532
|
-
'12': [12, '+', '11', '13', '-12'];
|
|
3533
|
-
'13': [13, '+', '12', '14', '-13'];
|
|
3534
|
-
'14': [14, '+', '13', '15', '-14'];
|
|
3535
|
-
'15': [15, '+', '14', '16', '-15'];
|
|
3536
|
-
'16': [16, '+', '15', '17', '-16'];
|
|
3537
|
-
'17': [17, '+', '16', '18', '-17'];
|
|
3538
|
-
'18': [18, '+', '17', '19', '-18'];
|
|
3539
|
-
'19': [19, '+', '18', '20', '-19'];
|
|
3540
|
-
'20': [20, '+', '19', '21', '-20'];
|
|
3541
|
-
'21': [21, '+', '20', '22', '-21'];
|
|
3542
|
-
'22': [22, '+', '21', '23', '-22'];
|
|
3543
|
-
'23': [23, '+', '22', '24', '-23'];
|
|
3544
|
-
'24': [24, '+', '23', '25', '-24'];
|
|
3545
|
-
'25': [25, '+', '24', '26', '-25'];
|
|
3546
|
-
'26': [26, '+', '25', '27', '-26'];
|
|
3547
|
-
'27': [27, '+', '26', '28', '-27'];
|
|
3548
|
-
'28': [28, '+', '27', '29', '-28'];
|
|
3549
|
-
'29': [29, '+', '28', '30', '-29'];
|
|
3550
|
-
'30': [30, '+', '29', '31', '-30'];
|
|
3551
|
-
'31': [31, '+', '30', '32', '-31'];
|
|
3552
|
-
'32': [32, '+', '31', '33', '-32'];
|
|
3553
|
-
'33': [33, '+', '32', '34', '-33'];
|
|
3554
|
-
'34': [34, '+', '33', '35', '-34'];
|
|
3555
|
-
'35': [35, '+', '34', '36', '-35'];
|
|
3556
|
-
'36': [36, '+', '35', '37', '-36'];
|
|
3557
|
-
'37': [37, '+', '36', '38', '-37'];
|
|
3558
|
-
'38': [38, '+', '37', '39', '-38'];
|
|
3559
|
-
'39': [39, '+', '38', '40', '-39'];
|
|
3560
|
-
'40': [40, '+', '39', '41', '-40'];
|
|
3561
|
-
'41': [41, '+', '40', '42', '-41'];
|
|
3562
|
-
'42': [42, '+', '41', '43', '-42'];
|
|
3563
|
-
'43': [43, '+', '42', '44', '-43'];
|
|
3564
|
-
'44': [44, '+', '43', '45', '-44'];
|
|
3565
|
-
'45': [45, '+', '44', '46', '-45'];
|
|
3566
|
-
'46': [46, '+', '45', '47', '-46'];
|
|
3567
|
-
'47': [47, '+', '46', '48', '-47'];
|
|
3568
|
-
'48': [48, '+', '47', '49', '-48'];
|
|
3569
|
-
'49': [49, '+', '48', '50', '-49'];
|
|
3570
|
-
'50': [50, '+', '49', '51', '-50'];
|
|
3571
|
-
'51': [51, '+', '50', '52', '-51'];
|
|
3572
|
-
'52': [52, '+', '51', '53', '-52'];
|
|
3573
|
-
'53': [53, '+', '52', '54', '-53'];
|
|
3574
|
-
'54': [54, '+', '53', '55', '-54'];
|
|
3575
|
-
'55': [55, '+', '54', '56', '-55'];
|
|
3576
|
-
'56': [56, '+', '55', '57', '-56'];
|
|
3577
|
-
'57': [57, '+', '56', '58', '-57'];
|
|
3578
|
-
'58': [58, '+', '57', '59', '-58'];
|
|
3579
|
-
'59': [59, '+', '58', '60', '-59'];
|
|
3580
|
-
'60': [60, '+', '59', '61', '-60'];
|
|
3581
|
-
'61': [61, '+', '60', '62', '-61'];
|
|
3582
|
-
'62': [62, '+', '61', '63', '-62'];
|
|
3583
|
-
'63': [63, '+', '62', '64', '-63'];
|
|
3584
|
-
'64': [64, '+', '63', '65', '-64'];
|
|
3585
|
-
'65': [65, '+', '64', '66', '-65'];
|
|
3586
|
-
'66': [66, '+', '65', '67', '-66'];
|
|
3587
|
-
'67': [67, '+', '66', '68', '-67'];
|
|
3588
|
-
'68': [68, '+', '67', '69', '-68'];
|
|
3589
|
-
'69': [69, '+', '68', '70', '-69'];
|
|
3590
|
-
'70': [70, '+', '69', '71', '-70'];
|
|
3591
|
-
'71': [71, '+', '70', '72', '-71'];
|
|
3592
|
-
'72': [72, '+', '71', '73', '-72'];
|
|
3593
|
-
'73': [73, '+', '72', '74', '-73'];
|
|
3594
|
-
'74': [74, '+', '73', '75', '-74'];
|
|
3595
|
-
'75': [75, '+', '74', '76', '-75'];
|
|
3596
|
-
'76': [76, '+', '75', '77', '-76'];
|
|
3597
|
-
'77': [77, '+', '76', '78', '-77'];
|
|
3598
|
-
'78': [78, '+', '77', '79', '-78'];
|
|
3599
|
-
'79': [79, '+', '78', '80', '-79'];
|
|
3600
|
-
'80': [80, '+', '79', '81', '-80'];
|
|
3601
|
-
'81': [81, '+', '80', '82', '-81'];
|
|
3602
|
-
'82': [82, '+', '81', '83', '-82'];
|
|
3603
|
-
'83': [83, '+', '82', '84', '-83'];
|
|
3604
|
-
'84': [84, '+', '83', '85', '-84'];
|
|
3605
|
-
'85': [85, '+', '84', '86', '-85'];
|
|
3606
|
-
'86': [86, '+', '85', '87', '-86'];
|
|
3607
|
-
'87': [87, '+', '86', '88', '-87'];
|
|
3608
|
-
'88': [88, '+', '87', '89', '-88'];
|
|
3609
|
-
'89': [89, '+', '88', '90', '-89'];
|
|
3610
|
-
'90': [90, '+', '89', '91', '-90'];
|
|
3611
|
-
'91': [91, '+', '90', '92', '-91'];
|
|
3612
|
-
'92': [92, '+', '91', '93', '-92'];
|
|
3613
|
-
'93': [93, '+', '92', '94', '-93'];
|
|
3614
|
-
'94': [94, '+', '93', '95', '-94'];
|
|
3615
|
-
'95': [95, '+', '94', '96', '-95'];
|
|
3616
|
-
'96': [96, '+', '95', '97', '-96'];
|
|
3617
|
-
'97': [97, '+', '96', '98', '-97'];
|
|
3618
|
-
'98': [98, '+', '97', '99', '-98'];
|
|
3619
|
-
'99': [99, '+', '98', '100', '-99'];
|
|
3620
|
-
'100': [100, '+', '99', '__', '-100'];
|
|
3621
|
-
};
|
|
3622
|
-
//#endregion
|
|
3623
|
-
//#region ../../node_modules/.pnpm/ts-toolbelt@9.6.0/node_modules/ts-toolbelt/out/Iteration/Prev.d.ts
|
|
3624
|
-
/**
|
|
3625
|
-
* Move `I`'s position backwards
|
|
3626
|
-
* @param I to move
|
|
3627
|
-
* @returns [[Iteration]]
|
|
3628
|
-
* @example
|
|
3629
|
-
* ```ts
|
|
3630
|
-
* import {I} from 'ts-toolbelt'
|
|
3631
|
-
*
|
|
3632
|
-
* type i = I.IterationOf<'20'>
|
|
3633
|
-
*
|
|
3634
|
-
* type test0 = I.Pos<i> // 20
|
|
3635
|
-
* type test1 = I.Pos<I.Prev<i>> // 19
|
|
3636
|
-
* ```
|
|
3637
|
-
*/
|
|
3638
|
-
declare type Prev<I extends Iteration> = IterationMap[I[2]];
|
|
3639
|
-
//#endregion
|
|
3640
|
-
//#region ../../node_modules/.pnpm/ts-toolbelt@9.6.0/node_modules/ts-toolbelt/out/Iteration/IterationOf.d.ts
|
|
3641
|
-
/**
|
|
3642
|
-
* Transform a number into an [[Iteration]]
|
|
3643
|
-
* (to use [[Prev]], [[Next]], & [[Pos]])
|
|
3644
|
-
* @param N to transform
|
|
3645
|
-
* @returns [[Iteration]]
|
|
3646
|
-
* @example
|
|
3647
|
-
* ```ts
|
|
3648
|
-
* import {I} from 'ts-toolbelt'
|
|
3649
|
-
*
|
|
3650
|
-
* type i = I.IterationOf<0> // ["-1", "1", "0", 0, "0"]
|
|
3651
|
-
*
|
|
3652
|
-
* type next = I.Next<i> // ["0", "2", "1", 1, "+"]
|
|
3653
|
-
* type prev = I.Prev<i> // ["-2", "0", "-1", -1, "-"]
|
|
3654
|
-
*
|
|
3655
|
-
* type nnext = I.Pos<next> // +1
|
|
3656
|
-
* type nprev = I.Pos<prev> // -1
|
|
3657
|
-
* ```
|
|
3658
|
-
*/
|
|
3659
|
-
declare type IterationOf<N extends number> = `${N}` extends keyof IterationMap ? IterationMap[`${N}`] : IterationMap['__'];
|
|
3660
|
-
//#endregion
|
|
3661
|
-
//#region ../../node_modules/.pnpm/ts-toolbelt@9.6.0/node_modules/ts-toolbelt/out/Iteration/Pos.d.ts
|
|
3662
|
-
/**
|
|
3663
|
-
* Get the position of `I` (**number**)
|
|
3664
|
-
* @param I to query
|
|
3665
|
-
* @returns `number`
|
|
3666
|
-
* @example
|
|
3667
|
-
* ```ts
|
|
3668
|
-
* import {I} from 'ts-toolbelt'
|
|
3669
|
-
*
|
|
3670
|
-
* type i = I.IterationOf<'20'>
|
|
3671
|
-
*
|
|
3672
|
-
* type test0 = I.Pos<i> // 20
|
|
3673
|
-
* type test1 = I.Pos<I.Next<i>> // 21
|
|
3674
|
-
* ```
|
|
3675
|
-
*/
|
|
3676
|
-
declare type Pos<I extends Iteration> = I[0];
|
|
3677
|
-
//#endregion
|
|
3678
|
-
//#region ../../node_modules/.pnpm/ts-toolbelt@9.6.0/node_modules/ts-toolbelt/out/List/Tail.d.ts
|
|
3679
|
-
/**
|
|
3680
|
-
* Remove the first item out of a [[List]]
|
|
3681
|
-
* @param L
|
|
3682
|
-
* @returns [[List]]
|
|
3683
|
-
* @example
|
|
3684
|
-
* ```ts
|
|
3685
|
-
* ```
|
|
3686
|
-
*/
|
|
3687
|
-
declare type Tail$1<L extends List> = L extends readonly [] ? L : L extends readonly [any?, ...infer LTail] ? LTail : L;
|
|
3688
|
-
//#endregion
|
|
3689
|
-
//#region ../../node_modules/.pnpm/ts-toolbelt@9.6.0/node_modules/ts-toolbelt/out/Object/Overwrite.d.ts
|
|
3690
|
-
/**
|
|
3691
|
-
* Update the fields of `O` with the ones of `O1`
|
|
3692
|
-
* (only the existing fields will be updated)
|
|
3693
|
-
* @param O to update
|
|
3694
|
-
* @param O1 to update with
|
|
3695
|
-
* @returns [[Object]]
|
|
3696
|
-
* @example
|
|
3697
|
-
* ```ts
|
|
3698
|
-
* ```
|
|
3699
|
-
*/
|
|
3700
|
-
declare type Overwrite<O extends object, O1 extends object> = { [K in keyof O]: K extends keyof O1 ? O1[K] : O[K]; } & {};
|
|
3701
|
-
//#endregion
|
|
3702
|
-
//#region ../../node_modules/.pnpm/ts-toolbelt@9.6.0/node_modules/ts-toolbelt/out/List/_Internal.d.ts
|
|
3703
|
-
/**
|
|
3704
|
-
* Remove `?` & `readonly` from a [[List]]
|
|
3705
|
-
*/
|
|
3706
|
-
declare type Naked<L extends List> = Overwrite<Required<L>, L>;
|
|
3707
|
-
//#endregion
|
|
3708
|
-
//#region ../../node_modules/.pnpm/ts-toolbelt@9.6.0/node_modules/ts-toolbelt/out/List/Prepend.d.ts
|
|
3709
|
-
/**
|
|
3710
|
-
* Add an element `A` at the beginning of `L`
|
|
3711
|
-
* @param L to append to
|
|
3712
|
-
* @param A to be added to
|
|
3713
|
-
* @returns [[List]]
|
|
3714
|
-
* @example
|
|
3715
|
-
* ```ts
|
|
3716
|
-
* ```
|
|
3717
|
-
*/
|
|
3718
|
-
declare type Prepend<L extends List, A extends any> = [A, ...L];
|
|
3719
|
-
//#endregion
|
|
3720
|
-
//#region ../../node_modules/.pnpm/ts-toolbelt@9.6.0/node_modules/ts-toolbelt/out/Iteration/_Internal.d.ts
|
|
3721
|
-
/**
|
|
3722
|
-
* Describes how to perform iterations
|
|
3723
|
-
*/
|
|
3724
|
-
declare type Way = '->' | '<-';
|
|
3725
|
-
//#endregion
|
|
3726
|
-
//#region ../../node_modules/.pnpm/ts-toolbelt@9.6.0/node_modules/ts-toolbelt/out/List/Append.d.ts
|
|
3727
|
-
/**
|
|
3728
|
-
* Add an element `A` at the end of `L`.
|
|
3729
|
-
* @param L to append to
|
|
3730
|
-
* @param A to be added to
|
|
3731
|
-
* @returns [[List]]
|
|
3732
|
-
* @example
|
|
3733
|
-
* ```ts
|
|
3734
|
-
* import {L} from 'ts-toolbelt'
|
|
3735
|
-
*
|
|
3736
|
-
* type test0 = L.Append<[1, 2, 3], 4> // [1, 2, 3, 4]
|
|
3737
|
-
* type test1 = L.Append<[], 'a'> // ['a']
|
|
3738
|
-
* type test2 = L.Append<readonly ['a', 'b'], 'c'> // ['a', 'b', 'c']
|
|
3739
|
-
* type test3 = L.Append<[1, 2], [3, 4]> // [1, 2, [3, 4]]
|
|
3740
|
-
* ```
|
|
3741
|
-
*/
|
|
3742
|
-
declare type Append<L extends List, A extends any> = [...L, A];
|
|
3743
|
-
//#endregion
|
|
3744
|
-
//#region ../../node_modules/.pnpm/ts-toolbelt@9.6.0/node_modules/ts-toolbelt/out/List/Drop.d.ts
|
|
3745
|
-
/**
|
|
3746
|
-
* @hidden
|
|
3747
|
-
*/
|
|
3748
|
-
declare type DropForth<L extends List, N extends Iteration> = {
|
|
3749
|
-
0: DropForth<Tail$1<L>, Prev<N>>;
|
|
3750
|
-
1: L;
|
|
3751
|
-
}[Extends<0, Pos<N>>];
|
|
3752
|
-
/**
|
|
3753
|
-
* @hidden
|
|
3754
|
-
*/
|
|
3755
|
-
declare type DropBack<L extends List, N extends Iteration, I extends Iteration = Prev<N>, LN extends List = []> = {
|
|
3756
|
-
0: DropBack<L, N, Prev<I>, Prepend<LN, L[Pos<I>]>>;
|
|
3757
|
-
1: LN;
|
|
3758
|
-
}[Extends<-1, Pos<I>>];
|
|
3759
|
-
/**
|
|
3760
|
-
* @hidden
|
|
3761
|
-
*/
|
|
3762
|
-
declare type __Drop<L extends List, N extends Iteration, way extends Way> = {
|
|
3763
|
-
'->': DropForth<L, N>;
|
|
3764
|
-
'<-': DropBack<L, N>;
|
|
3765
|
-
}[way];
|
|
3766
|
-
/**
|
|
3767
|
-
* @hidden
|
|
3768
|
-
*/
|
|
3769
|
-
declare type _Drop<L extends List, N extends number, way extends Way = '->'> = __Drop<Naked<L>, IterationOf<N>, way> extends (infer X) ? Cast<X, List> : never;
|
|
3770
|
-
/**
|
|
3771
|
-
* Remove `N` entries out of `L`
|
|
3772
|
-
* @param L to remove from
|
|
3773
|
-
* @param N to remove out
|
|
3774
|
-
* @param way (?=`'->'`) from front: '->', from end: '<-'
|
|
3775
|
-
* @returns [[List]]
|
|
3776
|
-
* @example
|
|
3777
|
-
* ```ts
|
|
3778
|
-
* ```
|
|
3779
|
-
*/
|
|
3780
|
-
declare type Drop<L extends List, N extends number, way extends Way = '->'> = L extends unknown ? N extends unknown ? _Drop<L, N, way> : never : never;
|
|
3781
|
-
//#endregion
|
|
3782
|
-
//#region ../../node_modules/.pnpm/ts-toolbelt@9.6.0/node_modules/ts-toolbelt/out/List/Take.d.ts
|
|
3783
|
-
/**
|
|
3784
|
-
* starts in reverse from `N` till `N` = 0
|
|
3785
|
-
* @hidden
|
|
3786
|
-
*/
|
|
3787
|
-
declare type TakeForth<L extends List, N extends Iteration, I extends Iteration = Prev<N>, LN extends List = []> = {
|
|
3788
|
-
0: TakeForth<L, N, Prev<I>, Prepend<LN, L[Pos<I>]>>;
|
|
3789
|
-
1: LN;
|
|
3790
|
-
}[Extends<-1, Pos<I>>];
|
|
3791
|
-
/**
|
|
3792
|
-
* starts in reverse from the end till `N` = 0
|
|
3793
|
-
* @hidden
|
|
3794
|
-
*/
|
|
3795
|
-
declare type TakeBack<L extends List, N extends Iteration> = {
|
|
3796
|
-
0: TakeBack<Tail$1<L>, Prev<N>>;
|
|
3797
|
-
1: L;
|
|
3798
|
-
}[Extends<0, Pos<N>>];
|
|
3799
|
-
/**
|
|
3800
|
-
* @hidden
|
|
3801
|
-
*/
|
|
3802
|
-
declare type __Take<L extends List, N extends Iteration, way extends Way> = {
|
|
3803
|
-
'->': TakeForth<L, N>;
|
|
3804
|
-
'<-': TakeBack<L, N>;
|
|
3805
|
-
}[way];
|
|
3806
|
-
/**
|
|
3807
|
-
* @hidden
|
|
3808
|
-
*/
|
|
3809
|
-
declare type _Take<L extends List, N extends number, way extends Way = '->'> = __Take<L, IterationOf<N>, way> extends (infer X) ? Cast<X, List> : never;
|
|
3810
|
-
/**
|
|
3811
|
-
* Extract `N` entries out of `L`
|
|
3812
|
-
* @param L to extract from
|
|
3813
|
-
* @param N to extract out
|
|
3814
|
-
* @param way (?=`'->'`) to extract from end
|
|
3815
|
-
* @returns [[List]]
|
|
3816
|
-
* @example
|
|
3817
|
-
* ```ts
|
|
3818
|
-
* ```
|
|
3819
|
-
*/
|
|
3820
|
-
declare type Take<L extends List, N extends number, way extends Way = '->'> = L extends unknown ? N extends unknown ? _Take<L, N, way> : never : never;
|
|
3821
|
-
//#endregion
|
|
3822
1220
|
//#region src/object/index.type.d.ts
|
|
3823
1221
|
type Range<Start extends number, End extends number> = Exclude<keyof TupleOf<End>, keyof TupleOf<Start>>;
|
|
3824
1222
|
type AnyArray<A = any> = readonly A[];
|
|
3825
1223
|
type TupleToEntries<A extends readonly unknown[]> = If<IsAny<A>, unknown, { [Key in keyof A]: [Key, A[Key]]; }>;
|
|
3826
1224
|
type Groups<L extends AnyArray, LN extends AnyArray = [], D extends number[] = []> = D["length"] extends 40 ? LN : {
|
|
3827
|
-
0: Groups<Drop<L, 1>, Append<LN, [`${LN["length"]}`, Take<L, 1>]>, [...D, 0]>;
|
|
1225
|
+
0: Groups<List.Drop<L, 1>, List.Append<LN, [`${LN["length"]}`, List.Take<L, 1>]>, [...D, 0]>;
|
|
3828
1226
|
1: LN;
|
|
3829
|
-
}[Extends<L, AnyArray<never>>];
|
|
3830
|
-
type TupleToGroups<L extends AnyArray> = Groups<L> extends (infer X) ? Cast<X, AnyArray> : never;
|
|
1227
|
+
}[Any.Extends<L, AnyArray<never>>];
|
|
1228
|
+
type TupleToGroups<L extends AnyArray> = Groups<L> extends (infer X) ? Any.Cast<X, AnyArray> : never;
|
|
3831
1229
|
type Crush<T> = T extends readonly (infer U)[] ? Record<string, U extends object ? unknown : U> : Simplify<UnionToIntersection<keyof T extends (infer Prop) ? Prop extends keyof T ? T[Prop] extends (infer Value) ? ([Extract<Value, object>] extends [never] ? never : Record<string, unknown>) | ([Exclude<Value, object>] extends [never] ? never : [Extract<Value, object>] extends [never] ? { [P in Prop]: Value; } : Record<string, unknown>) : never : never : never>>;
|
|
3832
1230
|
type IntersectOf<U> = (U extends unknown ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
|
|
3833
1231
|
type ComputeRaw<A> = A extends AnyFunction ? A : { [K in keyof A]: A[K]; } & unknown;
|
|
@@ -4074,40 +1472,45 @@ declare class StringUtil {
|
|
|
4074
1472
|
* - 当传入数值字面量时,返回对应的字符串字面量类型
|
|
4075
1473
|
*
|
|
4076
1474
|
* @param candidate 待转换的值
|
|
4077
|
-
* @param
|
|
1475
|
+
* @param checkNullish 是否检查空值(`null` / `undefined` / 空白字符串),默认为 `true`
|
|
4078
1476
|
* @param trim 是否去除结果首尾空白,默认为 `true`
|
|
4079
1477
|
* @returns 转换后的字符串
|
|
4080
1478
|
* @example
|
|
4081
1479
|
* ```ts
|
|
4082
|
-
* // 重载 1: null / undefined +
|
|
1480
|
+
* // 重载 1: null / undefined + checkNullish = true (默认) → ""
|
|
4083
1481
|
* StringUtil.cast(null); // ""
|
|
4084
1482
|
* StringUtil.cast(undefined); // ""
|
|
4085
1483
|
* StringUtil.cast(""); // ""
|
|
4086
1484
|
* StringUtil.cast(" "); // ""
|
|
4087
1485
|
*
|
|
4088
|
-
* // 重载 2: null / undefined +
|
|
1486
|
+
* // 重载 2: null / undefined + checkNullish = false → "null" / "undefined"
|
|
4089
1487
|
* StringUtil.cast(null, false); // "null" (类型为 "null")
|
|
4090
1488
|
* StringUtil.cast(undefined, false); // "undefined" (类型为 "undefined")
|
|
4091
1489
|
*
|
|
4092
|
-
* // 重载 3: 原始类型 →
|
|
1490
|
+
* // 重载 3: 原始类型 → Trim<`${T}`> 字面量类型(trim 默认 true)
|
|
4093
1491
|
* StringUtil.cast(123); // "123" (类型为 "123")
|
|
4094
1492
|
* StringUtil.cast("hello"); // "hello" (类型为 "hello")
|
|
4095
1493
|
* StringUtil.cast(true); // "true" (类型为 "true")
|
|
4096
1494
|
* StringUtil.cast(42n); // "42" (类型为 "42")
|
|
1495
|
+
* // 默认去除结果首尾空白
|
|
1496
|
+
* StringUtil.cast(" hello "); // "hello" (类型为 Trim<" hello "> = "hello")
|
|
1497
|
+
* StringUtil.cast("\n abc \n"); // "abc" (类型为 "abc")
|
|
4097
1498
|
*
|
|
4098
|
-
* // 重载 4:
|
|
4099
|
-
* StringUtil.cast(
|
|
1499
|
+
* // 重载 4: 原始类型 + trim = false → 保留字面量类型
|
|
1500
|
+
* StringUtil.cast("\n abc \n", true, false); // "\n abc \n" (类型为 "\n abc \n")
|
|
1501
|
+
* StringUtil.cast(123, undefined, false); // "123" (类型为 "123")
|
|
4100
1502
|
*
|
|
4101
|
-
* //
|
|
4102
|
-
* StringUtil.cast("
|
|
4103
|
-
* StringUtil.cast(
|
|
4104
|
-
* StringUtil.cast(
|
|
1503
|
+
* // 重载 5: 其他类型 → string
|
|
1504
|
+
* StringUtil.cast(Symbol("foo")); // "Symbol(foo)" (类型为 string)
|
|
1505
|
+
* StringUtil.cast([1, 2, 3]); // "1,2,3" (类型为 string)
|
|
1506
|
+
* StringUtil.cast({}); // "[object Object]" (类型为 string)
|
|
4105
1507
|
* ```
|
|
4106
1508
|
*/
|
|
4107
|
-
static cast<T extends null | undefined>(candidate: T,
|
|
4108
|
-
static cast<T extends null | undefined>(candidate: T,
|
|
4109
|
-
static cast<T extends string | number | bigint | boolean>(candidate: T,
|
|
4110
|
-
static cast(candidate:
|
|
1509
|
+
static cast<T extends null | undefined>(candidate: T, checkNullish?: true, trim?: boolean): "";
|
|
1510
|
+
static cast<T extends null | undefined>(candidate: T, checkNullish: false, trim?: boolean): Trim<`${T}`>;
|
|
1511
|
+
static cast<T extends string | number | bigint | boolean>(candidate: T, checkNullish?: boolean, trim?: true): Trim<`${T}`>;
|
|
1512
|
+
static cast<T extends string | number | bigint | boolean>(candidate: T, checkNullish: boolean | undefined, trim: false): `${T}`;
|
|
1513
|
+
static cast(candidate: unknown, checkNullish?: boolean, trim?: boolean): string;
|
|
4111
1514
|
/**
|
|
4112
1515
|
* 从字符串中提取数字字符串
|
|
4113
1516
|
* - 移除非数字字符,保留符号和小数点
|
|
@@ -4158,19 +1561,26 @@ declare class StringUtil {
|
|
|
4158
1561
|
static toUpperCase<const T extends string>(input: T): Uppercase<T>;
|
|
4159
1562
|
static toUpperCase(input: unknown): "";
|
|
4160
1563
|
/**
|
|
4161
|
-
*
|
|
4162
|
-
* -
|
|
1564
|
+
* 调整大小写
|
|
1565
|
+
* - 每个单词(`\S+`)独立处理
|
|
1566
|
+
* - 包含非西欧字母字符(如 `.`、`,`、`'`、`-`)时,该词不处理
|
|
4163
1567
|
* - 纯字母且全大写时,不处理
|
|
4164
|
-
* -
|
|
4165
|
-
* -
|
|
1568
|
+
* - 纯字母且非全大写时:`caseType` 为 `"lower"` 则首字母小写,`"upper"` 则首字母大写,其余字符保留
|
|
1569
|
+
* - ⚠️ 缺省 `caseType` 时不产生任何转换(no-op),需显式传 `"lower"` / `"upper"`
|
|
4166
1570
|
*
|
|
4167
1571
|
* @param input 待处理字符串
|
|
4168
|
-
* @param caseType
|
|
1572
|
+
* @param caseType 大小写类型(缺省时无操作)
|
|
4169
1573
|
* @returns 处理后的字符串
|
|
4170
1574
|
* @example
|
|
4171
1575
|
* ```ts
|
|
4172
|
-
*
|
|
4173
|
-
* StringUtil.toInitialCase("
|
|
1576
|
+
* // 重载 1: lower
|
|
1577
|
+
* StringUtil.toInitialCase("Hello World", "lower"); // "hello world"
|
|
1578
|
+
*
|
|
1579
|
+
* // 重载 2: upper
|
|
1580
|
+
* StringUtil.toInitialCase("hello world", "upper"); // "Hello World"
|
|
1581
|
+
*
|
|
1582
|
+
* // 缺省 caseType → no-op
|
|
1583
|
+
* StringUtil.toInitialCase("Hello"); // "Hello"
|
|
4174
1584
|
* ```
|
|
4175
1585
|
*/
|
|
4176
1586
|
static toInitialCase(input: string, caseType?: "lower" | "upper" | undefined): string;
|
|
@@ -4218,6 +1628,7 @@ declare class StringUtil {
|
|
|
4218
1628
|
/**
|
|
4219
1629
|
* 字符串分割为数组
|
|
4220
1630
|
* - 按指定分隔符分割字符串,并转换类型
|
|
1631
|
+
* - ⚠️ `valueType` 为 `"number"` 时,无法解析的片段会转为 `NaN`,**不进行过滤**
|
|
4221
1632
|
*
|
|
4222
1633
|
* @param input 待处理字符串
|
|
4223
1634
|
* @param valueType 数组中每一项的类型,默认为 "number"
|
|
@@ -4230,6 +1641,9 @@ declare class StringUtil {
|
|
|
4230
1641
|
*
|
|
4231
1642
|
* // 重载 2: valueType = "string"
|
|
4232
1643
|
* StringUtil.toValues("a-b-c", "string", "-"); // ["a", "b", "c"]
|
|
1644
|
+
*
|
|
1645
|
+
* // 无法解析的片段 → NaN 不被过滤
|
|
1646
|
+
* StringUtil.toValues("1,abc,3"); // [1, NaN, 3]
|
|
4233
1647
|
* ```
|
|
4234
1648
|
*/
|
|
4235
1649
|
static toValues(input: string | null | undefined, valueType?: "number" | undefined, splitSymbol?: string | undefined): number[];
|
|
@@ -4361,25 +1775,31 @@ type TreeMapCallback<R extends AnyObject, T extends AnyObject> = (row: T, meta:
|
|
|
4361
1775
|
//#region src/tree/treeUtil.d.ts
|
|
4362
1776
|
/**
|
|
4363
1777
|
* 树结构工具类
|
|
1778
|
+
*
|
|
1779
|
+
* 引用策略约定:
|
|
1780
|
+
* - 转换类方法(`rowsToTree` / `treeToRows` / `filter` / `map`):不突变输入;输出的每个节点均为**新对象引用**(来源节点的浅拷贝,仅自有可枚举属性;非枚举属性、原型链、getter 及深层嵌套对象不保证)。
|
|
1781
|
+
* - 查询类方法(`find` / `forEach`):按查询语义直接使用**原对象引用**。
|
|
4364
1782
|
*/
|
|
4365
1783
|
declare class TreeUtil {
|
|
4366
1784
|
/**
|
|
4367
1785
|
* 行结构 转 树结构
|
|
4368
1786
|
* - 将平铺的数组转换为树形结构
|
|
1787
|
+
* - 返回的树结构与输入行无共享节点(新对象引用),输入行不会被突变
|
|
1788
|
+
* - 重复 id 的行只取首次出现;仅叶子/缺失父节点的 id 会作为根节点,且每个根节点只输出一次
|
|
4369
1789
|
*
|
|
4370
1790
|
* @param rows 行数据数组
|
|
4371
1791
|
* @param options 配置项
|
|
4372
|
-
* @returns
|
|
1792
|
+
* @returns 树结构数组(所有节点均包含 children 数组)
|
|
4373
1793
|
* @example
|
|
4374
1794
|
* ```ts
|
|
4375
1795
|
* const rows = [
|
|
4376
1796
|
* { id: 1, parentId: null },
|
|
4377
1797
|
* { id: 2, parentId: 1 },
|
|
4378
1798
|
* ];
|
|
4379
|
-
* TreeUtil.rowsToTree(rows); // [{ id: 1, parentId: null, children: [{ id: 2, parentId: 1 }] }]
|
|
1799
|
+
* TreeUtil.rowsToTree(rows); // [{ id: 1, parentId: null, children: [{ id: 2, parentId: 1, children: [] }] }]
|
|
4380
1800
|
* ```
|
|
4381
1801
|
*/
|
|
4382
|
-
static rowsToTree<T extends AnyObject = AnyObject, CK extends string = ChildrenKey, R = TreeLike<T, CK>, RK extends string = RowKey, PK extends string = ParentIdKey>(rows: T[], options?: RowsToTreeOptions<RK, PK, CK> | undefined): R[];
|
|
1802
|
+
static rowsToTree<T extends AnyObject = AnyObject, CK extends string = ChildrenKey, R extends AnyObject = TreeLike<T, CK>, RK extends string = RowKey, PK extends string = ParentIdKey>(rows: T[], options?: RowsToTreeOptions<RK, PK, CK> | undefined): R[];
|
|
4383
1803
|
/**
|
|
4384
1804
|
* 树结构 转 行结构
|
|
4385
1805
|
* - 将树形结构扁平化为数组
|
|
@@ -4393,7 +1813,7 @@ declare class TreeUtil {
|
|
|
4393
1813
|
* TreeUtil.treeToRows(tree); // [{ id: 1, children: undefined }, { id: 2, children: undefined }]
|
|
4394
1814
|
* ```
|
|
4395
1815
|
*/
|
|
4396
|
-
static treeToRows<T extends AnyObject, CK extends string = ChildrenKey, R extends AnyObject =
|
|
1816
|
+
static treeToRows<T extends AnyObject, CK extends string = ChildrenKey, R extends AnyObject = TreeLikeOptionalChildren<T, CK>>(tree: T | T[], options?: TreeToRowsOptions<T, CK>): R[];
|
|
4397
1817
|
/**
|
|
4398
1818
|
* 遍历树节点
|
|
4399
1819
|
*
|
|
@@ -4490,13 +1910,12 @@ declare class TypeUtil {
|
|
|
4490
1910
|
* @returns 标准化的类型标签字符串
|
|
4491
1911
|
*/
|
|
4492
1912
|
private static getPrototypeString;
|
|
4493
|
-
private static isConstructable;
|
|
4494
1913
|
/**
|
|
4495
1914
|
* 检查 value 是否为 string 类型
|
|
4496
|
-
* - 当 `
|
|
1915
|
+
* - 当 `checkNullish` 为 `true` 时,会先 trim 再判断是否为空
|
|
4497
1916
|
*
|
|
4498
1917
|
* @param value 待检查值
|
|
4499
|
-
* @param
|
|
1918
|
+
* @param checkNullish 是否检查空字符串(含空白字符串),默认为 `false`
|
|
4500
1919
|
* @returns 是否为字符串
|
|
4501
1920
|
* @example
|
|
4502
1921
|
* ```ts
|
|
@@ -4507,7 +1926,7 @@ declare class TypeUtil {
|
|
|
4507
1926
|
* TypeUtil.isString(" a ", true); // true
|
|
4508
1927
|
* ```
|
|
4509
1928
|
*/
|
|
4510
|
-
static isString(value: unknown,
|
|
1929
|
+
static isString(value: unknown, checkNullish?: boolean): value is string;
|
|
4511
1930
|
/**
|
|
4512
1931
|
* 检查 value 是否为 number 类型
|
|
4513
1932
|
* - 默认会调用 `TypeUtil.isNaN`(内部基于 `Number.isNaN`)过滤掉 `NaN`
|
|
@@ -4649,6 +2068,17 @@ declare class TypeUtil {
|
|
|
4649
2068
|
* ```
|
|
4650
2069
|
*/
|
|
4651
2070
|
static isNull(value: unknown): value is null;
|
|
2071
|
+
/**
|
|
2072
|
+
* 检查 value 是否为 null 或 undefined
|
|
2073
|
+
* @param value 待检查值
|
|
2074
|
+
* @returns 是否为 Nullish
|
|
2075
|
+
* @example
|
|
2076
|
+
* ```ts
|
|
2077
|
+
* TypeUtil.isNullish(null); // true
|
|
2078
|
+
* TypeUtil.isNullish(undefined); // true
|
|
2079
|
+
* ```
|
|
2080
|
+
*/
|
|
2081
|
+
static isNullish(value: unknown): value is null | undefined;
|
|
4652
2082
|
/**
|
|
4653
2083
|
* 检查 value 是否为 Function
|
|
4654
2084
|
* @param value 待检查值
|
|
@@ -4973,7 +2403,9 @@ declare class TypeUtil {
|
|
|
4973
2403
|
[Symbol.iterator]: () => Iterator<unknown>;
|
|
4974
2404
|
};
|
|
4975
2405
|
/**
|
|
4976
|
-
* 检查 value 是否为 Falsy 值 (false, 0, "", null, undefined, NaN)
|
|
2406
|
+
* 检查 value 是否为 Falsy 值 (false, 0, "", null, undefined, NaN, 0n)
|
|
2407
|
+
* - 处理非字符串形式的 falsy;字符串形式(`"null"`、`"0"` 等)请使用 `isFalsyLike`
|
|
2408
|
+
*
|
|
4977
2409
|
* @param value 待检查值
|
|
4978
2410
|
* @returns 是否为 Falsy
|
|
4979
2411
|
* @example
|
|
@@ -4981,7 +2413,7 @@ declare class TypeUtil {
|
|
|
4981
2413
|
* TypeUtil.isFalsy(0); // true
|
|
4982
2414
|
* ```
|
|
4983
2415
|
*/
|
|
4984
|
-
static isFalsy(value: unknown):
|
|
2416
|
+
static isFalsy(value: unknown): boolean;
|
|
4985
2417
|
/**
|
|
4986
2418
|
* 检查 value 是否为 FalsyLike 值
|
|
4987
2419
|
* - 包含字符串形式的 `"null"`、`"undefined"`、`"false"`、`"0"` 等
|
|
@@ -5067,19 +2499,31 @@ declare class ValidateUtil {
|
|
|
5067
2499
|
static isThunderLink(input: string): boolean;
|
|
5068
2500
|
static _uscc: RegExp;
|
|
5069
2501
|
/**
|
|
5070
|
-
*
|
|
2502
|
+
* 验证是否为统一社会信用代码(USCC / USCI / USCCS)
|
|
2503
|
+
* - 固定 18 位:1 位登记管理部门码 + 1 位机构类别码 + 6 位行政区划码 + 9 位主体标识码 + 1 位校验码
|
|
2504
|
+
* - 字符集:数字 0-9 + 大写英文字母(排除 I、O、Z、S、V,防视觉混淆)
|
|
2505
|
+
* - 第 1-2 位允许字母(如登记管理部门码 `A`,代表"其他"),第 3-8 位行政区划码为纯数字
|
|
2506
|
+
*
|
|
2507
|
+
* @param input 待校验字符串
|
|
2508
|
+
* @returns 是否为合法格式的统一社会信用代码
|
|
5071
2509
|
* @example
|
|
5072
2510
|
* ```ts
|
|
5073
2511
|
* ValidateUtil.isUSCC("91350100M000100Y43"); // true
|
|
2512
|
+
* ValidateUtil.isUSCC("A1350100M000100Y43"); // true (A 开头"其他"部门码)
|
|
5074
2513
|
* ```
|
|
5075
2514
|
*/
|
|
5076
2515
|
static isUSCC(input: string): boolean;
|
|
5077
|
-
static _usccs: RegExp;
|
|
5078
2516
|
/**
|
|
5079
|
-
*
|
|
2517
|
+
* 验证是否为统一社会信用代码(同 `isUSCC`)
|
|
2518
|
+
* - USCC / USCI / USCCS 均指统一社会信用代码,固定 18 位
|
|
2519
|
+
* - 15 位旧税务登记号在 2015 年"三证合一"前使用,现已作废,视为无效
|
|
2520
|
+
*
|
|
2521
|
+
* @param input 待校验字符串
|
|
2522
|
+
* @returns 是否为合法代码
|
|
5080
2523
|
* @example
|
|
5081
2524
|
* ```ts
|
|
5082
|
-
* ValidateUtil.isUSCCS("91350100M000100Y43"); // true
|
|
2525
|
+
* ValidateUtil.isUSCCS("91350100M000100Y43"); // true (18位)
|
|
2526
|
+
* ValidateUtil.isUSCCS("91350100M000100"); // false (15位旧号,已作废)
|
|
5083
2527
|
* ```
|
|
5084
2528
|
*/
|
|
5085
2529
|
static isUSCCS(input: string): boolean;
|
|
@@ -5149,6 +2593,7 @@ declare class ValidateUtil {
|
|
|
5149
2593
|
static _chineseId: RegExp;
|
|
5150
2594
|
/**
|
|
5151
2595
|
* 验证是否为中国身份证号
|
|
2596
|
+
* - ⚠️ 仅校验 18 位格式(含生日合法性),**不验证第 18 位校验位**,伪造码可通过校验
|
|
5152
2597
|
* @example
|
|
5153
2598
|
* ```ts
|
|
5154
2599
|
* ValidateUtil.isChineseID("11010519491231002X"); // true
|
|
@@ -5291,4 +2736,4 @@ declare class ValidateUtil {
|
|
|
5291
2736
|
static isSpaceStartOrEnd(input: string): boolean;
|
|
5292
2737
|
}
|
|
5293
2738
|
//#endregion
|
|
5294
|
-
export { ArrayUtil, type CurrencyCode, type CurrencyLocale, CurrencyUtil, DateTimeUtil, EnvUtil, type FormatterOptions, FunctionUtil, MimeUtil, NumberUtil, ObjectUtil, StringUtil, type THEME_MODE_TYPE, type THEME_TYPE, ThemeUtil, TreeUtil, TypeUtil, ValidateUtil };
|
|
2739
|
+
export { ArrayUtil, type CurrencyCode, type CurrencyLocale, CurrencyUtil, DateTimeUtil, EnvUtil, type FormatterOptions, FunctionUtil, type MatchFunction, MimeUtil, NumberUtil, ObjectUtil, StringUtil, type THEME_MODE_TYPE, type THEME_TYPE, ThemeUtil, TreeUtil, TypeUtil, ValidateUtil, type ZipOptions };
|