@pawover/kit 0.0.0-alpha.29 → 0.0.0-alpha.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/hooks-react.d.ts +1 -1
- package/dist/hooks-react.d.ts.map +1 -1
- package/dist/hooks-react.js.map +1 -1
- package/dist/index.d.ts +1240 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +51 -17
- package/dist/index.js.map +1 -1
- package/dist/patches-fetchEventSource.d.ts +722 -3
- package/dist/patches-fetchEventSource.d.ts.map +1 -1
- package/dist/patches-fetchEventSource.js.map +1 -1
- package/package.json +6 -7
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { BigNumber, MathExpression, MathJsInstance, Matrix } from "mathjs";
|
|
2
|
-
import { Class, NonEmptyObject, Replace, SetOptional, Simplify, UnionToIntersection, UnionToTuple, ValueOf } from "type-fest";
|
|
3
2
|
|
|
4
3
|
//#region src/utils/array/arrayCast.d.ts
|
|
5
4
|
|
|
@@ -126,7 +125,7 @@ declare function arraySplit<T>(initialList: readonly T[], size?: number): T[][];
|
|
|
126
125
|
* @param promise
|
|
127
126
|
* @param errorExt - 可以传递给err对象的其他信息
|
|
128
127
|
*/
|
|
129
|
-
declare function to<T, U$1 = Error>(promise: Readonly<Promise<T>>, errorExt?:
|
|
128
|
+
declare function to<T, U$1 = Error>(promise: Readonly<Promise<T>>, errorExt?: PlainObject): Promise<[U$1, undefined] | [null, T]>;
|
|
130
129
|
//#endregion
|
|
131
130
|
//#region src/utils/math/toMathBignumber.d.ts
|
|
132
131
|
/**
|
|
@@ -174,6 +173,1198 @@ interface CloningStrategy {
|
|
|
174
173
|
*/
|
|
175
174
|
declare function cloneDeep<T extends AnyObject>(root: T, customStrategy?: Partial<CloningStrategy>): T;
|
|
176
175
|
//#endregion
|
|
176
|
+
//#region node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/basic.d.ts
|
|
177
|
+
/**
|
|
178
|
+
Matches a [`class`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes).
|
|
179
|
+
|
|
180
|
+
@category Class
|
|
181
|
+
*/
|
|
182
|
+
type Class<T, Arguments extends unknown[] = any[]> = {
|
|
183
|
+
prototype: Pick<T, keyof T>;
|
|
184
|
+
new (...arguments_: Arguments): T;
|
|
185
|
+
};
|
|
186
|
+
//#endregion
|
|
187
|
+
//#region node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/union-to-intersection.d.ts
|
|
188
|
+
/**
|
|
189
|
+
Convert a union type to an intersection type using [distributive conditional types](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types).
|
|
190
|
+
|
|
191
|
+
Inspired by [this Stack Overflow answer](https://stackoverflow.com/a/50375286/2172153).
|
|
192
|
+
|
|
193
|
+
@example
|
|
194
|
+
```
|
|
195
|
+
import type {UnionToIntersection} from 'type-fest';
|
|
196
|
+
|
|
197
|
+
type Union = {the(): void} | {great(arg: string): void} | {escape: boolean};
|
|
198
|
+
|
|
199
|
+
type Intersection = UnionToIntersection<Union>;
|
|
200
|
+
//=> {the(): void; great(arg: string): void; escape: boolean};
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
@category Type
|
|
204
|
+
*/
|
|
205
|
+
type UnionToIntersection<Union> = (
|
|
206
|
+
// `extends unknown` is always going to be the case and is used to convert the
|
|
207
|
+
// `Union` into a [distributive conditional
|
|
208
|
+
// type](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types).
|
|
209
|
+
Union extends unknown
|
|
210
|
+
// The union type is used as the only argument to a function since the union
|
|
211
|
+
// of function arguments is an intersection.
|
|
212
|
+
? (distributedUnion: Union) => void
|
|
213
|
+
// This won't happen.
|
|
214
|
+
: never
|
|
215
|
+
// Infer the `Intersection` type since TypeScript represents the positional
|
|
216
|
+
// arguments of unions of functions as an intersection of the union.
|
|
217
|
+
) extends ((mergedIntersection: infer Intersection) => void)
|
|
218
|
+
// The `& Union` is to ensure result of `UnionToIntersection<A | B>` is always assignable to `A | B`
|
|
219
|
+
? Intersection & Union : never;
|
|
220
|
+
//#endregion
|
|
221
|
+
//#region node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/keys-of-union.d.ts
|
|
222
|
+
/**
|
|
223
|
+
Create a union of all keys from a given type, even those exclusive to specific union members.
|
|
224
|
+
|
|
225
|
+
Unlike the native `keyof` keyword, which returns keys present in **all** union members, this type returns keys from **any** member.
|
|
226
|
+
|
|
227
|
+
@link https://stackoverflow.com/a/49402091
|
|
228
|
+
|
|
229
|
+
@example
|
|
230
|
+
```
|
|
231
|
+
import type {KeysOfUnion} from 'type-fest';
|
|
232
|
+
|
|
233
|
+
type A = {
|
|
234
|
+
common: string;
|
|
235
|
+
a: number;
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
type B = {
|
|
239
|
+
common: string;
|
|
240
|
+
b: string;
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
type C = {
|
|
244
|
+
common: string;
|
|
245
|
+
c: boolean;
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
type Union = A | B | C;
|
|
249
|
+
|
|
250
|
+
type CommonKeys = keyof Union;
|
|
251
|
+
//=> 'common'
|
|
252
|
+
|
|
253
|
+
type AllKeys = KeysOfUnion<Union>;
|
|
254
|
+
//=> 'common' | 'a' | 'b' | 'c'
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
@category Object
|
|
258
|
+
*/
|
|
259
|
+
type KeysOfUnion<ObjectType> =
|
|
260
|
+
// Hack to fix https://github.com/sindresorhus/type-fest/issues/1008
|
|
261
|
+
keyof UnionToIntersection<ObjectType extends unknown ? Record<keyof ObjectType, never> : never>;
|
|
262
|
+
//#endregion
|
|
263
|
+
//#region node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/is-any.d.ts
|
|
264
|
+
/**
|
|
265
|
+
Returns a boolean for whether the given type is `any`.
|
|
266
|
+
|
|
267
|
+
@link https://stackoverflow.com/a/49928360/1490091
|
|
268
|
+
|
|
269
|
+
Useful in type utilities, such as disallowing `any`s to be passed to a function.
|
|
270
|
+
|
|
271
|
+
@example
|
|
272
|
+
```
|
|
273
|
+
import type {IsAny} from 'type-fest';
|
|
274
|
+
|
|
275
|
+
const typedObject = {a: 1, b: 2} as const;
|
|
276
|
+
const anyObject: any = {a: 1, b: 2};
|
|
277
|
+
|
|
278
|
+
function get<O extends (IsAny<O> extends true ? {} : Record<string, number>), K extends keyof O = keyof O>(object: O, key: K) {
|
|
279
|
+
return object[key];
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
const typedA = get(typedObject, 'a');
|
|
283
|
+
//=> 1
|
|
284
|
+
|
|
285
|
+
const anyA = get(anyObject, 'a');
|
|
286
|
+
//=> any
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
@category Type Guard
|
|
290
|
+
@category Utilities
|
|
291
|
+
*/
|
|
292
|
+
type IsAny<T> = 0 extends 1 & NoInfer<T> ? true : false;
|
|
293
|
+
//#endregion
|
|
294
|
+
//#region node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/is-optional-key-of.d.ts
|
|
295
|
+
/**
|
|
296
|
+
Returns a boolean for whether the given key is an optional key of type.
|
|
297
|
+
|
|
298
|
+
This is useful when writing utility types or schema validators that need to differentiate `optional` keys.
|
|
299
|
+
|
|
300
|
+
@example
|
|
301
|
+
```
|
|
302
|
+
import type {IsOptionalKeyOf} from 'type-fest';
|
|
303
|
+
|
|
304
|
+
type User = {
|
|
305
|
+
name: string;
|
|
306
|
+
surname: string;
|
|
307
|
+
|
|
308
|
+
luckyNumber?: number;
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
type Admin = {
|
|
312
|
+
name: string;
|
|
313
|
+
surname?: string;
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
type T1 = IsOptionalKeyOf<User, 'luckyNumber'>;
|
|
317
|
+
//=> true
|
|
318
|
+
|
|
319
|
+
type T2 = IsOptionalKeyOf<User, 'name'>;
|
|
320
|
+
//=> false
|
|
321
|
+
|
|
322
|
+
type T3 = IsOptionalKeyOf<User, 'name' | 'luckyNumber'>;
|
|
323
|
+
//=> boolean
|
|
324
|
+
|
|
325
|
+
type T4 = IsOptionalKeyOf<User | Admin, 'name'>;
|
|
326
|
+
//=> false
|
|
327
|
+
|
|
328
|
+
type T5 = IsOptionalKeyOf<User | Admin, 'surname'>;
|
|
329
|
+
//=> boolean
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
@category Type Guard
|
|
333
|
+
@category Utilities
|
|
334
|
+
*/
|
|
335
|
+
type IsOptionalKeyOf<Type extends object, Key$1 extends keyof Type> = IsAny<Type | Key$1> extends true ? never : Key$1 extends keyof Type ? Type extends Record<Key$1, Type[Key$1]> ? false : true : false;
|
|
336
|
+
//#endregion
|
|
337
|
+
//#region node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/optional-keys-of.d.ts
|
|
338
|
+
/**
|
|
339
|
+
Extract all optional keys from the given type.
|
|
340
|
+
|
|
341
|
+
This is useful when you want to create a new type that contains different type values for the optional keys only.
|
|
342
|
+
|
|
343
|
+
@example
|
|
344
|
+
```
|
|
345
|
+
import type {OptionalKeysOf, Except} from 'type-fest';
|
|
346
|
+
|
|
347
|
+
type User = {
|
|
348
|
+
name: string;
|
|
349
|
+
surname: string;
|
|
350
|
+
|
|
351
|
+
luckyNumber?: number;
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
const REMOVE_FIELD = Symbol('remove field symbol');
|
|
355
|
+
type UpdateOperation<Entity extends object> = Except<Partial<Entity>, OptionalKeysOf<Entity>> & {
|
|
356
|
+
[Key in OptionalKeysOf<Entity>]?: Entity[Key] | typeof REMOVE_FIELD;
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
const update1: UpdateOperation<User> = {
|
|
360
|
+
name: 'Alice',
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
const update2: UpdateOperation<User> = {
|
|
364
|
+
name: 'Bob',
|
|
365
|
+
luckyNumber: REMOVE_FIELD,
|
|
366
|
+
};
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
@category Utilities
|
|
370
|
+
*/
|
|
371
|
+
type OptionalKeysOf<Type extends object> = Type extends unknown // For distributing `Type`
|
|
372
|
+
? (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`
|
|
373
|
+
: never;
|
|
374
|
+
//#endregion
|
|
375
|
+
//#region node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/required-keys-of.d.ts
|
|
376
|
+
/**
|
|
377
|
+
Extract all required keys from the given type.
|
|
378
|
+
|
|
379
|
+
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...
|
|
380
|
+
|
|
381
|
+
@example
|
|
382
|
+
```
|
|
383
|
+
import type {RequiredKeysOf} from 'type-fest';
|
|
384
|
+
|
|
385
|
+
declare function createValidation<
|
|
386
|
+
Entity extends object,
|
|
387
|
+
Key extends RequiredKeysOf<Entity> = RequiredKeysOf<Entity>,
|
|
388
|
+
>(field: Key, validator: (value: Entity[Key]) => boolean): (entity: Entity) => boolean;
|
|
389
|
+
|
|
390
|
+
type User = {
|
|
391
|
+
name: string;
|
|
392
|
+
surname: string;
|
|
393
|
+
luckyNumber?: number;
|
|
394
|
+
};
|
|
395
|
+
|
|
396
|
+
const validator1 = createValidation<User>('name', value => value.length < 25);
|
|
397
|
+
const validator2 = createValidation<User>('surname', value => value.length < 25);
|
|
398
|
+
|
|
399
|
+
// @ts-expect-error
|
|
400
|
+
const validator3 = createValidation<User>('luckyNumber', value => value > 0);
|
|
401
|
+
// Error: Argument of type '"luckyNumber"' is not assignable to parameter of type '"name" | "surname"'.
|
|
402
|
+
```
|
|
403
|
+
|
|
404
|
+
@category Utilities
|
|
405
|
+
*/
|
|
406
|
+
type RequiredKeysOf<Type extends object> = Type extends unknown // For distributing `Type`
|
|
407
|
+
? Exclude<keyof Type, OptionalKeysOf<Type>> : never;
|
|
408
|
+
//#endregion
|
|
409
|
+
//#region node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/has-required-keys.d.ts
|
|
410
|
+
/**
|
|
411
|
+
Creates a type that represents `true` or `false` depending on whether the given type has any required fields.
|
|
412
|
+
|
|
413
|
+
This is useful when you want to create an API whose behavior depends on the presence or absence of required fields.
|
|
414
|
+
|
|
415
|
+
@example
|
|
416
|
+
```
|
|
417
|
+
import type {HasRequiredKeys} from 'type-fest';
|
|
418
|
+
|
|
419
|
+
type GeneratorOptions<Template extends object> = {
|
|
420
|
+
prop1: number;
|
|
421
|
+
prop2: string;
|
|
422
|
+
} & (HasRequiredKeys<Template> extends true
|
|
423
|
+
? {template: Template}
|
|
424
|
+
: {template?: Template});
|
|
425
|
+
|
|
426
|
+
type Template1 = {
|
|
427
|
+
optionalSubParam?: string;
|
|
428
|
+
};
|
|
429
|
+
|
|
430
|
+
type Template2 = {
|
|
431
|
+
requiredSubParam: string;
|
|
432
|
+
};
|
|
433
|
+
|
|
434
|
+
type Options1 = GeneratorOptions<Template1>;
|
|
435
|
+
type Options2 = GeneratorOptions<Template2>;
|
|
436
|
+
|
|
437
|
+
const optA: Options1 = {
|
|
438
|
+
prop1: 0,
|
|
439
|
+
prop2: 'hi',
|
|
440
|
+
};
|
|
441
|
+
const optB: Options1 = {
|
|
442
|
+
prop1: 0,
|
|
443
|
+
prop2: 'hi',
|
|
444
|
+
template: {},
|
|
445
|
+
};
|
|
446
|
+
const optC: Options1 = {
|
|
447
|
+
prop1: 0,
|
|
448
|
+
prop2: 'hi',
|
|
449
|
+
template: {
|
|
450
|
+
optionalSubParam: 'optional value',
|
|
451
|
+
},
|
|
452
|
+
};
|
|
453
|
+
|
|
454
|
+
const optD: Options2 = {
|
|
455
|
+
prop1: 0,
|
|
456
|
+
prop2: 'hi',
|
|
457
|
+
template: {
|
|
458
|
+
requiredSubParam: 'required value',
|
|
459
|
+
},
|
|
460
|
+
};
|
|
461
|
+
|
|
462
|
+
```
|
|
463
|
+
|
|
464
|
+
@category Utilities
|
|
465
|
+
*/
|
|
466
|
+
type HasRequiredKeys<BaseType extends object> = RequiredKeysOf<BaseType> extends never ? false : true;
|
|
467
|
+
//#endregion
|
|
468
|
+
//#region node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/is-never.d.ts
|
|
469
|
+
/**
|
|
470
|
+
Returns a boolean for whether the given type is `never`.
|
|
471
|
+
|
|
472
|
+
@link https://github.com/microsoft/TypeScript/issues/31751#issuecomment-498526919
|
|
473
|
+
@link https://stackoverflow.com/a/53984913/10292952
|
|
474
|
+
@link https://www.zhenghao.io/posts/ts-never
|
|
475
|
+
|
|
476
|
+
Useful in type utilities, such as checking if something does not occur.
|
|
477
|
+
|
|
478
|
+
@example
|
|
479
|
+
```
|
|
480
|
+
import type {IsNever, And} from 'type-fest';
|
|
481
|
+
|
|
482
|
+
type A = IsNever<never>;
|
|
483
|
+
//=> true
|
|
484
|
+
|
|
485
|
+
type B = IsNever<any>;
|
|
486
|
+
//=> false
|
|
487
|
+
|
|
488
|
+
type C = IsNever<unknown>;
|
|
489
|
+
//=> false
|
|
490
|
+
|
|
491
|
+
type D = IsNever<never[]>;
|
|
492
|
+
//=> false
|
|
493
|
+
|
|
494
|
+
type E = IsNever<object>;
|
|
495
|
+
//=> false
|
|
496
|
+
|
|
497
|
+
type F = IsNever<string>;
|
|
498
|
+
//=> false
|
|
499
|
+
```
|
|
500
|
+
|
|
501
|
+
@example
|
|
502
|
+
```
|
|
503
|
+
import type {IsNever} from 'type-fest';
|
|
504
|
+
|
|
505
|
+
type IsTrue<T> = T extends true ? true : false;
|
|
506
|
+
|
|
507
|
+
// When a distributive conditional is instantiated with `never`, the entire conditional results in `never`.
|
|
508
|
+
type A = IsTrue<never>;
|
|
509
|
+
// ^? type A = never
|
|
510
|
+
|
|
511
|
+
// If you don't want that behaviour, you can explicitly add an `IsNever` check before the distributive conditional.
|
|
512
|
+
type IsTrueFixed<T> =
|
|
513
|
+
IsNever<T> extends true ? false : T extends true ? true : false;
|
|
514
|
+
|
|
515
|
+
type B = IsTrueFixed<never>;
|
|
516
|
+
// ^? type B = false
|
|
517
|
+
```
|
|
518
|
+
|
|
519
|
+
@category Type Guard
|
|
520
|
+
@category Utilities
|
|
521
|
+
*/
|
|
522
|
+
type IsNever<T> = [T] extends [never] ? true : false;
|
|
523
|
+
//#endregion
|
|
524
|
+
//#region node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/if.d.ts
|
|
525
|
+
/**
|
|
526
|
+
An if-else-like type that resolves depending on whether the given `boolean` type is `true` or `false`.
|
|
527
|
+
|
|
528
|
+
Use-cases:
|
|
529
|
+
- 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'>`.
|
|
530
|
+
|
|
531
|
+
Note:
|
|
532
|
+
- 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'`.
|
|
533
|
+
- Returns the else branch if the given type is `never`. For example, `If<never, 'Y', 'N'>` will return `'N'`.
|
|
534
|
+
|
|
535
|
+
@example
|
|
536
|
+
```
|
|
537
|
+
import type {If} from 'type-fest';
|
|
538
|
+
|
|
539
|
+
type A = If<true, 'yes', 'no'>;
|
|
540
|
+
//=> 'yes'
|
|
541
|
+
|
|
542
|
+
type B = If<false, 'yes', 'no'>;
|
|
543
|
+
//=> 'no'
|
|
544
|
+
|
|
545
|
+
type C = If<boolean, 'yes', 'no'>;
|
|
546
|
+
//=> 'yes' | 'no'
|
|
547
|
+
|
|
548
|
+
type D = If<any, 'yes', 'no'>;
|
|
549
|
+
//=> 'yes' | 'no'
|
|
550
|
+
|
|
551
|
+
type E = If<never, 'yes', 'no'>;
|
|
552
|
+
//=> 'no'
|
|
553
|
+
```
|
|
554
|
+
|
|
555
|
+
@example
|
|
556
|
+
```
|
|
557
|
+
import type {If, IsAny, IsNever} from 'type-fest';
|
|
558
|
+
|
|
559
|
+
type A = If<IsAny<unknown>, 'is any', 'not any'>;
|
|
560
|
+
//=> 'not any'
|
|
561
|
+
|
|
562
|
+
type B = If<IsNever<never>, 'is never', 'not never'>;
|
|
563
|
+
//=> 'is never'
|
|
564
|
+
```
|
|
565
|
+
|
|
566
|
+
@example
|
|
567
|
+
```
|
|
568
|
+
import type {If, IsEqual} from 'type-fest';
|
|
569
|
+
|
|
570
|
+
type IfEqual<T, U, IfBranch, ElseBranch> = If<IsEqual<T, U>, IfBranch, ElseBranch>;
|
|
571
|
+
|
|
572
|
+
type A = IfEqual<string, string, 'equal', 'not equal'>;
|
|
573
|
+
//=> 'equal'
|
|
574
|
+
|
|
575
|
+
type B = IfEqual<string, number, 'equal', 'not equal'>;
|
|
576
|
+
//=> 'not equal'
|
|
577
|
+
```
|
|
578
|
+
|
|
579
|
+
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:
|
|
580
|
+
|
|
581
|
+
@example
|
|
582
|
+
```
|
|
583
|
+
import type {If, IsEqual, StringRepeat} from 'type-fest';
|
|
584
|
+
|
|
585
|
+
type HundredZeroes = StringRepeat<'0', 100>;
|
|
586
|
+
|
|
587
|
+
// The following implementation is not tail recursive
|
|
588
|
+
type Includes<S extends string, Char extends string> =
|
|
589
|
+
S extends `${infer First}${infer Rest}`
|
|
590
|
+
? If<IsEqual<First, Char>,
|
|
591
|
+
'found',
|
|
592
|
+
Includes<Rest, Char>>
|
|
593
|
+
: 'not found';
|
|
594
|
+
|
|
595
|
+
// Hence, instantiations with long strings will fail
|
|
596
|
+
// @ts-expect-error
|
|
597
|
+
type Fails = Includes<HundredZeroes, '1'>;
|
|
598
|
+
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
599
|
+
// Error: Type instantiation is excessively deep and possibly infinite.
|
|
600
|
+
|
|
601
|
+
// However, if we use a simple conditional instead of `If`, the implementation becomes tail-recursive
|
|
602
|
+
type IncludesWithoutIf<S extends string, Char extends string> =
|
|
603
|
+
S extends `${infer First}${infer Rest}`
|
|
604
|
+
? IsEqual<First, Char> extends true
|
|
605
|
+
? 'found'
|
|
606
|
+
: IncludesWithoutIf<Rest, Char>
|
|
607
|
+
: 'not found';
|
|
608
|
+
|
|
609
|
+
// Now, instantiations with long strings will work
|
|
610
|
+
type Works = IncludesWithoutIf<HundredZeroes, '1'>;
|
|
611
|
+
//=> 'not found'
|
|
612
|
+
```
|
|
613
|
+
|
|
614
|
+
@category Type Guard
|
|
615
|
+
@category Utilities
|
|
616
|
+
*/
|
|
617
|
+
type If<Type extends boolean, IfBranch, ElseBranch> = IsNever<Type> extends true ? ElseBranch : Type extends true ? IfBranch : ElseBranch;
|
|
618
|
+
//#endregion
|
|
619
|
+
//#region node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/internal/type.d.ts
|
|
620
|
+
/**
|
|
621
|
+
An if-else-like type that resolves depending on whether the given type is `any` or `never`.
|
|
622
|
+
|
|
623
|
+
@example
|
|
624
|
+
```
|
|
625
|
+
// When `T` is a NOT `any` or `never` (like `string`) => Returns `IfNotAnyOrNever` branch
|
|
626
|
+
type A = IfNotAnyOrNever<string, 'VALID', 'IS_ANY', 'IS_NEVER'>;
|
|
627
|
+
//=> 'VALID'
|
|
628
|
+
|
|
629
|
+
// When `T` is `any` => Returns `IfAny` branch
|
|
630
|
+
type B = IfNotAnyOrNever<any, 'VALID', 'IS_ANY', 'IS_NEVER'>;
|
|
631
|
+
//=> 'IS_ANY'
|
|
632
|
+
|
|
633
|
+
// When `T` is `never` => Returns `IfNever` branch
|
|
634
|
+
type C = IfNotAnyOrNever<never, 'VALID', 'IS_ANY', 'IS_NEVER'>;
|
|
635
|
+
//=> 'IS_NEVER'
|
|
636
|
+
```
|
|
637
|
+
|
|
638
|
+
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:
|
|
639
|
+
|
|
640
|
+
@example
|
|
641
|
+
```ts
|
|
642
|
+
import type {StringRepeat} from 'type-fest';
|
|
643
|
+
|
|
644
|
+
type NineHundredNinetyNineSpaces = StringRepeat<' ', 999>;
|
|
645
|
+
|
|
646
|
+
// The following implementation is not tail recursive
|
|
647
|
+
type TrimLeft<S extends string> = IfNotAnyOrNever<S, S extends ` ${infer R}` ? TrimLeft<R> : S>;
|
|
648
|
+
|
|
649
|
+
// Hence, instantiations with long strings will fail
|
|
650
|
+
// @ts-expect-error
|
|
651
|
+
type T1 = TrimLeft<NineHundredNinetyNineSpaces>;
|
|
652
|
+
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
653
|
+
// Error: Type instantiation is excessively deep and possibly infinite.
|
|
654
|
+
|
|
655
|
+
// To fix this, move the recursion into a helper type
|
|
656
|
+
type TrimLeftOptimised<S extends string> = IfNotAnyOrNever<S, _TrimLeftOptimised<S>>;
|
|
657
|
+
|
|
658
|
+
type _TrimLeftOptimised<S extends string> = S extends ` ${infer R}` ? _TrimLeftOptimised<R> : S;
|
|
659
|
+
|
|
660
|
+
type T2 = TrimLeftOptimised<NineHundredNinetyNineSpaces>;
|
|
661
|
+
//=> ''
|
|
662
|
+
```
|
|
663
|
+
*/
|
|
664
|
+
type IfNotAnyOrNever<T, IfNotAnyOrNever$1, IfAny = any, IfNever = never> = If<IsAny<T>, IfAny, If<IsNever<T>, IfNever, IfNotAnyOrNever$1>>;
|
|
665
|
+
//#endregion
|
|
666
|
+
//#region node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/simplify.d.ts
|
|
667
|
+
/**
|
|
668
|
+
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.
|
|
669
|
+
|
|
670
|
+
@example
|
|
671
|
+
```
|
|
672
|
+
import type {Simplify} from 'type-fest';
|
|
673
|
+
|
|
674
|
+
type PositionProps = {
|
|
675
|
+
top: number;
|
|
676
|
+
left: number;
|
|
677
|
+
};
|
|
678
|
+
|
|
679
|
+
type SizeProps = {
|
|
680
|
+
width: number;
|
|
681
|
+
height: number;
|
|
682
|
+
};
|
|
683
|
+
|
|
684
|
+
// In your editor, hovering over `Props` will show a flattened object with all the properties.
|
|
685
|
+
type Props = Simplify<PositionProps & SizeProps>;
|
|
686
|
+
```
|
|
687
|
+
|
|
688
|
+
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.
|
|
689
|
+
|
|
690
|
+
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`.
|
|
691
|
+
|
|
692
|
+
@example
|
|
693
|
+
```
|
|
694
|
+
import type {Simplify} from 'type-fest';
|
|
695
|
+
|
|
696
|
+
interface SomeInterface {
|
|
697
|
+
foo: number;
|
|
698
|
+
bar?: string;
|
|
699
|
+
baz: number | undefined;
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
type SomeType = {
|
|
703
|
+
foo: number;
|
|
704
|
+
bar?: string;
|
|
705
|
+
baz: number | undefined;
|
|
706
|
+
};
|
|
707
|
+
|
|
708
|
+
const literal = {foo: 123, bar: 'hello', baz: 456};
|
|
709
|
+
const someType: SomeType = literal;
|
|
710
|
+
const someInterface: SomeInterface = literal;
|
|
711
|
+
|
|
712
|
+
declare function fn(object: Record<string, unknown>): void;
|
|
713
|
+
|
|
714
|
+
fn(literal); // Good: literal object type is sealed
|
|
715
|
+
fn(someType); // Good: type is sealed
|
|
716
|
+
// @ts-expect-error
|
|
717
|
+
fn(someInterface); // Error: Index signature for type 'string' is missing in type 'someInterface'. Because `interface` can be re-opened
|
|
718
|
+
fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface` into a `type`
|
|
719
|
+
```
|
|
720
|
+
|
|
721
|
+
@link https://github.com/microsoft/TypeScript/issues/15300
|
|
722
|
+
@see {@link SimplifyDeep}
|
|
723
|
+
@category Object
|
|
724
|
+
*/
|
|
725
|
+
type Simplify<T> = { [KeyType in keyof T]: T[KeyType] } & {};
|
|
726
|
+
//#endregion
|
|
727
|
+
//#region node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/is-equal.d.ts
|
|
728
|
+
/**
|
|
729
|
+
Returns a boolean for whether the two given types are equal.
|
|
730
|
+
|
|
731
|
+
@link https://github.com/microsoft/TypeScript/issues/27024#issuecomment-421529650
|
|
732
|
+
@link https://stackoverflow.com/questions/68961864/how-does-the-equals-work-in-typescript/68963796#68963796
|
|
733
|
+
|
|
734
|
+
Use-cases:
|
|
735
|
+
- If you want to make a conditional branch based on the result of a comparison of two types.
|
|
736
|
+
|
|
737
|
+
@example
|
|
738
|
+
```
|
|
739
|
+
import type {IsEqual} from 'type-fest';
|
|
740
|
+
|
|
741
|
+
// This type returns a boolean for whether the given array includes the given item.
|
|
742
|
+
// `IsEqual` is used to compare the given array at position 0 and the given item and then return true if they are equal.
|
|
743
|
+
type Includes<Value extends readonly any[], Item> =
|
|
744
|
+
Value extends readonly [Value[0], ...infer rest]
|
|
745
|
+
? IsEqual<Value[0], Item> extends true
|
|
746
|
+
? true
|
|
747
|
+
: Includes<rest, Item>
|
|
748
|
+
: false;
|
|
749
|
+
```
|
|
750
|
+
|
|
751
|
+
@category Type Guard
|
|
752
|
+
@category Utilities
|
|
753
|
+
*/
|
|
754
|
+
type IsEqual<A$1, B$1> = [A$1] extends [B$1] ? [B$1] extends [A$1] ? _IsEqual<A$1, B$1> : false : false;
|
|
755
|
+
// This version fails the `equalWrappedTupleIntersectionToBeNeverAndNeverExpanded` test in `test-d/is-equal.ts`.
|
|
756
|
+
type _IsEqual<A$1, B$1> = (<G>() => G extends A$1 & G | G ? 1 : 2) extends (<G>() => G extends B$1 & G | G ? 1 : 2) ? true : false;
|
|
757
|
+
//#endregion
|
|
758
|
+
//#region node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/omit-index-signature.d.ts
|
|
759
|
+
/**
|
|
760
|
+
Omit any index signatures from the given object type, leaving only explicitly defined properties.
|
|
761
|
+
|
|
762
|
+
This is the counterpart of `PickIndexSignature`.
|
|
763
|
+
|
|
764
|
+
Use-cases:
|
|
765
|
+
- Remove overly permissive signatures from third-party types.
|
|
766
|
+
|
|
767
|
+
This type was taken from this [StackOverflow answer](https://stackoverflow.com/a/68261113/420747).
|
|
768
|
+
|
|
769
|
+
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>`.
|
|
770
|
+
|
|
771
|
+
(The actual value type, `unknown`, is irrelevant and could be any type. Only the key type matters.)
|
|
772
|
+
|
|
773
|
+
```
|
|
774
|
+
const indexed: Record<string, unknown> = {}; // Allowed
|
|
775
|
+
|
|
776
|
+
// @ts-expect-error
|
|
777
|
+
const keyed: Record<'foo', unknown> = {}; // Error
|
|
778
|
+
// => TS2739: Type '{}' is missing the following properties from type 'Record<"foo" | "bar", unknown>': foo, bar
|
|
779
|
+
```
|
|
780
|
+
|
|
781
|
+
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:
|
|
782
|
+
|
|
783
|
+
```
|
|
784
|
+
type Indexed = {} extends Record<string, unknown>
|
|
785
|
+
? '✅ `{}` is assignable to `Record<string, unknown>`'
|
|
786
|
+
: '❌ `{}` is NOT assignable to `Record<string, unknown>`';
|
|
787
|
+
// => '✅ `{}` is assignable to `Record<string, unknown>`'
|
|
788
|
+
|
|
789
|
+
type Keyed = {} extends Record<'foo' | 'bar', unknown>
|
|
790
|
+
? '✅ `{}` is assignable to `Record<\'foo\' | \'bar\', unknown>`'
|
|
791
|
+
: '❌ `{}` is NOT assignable to `Record<\'foo\' | \'bar\', unknown>`';
|
|
792
|
+
// => "❌ `{}` is NOT assignable to `Record<'foo' | 'bar', unknown>`"
|
|
793
|
+
```
|
|
794
|
+
|
|
795
|
+
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`...
|
|
796
|
+
|
|
797
|
+
```
|
|
798
|
+
type OmitIndexSignature<ObjectType> = {
|
|
799
|
+
[KeyType in keyof ObjectType // Map each key of `ObjectType`...
|
|
800
|
+
]: ObjectType[KeyType]; // ...to its original value, i.e. `OmitIndexSignature<Foo> == Foo`.
|
|
801
|
+
};
|
|
802
|
+
```
|
|
803
|
+
|
|
804
|
+
...whether an empty object (`{}`) would be assignable to an object with that `KeyType` (`Record<KeyType, unknown>`)...
|
|
805
|
+
|
|
806
|
+
```
|
|
807
|
+
type OmitIndexSignature<ObjectType> = {
|
|
808
|
+
[KeyType in keyof ObjectType
|
|
809
|
+
// Is `{}` assignable to `Record<KeyType, unknown>`?
|
|
810
|
+
as {} extends Record<KeyType, unknown>
|
|
811
|
+
? never // ✅ `{}` is assignable to `Record<KeyType, unknown>`
|
|
812
|
+
: KeyType // ❌ `{}` is NOT assignable to `Record<KeyType, unknown>`
|
|
813
|
+
]: ObjectType[KeyType];
|
|
814
|
+
};
|
|
815
|
+
```
|
|
816
|
+
|
|
817
|
+
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.
|
|
818
|
+
|
|
819
|
+
@example
|
|
820
|
+
```
|
|
821
|
+
import type {OmitIndexSignature} from 'type-fest';
|
|
822
|
+
|
|
823
|
+
type Example = {
|
|
824
|
+
// These index signatures will be removed.
|
|
825
|
+
[x: string]: any;
|
|
826
|
+
[x: number]: any;
|
|
827
|
+
[x: symbol]: any;
|
|
828
|
+
[x: `head-${string}`]: string;
|
|
829
|
+
[x: `${string}-tail`]: string;
|
|
830
|
+
[x: `head-${string}-tail`]: string;
|
|
831
|
+
[x: `${bigint}`]: string;
|
|
832
|
+
[x: `embedded-${number}`]: string;
|
|
833
|
+
|
|
834
|
+
// These explicitly defined keys will remain.
|
|
835
|
+
foo: 'bar';
|
|
836
|
+
qux?: 'baz';
|
|
837
|
+
};
|
|
838
|
+
|
|
839
|
+
type ExampleWithoutIndexSignatures = OmitIndexSignature<Example>;
|
|
840
|
+
// => { foo: 'bar'; qux?: 'baz' | undefined; }
|
|
841
|
+
```
|
|
842
|
+
|
|
843
|
+
@see {@link PickIndexSignature}
|
|
844
|
+
@category Object
|
|
845
|
+
*/
|
|
846
|
+
type OmitIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? never : KeyType]: ObjectType[KeyType] };
|
|
847
|
+
//#endregion
|
|
848
|
+
//#region node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/pick-index-signature.d.ts
|
|
849
|
+
/**
|
|
850
|
+
Pick only index signatures from the given object type, leaving out all explicitly defined properties.
|
|
851
|
+
|
|
852
|
+
This is the counterpart of `OmitIndexSignature`.
|
|
853
|
+
|
|
854
|
+
@example
|
|
855
|
+
```
|
|
856
|
+
import type {PickIndexSignature} from 'type-fest';
|
|
857
|
+
|
|
858
|
+
declare const symbolKey: unique symbol;
|
|
859
|
+
|
|
860
|
+
type Example = {
|
|
861
|
+
// These index signatures will remain.
|
|
862
|
+
[x: string]: unknown;
|
|
863
|
+
[x: number]: unknown;
|
|
864
|
+
[x: symbol]: unknown;
|
|
865
|
+
[x: `head-${string}`]: string;
|
|
866
|
+
[x: `${string}-tail`]: string;
|
|
867
|
+
[x: `head-${string}-tail`]: string;
|
|
868
|
+
[x: `${bigint}`]: string;
|
|
869
|
+
[x: `embedded-${number}`]: string;
|
|
870
|
+
|
|
871
|
+
// These explicitly defined keys will be removed.
|
|
872
|
+
['kebab-case-key']: string;
|
|
873
|
+
[symbolKey]: string;
|
|
874
|
+
foo: 'bar';
|
|
875
|
+
qux?: 'baz';
|
|
876
|
+
};
|
|
877
|
+
|
|
878
|
+
type ExampleIndexSignature = PickIndexSignature<Example>;
|
|
879
|
+
// {
|
|
880
|
+
// [x: string]: unknown;
|
|
881
|
+
// [x: number]: unknown;
|
|
882
|
+
// [x: symbol]: unknown;
|
|
883
|
+
// [x: `head-${string}`]: string;
|
|
884
|
+
// [x: `${string}-tail`]: string;
|
|
885
|
+
// [x: `head-${string}-tail`]: string;
|
|
886
|
+
// [x: `${bigint}`]: string;
|
|
887
|
+
// [x: `embedded-${number}`]: string;
|
|
888
|
+
// }
|
|
889
|
+
```
|
|
890
|
+
|
|
891
|
+
@see {@link OmitIndexSignature}
|
|
892
|
+
@category Object
|
|
893
|
+
*/
|
|
894
|
+
type PickIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? KeyType : never]: ObjectType[KeyType] };
|
|
895
|
+
//#endregion
|
|
896
|
+
//#region node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/merge.d.ts
|
|
897
|
+
// Merges two objects without worrying about index signatures.
|
|
898
|
+
type SimpleMerge<Destination, Source> = { [Key in keyof Destination as Key extends keyof Source ? never : Key]: Destination[Key] } & Source;
|
|
899
|
+
|
|
900
|
+
/**
|
|
901
|
+
Merge two types into a new type. Keys of the second type overrides keys of the first type.
|
|
902
|
+
|
|
903
|
+
@example
|
|
904
|
+
```
|
|
905
|
+
import type {Merge} from 'type-fest';
|
|
906
|
+
|
|
907
|
+
type Foo = {
|
|
908
|
+
[x: string]: unknown;
|
|
909
|
+
[x: number]: unknown;
|
|
910
|
+
foo: string;
|
|
911
|
+
bar: symbol;
|
|
912
|
+
};
|
|
913
|
+
|
|
914
|
+
type Bar = {
|
|
915
|
+
[x: number]: number;
|
|
916
|
+
[x: symbol]: unknown;
|
|
917
|
+
bar: Date;
|
|
918
|
+
baz: boolean;
|
|
919
|
+
};
|
|
920
|
+
|
|
921
|
+
export type FooBar = Merge<Foo, Bar>;
|
|
922
|
+
// => {
|
|
923
|
+
// [x: string]: unknown;
|
|
924
|
+
// [x: number]: number;
|
|
925
|
+
// [x: symbol]: unknown;
|
|
926
|
+
// foo: string;
|
|
927
|
+
// bar: Date;
|
|
928
|
+
// baz: boolean;
|
|
929
|
+
// }
|
|
930
|
+
```
|
|
931
|
+
|
|
932
|
+
@category Object
|
|
933
|
+
*/
|
|
934
|
+
type Merge<Destination, Source> = Simplify<SimpleMerge<PickIndexSignature<Destination>, PickIndexSignature<Source>> & SimpleMerge<OmitIndexSignature<Destination>, OmitIndexSignature<Source>>>;
|
|
935
|
+
//#endregion
|
|
936
|
+
//#region node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/internal/object.d.ts
|
|
937
|
+
/**
|
|
938
|
+
Works similar to the built-in `Pick` utility type, except for the following differences:
|
|
939
|
+
- Distributes over union types and allows picking keys from any member of the union type.
|
|
940
|
+
- Primitives types are returned as-is.
|
|
941
|
+
- Picks all keys if `Keys` is `any`.
|
|
942
|
+
- Doesn't pick `number` from a `string` index signature.
|
|
943
|
+
|
|
944
|
+
@example
|
|
945
|
+
```
|
|
946
|
+
type ImageUpload = {
|
|
947
|
+
url: string;
|
|
948
|
+
size: number;
|
|
949
|
+
thumbnailUrl: string;
|
|
950
|
+
};
|
|
951
|
+
|
|
952
|
+
type VideoUpload = {
|
|
953
|
+
url: string;
|
|
954
|
+
duration: number;
|
|
955
|
+
encodingFormat: string;
|
|
956
|
+
};
|
|
957
|
+
|
|
958
|
+
// Distributes over union types and allows picking keys from any member of the union type
|
|
959
|
+
type MediaDisplay = HomomorphicPick<ImageUpload | VideoUpload, "url" | "size" | "duration">;
|
|
960
|
+
//=> {url: string; size: number} | {url: string; duration: number}
|
|
961
|
+
|
|
962
|
+
// Primitive types are returned as-is
|
|
963
|
+
type Primitive = HomomorphicPick<string | number, 'toUpperCase' | 'toString'>;
|
|
964
|
+
//=> string | number
|
|
965
|
+
|
|
966
|
+
// Picks all keys if `Keys` is `any`
|
|
967
|
+
type Any = HomomorphicPick<{a: 1; b: 2} | {c: 3}, any>;
|
|
968
|
+
//=> {a: 1; b: 2} | {c: 3}
|
|
969
|
+
|
|
970
|
+
// Doesn't pick `number` from a `string` index signature
|
|
971
|
+
type IndexSignature = HomomorphicPick<{[k: string]: unknown}, number>;
|
|
972
|
+
//=> {}
|
|
973
|
+
*/
|
|
974
|
+
type HomomorphicPick<T, Keys extends KeysOfUnion<T>> = { [P in keyof T as Extract<P, Keys>]: T[P] };
|
|
975
|
+
/**
|
|
976
|
+
Merges user specified options with default options.
|
|
977
|
+
|
|
978
|
+
@example
|
|
979
|
+
```
|
|
980
|
+
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
981
|
+
type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
|
|
982
|
+
type SpecifiedOptions = {leavesOnly: true};
|
|
983
|
+
|
|
984
|
+
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
985
|
+
//=> {maxRecursionDepth: 10; leavesOnly: true}
|
|
986
|
+
```
|
|
987
|
+
|
|
988
|
+
@example
|
|
989
|
+
```
|
|
990
|
+
// Complains if default values are not provided for optional options
|
|
991
|
+
|
|
992
|
+
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
993
|
+
type DefaultPathsOptions = {maxRecursionDepth: 10};
|
|
994
|
+
type SpecifiedOptions = {};
|
|
995
|
+
|
|
996
|
+
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
997
|
+
// ~~~~~~~~~~~~~~~~~~~
|
|
998
|
+
// Property 'leavesOnly' is missing in type 'DefaultPathsOptions' but required in type '{ maxRecursionDepth: number; leavesOnly: boolean; }'.
|
|
999
|
+
```
|
|
1000
|
+
|
|
1001
|
+
@example
|
|
1002
|
+
```
|
|
1003
|
+
// Complains if an option's default type does not conform to the expected type
|
|
1004
|
+
|
|
1005
|
+
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
1006
|
+
type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: 'no'};
|
|
1007
|
+
type SpecifiedOptions = {};
|
|
1008
|
+
|
|
1009
|
+
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
1010
|
+
// ~~~~~~~~~~~~~~~~~~~
|
|
1011
|
+
// Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
|
|
1012
|
+
```
|
|
1013
|
+
|
|
1014
|
+
@example
|
|
1015
|
+
```
|
|
1016
|
+
// Complains if an option's specified type does not conform to the expected type
|
|
1017
|
+
|
|
1018
|
+
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
1019
|
+
type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
|
|
1020
|
+
type SpecifiedOptions = {leavesOnly: 'yes'};
|
|
1021
|
+
|
|
1022
|
+
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
1023
|
+
// ~~~~~~~~~~~~~~~~
|
|
1024
|
+
// Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
|
|
1025
|
+
```
|
|
1026
|
+
*/
|
|
1027
|
+
type ApplyDefaultOptions<Options extends object, Defaults extends Simplify<Omit<Required<Options>, RequiredKeysOf<Options>> & Partial<Record<RequiredKeysOf<Options>, never>>>, SpecifiedOptions extends Options> = If<IsAny<SpecifiedOptions>, Defaults, If<IsNever<SpecifiedOptions>, Defaults, Simplify<Merge<Defaults, { [Key in keyof SpecifiedOptions as Key extends OptionalKeysOf<Options> ? undefined extends SpecifiedOptions[Key] ? never : Key : Key]: SpecifiedOptions[Key] }> & Required<Options>>>>;
|
|
1028
|
+
//#endregion
|
|
1029
|
+
//#region node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/except.d.ts
|
|
1030
|
+
/**
|
|
1031
|
+
Filter out keys from an object.
|
|
1032
|
+
|
|
1033
|
+
Returns `never` if `Exclude` is strictly equal to `Key`.
|
|
1034
|
+
Returns `never` if `Key` extends `Exclude`.
|
|
1035
|
+
Returns `Key` otherwise.
|
|
1036
|
+
|
|
1037
|
+
@example
|
|
1038
|
+
```
|
|
1039
|
+
type Filtered = Filter<'foo', 'foo'>;
|
|
1040
|
+
//=> never
|
|
1041
|
+
```
|
|
1042
|
+
|
|
1043
|
+
@example
|
|
1044
|
+
```
|
|
1045
|
+
type Filtered = Filter<'bar', string>;
|
|
1046
|
+
//=> never
|
|
1047
|
+
```
|
|
1048
|
+
|
|
1049
|
+
@example
|
|
1050
|
+
```
|
|
1051
|
+
type Filtered = Filter<'bar', 'foo'>;
|
|
1052
|
+
//=> 'bar'
|
|
1053
|
+
```
|
|
1054
|
+
|
|
1055
|
+
@see {Except}
|
|
1056
|
+
*/
|
|
1057
|
+
type Filter<KeyType$1, ExcludeType> = IsEqual<KeyType$1, ExcludeType> extends true ? never : (KeyType$1 extends ExcludeType ? never : KeyType$1);
|
|
1058
|
+
type ExceptOptions = {
|
|
1059
|
+
/**
|
|
1060
|
+
Disallow assigning non-specified properties.
|
|
1061
|
+
Note that any omitted properties in the resulting type will be present in autocomplete as `undefined`.
|
|
1062
|
+
@default false
|
|
1063
|
+
*/
|
|
1064
|
+
requireExactProps?: boolean;
|
|
1065
|
+
};
|
|
1066
|
+
type DefaultExceptOptions = {
|
|
1067
|
+
requireExactProps: false;
|
|
1068
|
+
};
|
|
1069
|
+
|
|
1070
|
+
/**
|
|
1071
|
+
Create a type from an object type without certain keys.
|
|
1072
|
+
|
|
1073
|
+
We recommend setting the `requireExactProps` option to `true`.
|
|
1074
|
+
|
|
1075
|
+
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.
|
|
1076
|
+
|
|
1077
|
+
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)).
|
|
1078
|
+
|
|
1079
|
+
@example
|
|
1080
|
+
```
|
|
1081
|
+
import type {Except} from 'type-fest';
|
|
1082
|
+
|
|
1083
|
+
type Foo = {
|
|
1084
|
+
a: number;
|
|
1085
|
+
b: string;
|
|
1086
|
+
};
|
|
1087
|
+
|
|
1088
|
+
type FooWithoutA = Except<Foo, 'a'>;
|
|
1089
|
+
//=> {b: string}
|
|
1090
|
+
|
|
1091
|
+
// @ts-expect-error
|
|
1092
|
+
const fooWithoutA: FooWithoutA = {a: 1, b: '2'};
|
|
1093
|
+
//=> errors: 'a' does not exist in type '{ b: string; }'
|
|
1094
|
+
|
|
1095
|
+
type FooWithoutB = Except<Foo, 'b', {requireExactProps: true}>;
|
|
1096
|
+
//=> {a: number} & Partial<Record<"b", never>>
|
|
1097
|
+
|
|
1098
|
+
// @ts-expect-error
|
|
1099
|
+
const fooWithoutB: FooWithoutB = {a: 1, b: '2'};
|
|
1100
|
+
//=> errors at 'b': Type 'string' is not assignable to type 'undefined'.
|
|
1101
|
+
|
|
1102
|
+
// The `Omit` utility type doesn't work when omitting specific keys from objects containing index signatures.
|
|
1103
|
+
|
|
1104
|
+
// Consider the following example:
|
|
1105
|
+
|
|
1106
|
+
type UserData = {
|
|
1107
|
+
[metadata: string]: string;
|
|
1108
|
+
email: string;
|
|
1109
|
+
name: string;
|
|
1110
|
+
role: 'admin' | 'user';
|
|
1111
|
+
};
|
|
1112
|
+
|
|
1113
|
+
// `Omit` clearly doesn't behave as expected in this case:
|
|
1114
|
+
type PostPayload = Omit<UserData, 'email'>;
|
|
1115
|
+
//=> { [x: string]: string; [x: number]: string; }
|
|
1116
|
+
|
|
1117
|
+
// In situations like this, `Except` works better.
|
|
1118
|
+
// It simply removes the `email` key while preserving all the other keys.
|
|
1119
|
+
type PostPayloadFixed = Except<UserData, 'email'>;
|
|
1120
|
+
//=> { [x: string]: string; name: string; role: 'admin' | 'user'; }
|
|
1121
|
+
```
|
|
1122
|
+
|
|
1123
|
+
@category Object
|
|
1124
|
+
*/
|
|
1125
|
+
type Except<ObjectType, KeysType extends keyof ObjectType, Options extends ExceptOptions = {}> = _Except<ObjectType, KeysType, ApplyDefaultOptions<ExceptOptions, DefaultExceptOptions, Options>>;
|
|
1126
|
+
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>> : {});
|
|
1127
|
+
//#endregion
|
|
1128
|
+
//#region node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/require-at-least-one.d.ts
|
|
1129
|
+
/**
|
|
1130
|
+
Create a type that requires at least one of the given keys. The remaining keys are kept as is.
|
|
1131
|
+
|
|
1132
|
+
@example
|
|
1133
|
+
```
|
|
1134
|
+
import type {RequireAtLeastOne} from 'type-fest';
|
|
1135
|
+
|
|
1136
|
+
type Responder = {
|
|
1137
|
+
text?: () => string;
|
|
1138
|
+
json?: () => string;
|
|
1139
|
+
secure?: boolean;
|
|
1140
|
+
};
|
|
1141
|
+
|
|
1142
|
+
const responder: RequireAtLeastOne<Responder, 'text' | 'json'> = {
|
|
1143
|
+
json: () => '{"message": "ok"}',
|
|
1144
|
+
secure: true,
|
|
1145
|
+
};
|
|
1146
|
+
```
|
|
1147
|
+
|
|
1148
|
+
@category Object
|
|
1149
|
+
*/
|
|
1150
|
+
type RequireAtLeastOne<ObjectType, KeysType extends keyof ObjectType = keyof ObjectType> = IfNotAnyOrNever<ObjectType, If<IsNever<KeysType>, never, _RequireAtLeastOne<ObjectType, If<IsAny<KeysType>, keyof ObjectType, KeysType>>>>;
|
|
1151
|
+
type _RequireAtLeastOne<ObjectType, KeysType extends keyof ObjectType> = {
|
|
1152
|
+
// For each `Key` in `KeysType` make a mapped type:
|
|
1153
|
+
[Key in KeysType]-?: Required<Pick<ObjectType, Key>> &
|
|
1154
|
+
// 1. Make `Key`'s type required
|
|
1155
|
+
// 2. Make all other keys in `KeysType` optional
|
|
1156
|
+
Partial<Pick<ObjectType, Exclude<KeysType, Key>>> }[KeysType] &
|
|
1157
|
+
// 3. Add the remaining keys not in `KeysType`
|
|
1158
|
+
Except<ObjectType, KeysType>;
|
|
1159
|
+
//#endregion
|
|
1160
|
+
//#region node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/non-empty-object.d.ts
|
|
1161
|
+
/**
|
|
1162
|
+
Represents an object with at least 1 non-optional key.
|
|
1163
|
+
|
|
1164
|
+
This is useful when you need an object where all keys are optional, but there must be at least 1 key.
|
|
1165
|
+
|
|
1166
|
+
@example
|
|
1167
|
+
```
|
|
1168
|
+
import type {NonEmptyObject} from 'type-fest';
|
|
1169
|
+
|
|
1170
|
+
type User = {
|
|
1171
|
+
name: string;
|
|
1172
|
+
surname: string;
|
|
1173
|
+
id: number;
|
|
1174
|
+
};
|
|
1175
|
+
|
|
1176
|
+
type UpdateRequest<Entity extends object> = NonEmptyObject<Partial<Entity>>;
|
|
1177
|
+
|
|
1178
|
+
const update1: UpdateRequest<User> = {
|
|
1179
|
+
name: 'Alice',
|
|
1180
|
+
surname: 'Acme',
|
|
1181
|
+
};
|
|
1182
|
+
|
|
1183
|
+
// At least 1 key is required, therefore this will report a 2322 error:
|
|
1184
|
+
// Type '{}' is not assignable to type 'UpdateRequest<User>'
|
|
1185
|
+
// @ts-expect-error
|
|
1186
|
+
const update2: UpdateRequest<User> = {};
|
|
1187
|
+
```
|
|
1188
|
+
|
|
1189
|
+
@see Use `IsEmptyObject` to check whether an object is empty.
|
|
1190
|
+
|
|
1191
|
+
@category Object
|
|
1192
|
+
*/
|
|
1193
|
+
type NonEmptyObject<T extends object> = HasRequiredKeys<T> extends true ? T : RequireAtLeastOne<T, keyof T>;
|
|
1194
|
+
//#endregion
|
|
1195
|
+
//#region node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/union-to-tuple.d.ts
|
|
1196
|
+
/**
|
|
1197
|
+
Returns the last element of a union type.
|
|
1198
|
+
|
|
1199
|
+
@example
|
|
1200
|
+
```
|
|
1201
|
+
type Last = LastOfUnion<1 | 2 | 3>;
|
|
1202
|
+
//=> 3
|
|
1203
|
+
```
|
|
1204
|
+
*/
|
|
1205
|
+
type LastOfUnion<T> = UnionToIntersection<T extends any ? () => T : never> extends (() => (infer R)) ? R : never;
|
|
1206
|
+
|
|
1207
|
+
/**
|
|
1208
|
+
Convert a union type into an unordered tuple type of its elements.
|
|
1209
|
+
|
|
1210
|
+
"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.
|
|
1211
|
+
|
|
1212
|
+
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.
|
|
1213
|
+
|
|
1214
|
+
@example
|
|
1215
|
+
```
|
|
1216
|
+
import type {UnionToTuple} from 'type-fest';
|
|
1217
|
+
|
|
1218
|
+
type Numbers = 1 | 2 | 3;
|
|
1219
|
+
type NumbersTuple = UnionToTuple<Numbers>;
|
|
1220
|
+
//=> [1, 2, 3]
|
|
1221
|
+
```
|
|
1222
|
+
|
|
1223
|
+
@example
|
|
1224
|
+
```
|
|
1225
|
+
import type {UnionToTuple} from 'type-fest';
|
|
1226
|
+
|
|
1227
|
+
const pets = {
|
|
1228
|
+
dog: '🐶',
|
|
1229
|
+
cat: '🐱',
|
|
1230
|
+
snake: '🐍',
|
|
1231
|
+
};
|
|
1232
|
+
|
|
1233
|
+
type Pet = keyof typeof pets;
|
|
1234
|
+
//=> 'dog' | 'cat' | 'snake'
|
|
1235
|
+
|
|
1236
|
+
const petList = Object.keys(pets) as UnionToTuple<Pet>;
|
|
1237
|
+
//=> ['dog', 'cat', 'snake']
|
|
1238
|
+
```
|
|
1239
|
+
|
|
1240
|
+
@category Array
|
|
1241
|
+
*/
|
|
1242
|
+
type UnionToTuple<T, L = LastOfUnion<T>> = IsNever<T> extends false ? [...UnionToTuple<Exclude<T, L>>, L] : [];
|
|
1243
|
+
//#endregion
|
|
1244
|
+
//#region node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/set-optional.d.ts
|
|
1245
|
+
/**
|
|
1246
|
+
Create a type that makes the given keys optional. The remaining keys are kept as is. The sister of the `SetRequired` type.
|
|
1247
|
+
|
|
1248
|
+
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.
|
|
1249
|
+
|
|
1250
|
+
@example
|
|
1251
|
+
```
|
|
1252
|
+
import type {SetOptional} from 'type-fest';
|
|
1253
|
+
|
|
1254
|
+
type Foo = {
|
|
1255
|
+
a: number;
|
|
1256
|
+
b?: string;
|
|
1257
|
+
c: boolean;
|
|
1258
|
+
};
|
|
1259
|
+
|
|
1260
|
+
type SomeOptional = SetOptional<Foo, 'b' | 'c'>;
|
|
1261
|
+
// type SomeOptional = {
|
|
1262
|
+
// a: number;
|
|
1263
|
+
// b?: string; // Was already optional and still is.
|
|
1264
|
+
// c?: boolean; // Is now optional.
|
|
1265
|
+
// }
|
|
1266
|
+
```
|
|
1267
|
+
|
|
1268
|
+
@category Object
|
|
1269
|
+
*/
|
|
1270
|
+
type SetOptional<BaseType, Keys extends keyof BaseType> = (BaseType extends ((...arguments_: never) => any) ? (...arguments_: Parameters<BaseType>) => ReturnType<BaseType> : unknown) & _SetOptional<BaseType, Keys>;
|
|
1271
|
+
type _SetOptional<BaseType, Keys extends keyof BaseType> = BaseType extends unknown // To distribute `BaseType` when it's a union type.
|
|
1272
|
+
? Simplify<
|
|
1273
|
+
// Pick just the keys that are readonly from the base type.
|
|
1274
|
+
Except<BaseType, Keys> &
|
|
1275
|
+
// Pick the keys that should be mutable from the base type and make them mutable.
|
|
1276
|
+
Partial<HomomorphicPick<BaseType, Keys>>> : never;
|
|
1277
|
+
//#endregion
|
|
1278
|
+
//#region node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/value-of.d.ts
|
|
1279
|
+
/**
|
|
1280
|
+
Create a union of the given object's values, and optionally specify which keys to get the values from.
|
|
1281
|
+
|
|
1282
|
+
Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/31438) if you want to have this type as a built-in in TypeScript.
|
|
1283
|
+
|
|
1284
|
+
@example
|
|
1285
|
+
```
|
|
1286
|
+
import type {ValueOf} from 'type-fest';
|
|
1287
|
+
|
|
1288
|
+
type A = ValueOf<{id: number; name: string; active: boolean}>;
|
|
1289
|
+
//=> number | string | boolean
|
|
1290
|
+
|
|
1291
|
+
type B = ValueOf<{id: number; name: string; active: boolean}, 'name'>;
|
|
1292
|
+
//=> string
|
|
1293
|
+
|
|
1294
|
+
type C = ValueOf<{id: number; name: string; active: boolean}, 'id' | 'name'>;
|
|
1295
|
+
//=> number | string
|
|
1296
|
+
```
|
|
1297
|
+
|
|
1298
|
+
@category Object
|
|
1299
|
+
*/
|
|
1300
|
+
type ValueOf<ObjectType, ValueType extends keyof ObjectType = keyof ObjectType> = ObjectType[ValueType];
|
|
1301
|
+
//#endregion
|
|
1302
|
+
//#region node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/replace.d.ts
|
|
1303
|
+
type ReplaceOptions = {
|
|
1304
|
+
all?: boolean;
|
|
1305
|
+
};
|
|
1306
|
+
type DefaultReplaceOptions = {
|
|
1307
|
+
all: false;
|
|
1308
|
+
};
|
|
1309
|
+
|
|
1310
|
+
/**
|
|
1311
|
+
Represents a string with some or all matches replaced by a replacement.
|
|
1312
|
+
|
|
1313
|
+
Use-case:
|
|
1314
|
+
- `kebab-case-path` to `dotted.path.notation`
|
|
1315
|
+
- Changing date/time format: `01-08-2042` → `01/08/2042`
|
|
1316
|
+
- Manipulation of type properties, for example, removal of prefixes
|
|
1317
|
+
|
|
1318
|
+
@example
|
|
1319
|
+
```
|
|
1320
|
+
import type {Replace} from 'type-fest';
|
|
1321
|
+
|
|
1322
|
+
declare function replace<
|
|
1323
|
+
Input extends string,
|
|
1324
|
+
Search extends string,
|
|
1325
|
+
Replacement extends string,
|
|
1326
|
+
>(
|
|
1327
|
+
input: Input,
|
|
1328
|
+
search: Search,
|
|
1329
|
+
replacement: Replacement
|
|
1330
|
+
): Replace<Input, Search, Replacement>;
|
|
1331
|
+
|
|
1332
|
+
declare function replaceAll<
|
|
1333
|
+
Input extends string,
|
|
1334
|
+
Search extends string,
|
|
1335
|
+
Replacement extends string,
|
|
1336
|
+
>(
|
|
1337
|
+
input: Input,
|
|
1338
|
+
search: Search,
|
|
1339
|
+
replacement: Replacement
|
|
1340
|
+
): Replace<Input, Search, Replacement, {all: true}>;
|
|
1341
|
+
|
|
1342
|
+
// The return type is the exact string literal, not just `string`.
|
|
1343
|
+
|
|
1344
|
+
replace('hello ?', '?', '🦄');
|
|
1345
|
+
//=> 'hello 🦄'
|
|
1346
|
+
|
|
1347
|
+
replace('hello ??', '?', '❓');
|
|
1348
|
+
//=> 'hello ❓?'
|
|
1349
|
+
|
|
1350
|
+
replaceAll('10:42:00', ':', '-');
|
|
1351
|
+
//=> '10-42-00'
|
|
1352
|
+
|
|
1353
|
+
replaceAll('__userName__', '__', '');
|
|
1354
|
+
//=> 'userName'
|
|
1355
|
+
|
|
1356
|
+
replaceAll('My Cool Title', ' ', '');
|
|
1357
|
+
//=> 'MyCoolTitle'
|
|
1358
|
+
```
|
|
1359
|
+
|
|
1360
|
+
@category String
|
|
1361
|
+
@category Template literal
|
|
1362
|
+
*/
|
|
1363
|
+
type Replace<Input extends string, Search extends string, Replacement extends string, Options extends ReplaceOptions = {}> = _Replace<Input, Search, Replacement, ApplyDefaultOptions<ReplaceOptions, DefaultReplaceOptions, Options>>;
|
|
1364
|
+
type _Replace<Input extends string, Search extends string, Replacement extends string, Options extends Required<ReplaceOptions>, Accumulator extends string = ''> = Search extends string // For distributing `Search`
|
|
1365
|
+
? Replacement extends string // For distributing `Replacement`
|
|
1366
|
+
? 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;
|
|
1367
|
+
//#endregion
|
|
177
1368
|
//#region src/utils/object/enumEntries.d.ts
|
|
178
1369
|
/**
|
|
179
1370
|
* 返回枚举的属性的键/值数组
|
|
@@ -202,7 +1393,7 @@ declare function enumTypeCheck<E extends AnyObject>(enumeration: E): E & Record<
|
|
|
202
1393
|
declare function enumValues<E extends AnyObject>(enumeration: NonEmptyObject<E>): UnionToTuple<ValueOf<E>>;
|
|
203
1394
|
//#endregion
|
|
204
1395
|
//#region src/utils/object/mapEntries.d.ts
|
|
205
|
-
declare function mapEntries<K$1 extends PropertyKey, V, NK extends PropertyKey, NV>(obj:
|
|
1396
|
+
declare function mapEntries<K$1 extends PropertyKey, V, NK extends PropertyKey, NV>(obj: PlainObject<K$1, V>, toEntry: (key: K$1, value: V) => [NK, NV]): PlainObject<NK, NV>;
|
|
206
1397
|
//#endregion
|
|
207
1398
|
//#region node_modules/.pnpm/radashi@12.7.1/node_modules/radashi/dist/radashi.d.cts
|
|
208
1399
|
|
|
@@ -887,11 +2078,11 @@ TOverride | (IsOptional extends true ? TInitial : never) : Extract<TOverride, ob
|
|
|
887
2078
|
* @param initial 初始对象
|
|
888
2079
|
* @param override 待合并对象
|
|
889
2080
|
*/
|
|
890
|
-
declare function objectAssign<I$1 extends
|
|
2081
|
+
declare function objectAssign<I$1 extends PlainObject, O extends PlainObject>(initial: I$1, override: O): Assign<I$1, O>;
|
|
891
2082
|
//#endregion
|
|
892
2083
|
//#region src/utils/object/objectCrush.d.ts
|
|
893
2084
|
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>>;
|
|
894
|
-
declare function objectCrush<T extends
|
|
2085
|
+
declare function objectCrush<T extends PlainObject>(value: T): Crush<T>;
|
|
895
2086
|
//#endregion
|
|
896
2087
|
//#region src/utils/object/objectEntries.d.ts
|
|
897
2088
|
/**
|
|
@@ -932,27 +2123,65 @@ declare function objectValues<O extends AnyObject>(obj: O): UnionToTuple<ValueOf
|
|
|
932
2123
|
//#endregion
|
|
933
2124
|
//#region src/utils/string/stringInitialCase.d.ts
|
|
934
2125
|
/**
|
|
935
|
-
*
|
|
2126
|
+
* 字符串首字母大小写
|
|
2127
|
+
* - 包含非西欧字母字符时,不处理
|
|
2128
|
+
* - 纯字母且全大写时,不处理
|
|
2129
|
+
* - 纯字母且非全大写时,首字母小写,其余保留
|
|
2130
|
+
* - 纯字母且非全大写时,首字母大写,其余保留
|
|
2131
|
+
*
|
|
2132
|
+
* @param input 待处理字符串
|
|
2133
|
+
* @param caseType 大小写类型
|
|
936
2134
|
*/
|
|
937
|
-
declare function stringInitialCase(input: string,
|
|
2135
|
+
declare function stringInitialCase(input: string, caseType?: "lower" | "upper" | undefined): string;
|
|
938
2136
|
//#endregion
|
|
939
2137
|
//#region src/utils/string/stringReplace.d.ts
|
|
2138
|
+
/**
|
|
2139
|
+
* 字符串替换
|
|
2140
|
+
* - 替换第一个匹配项
|
|
2141
|
+
*
|
|
2142
|
+
* @param input 待处理字符串
|
|
2143
|
+
* @param search 匹配项
|
|
2144
|
+
* @param replacement 替换项
|
|
2145
|
+
*/
|
|
940
2146
|
declare function stringReplace<I$1 extends string, S extends string, R$1 extends string>(input: I$1, search: S, replacement: R$1): Replace<I$1, S, R$1>;
|
|
941
2147
|
//#endregion
|
|
942
2148
|
//#region src/utils/string/stringTemplate.d.ts
|
|
943
|
-
|
|
2149
|
+
/**
|
|
2150
|
+
* 字符串模板替换
|
|
2151
|
+
*
|
|
2152
|
+
* @param input 待处理字符串
|
|
2153
|
+
* @param template 模板对象
|
|
2154
|
+
* @param regex 模板匹配正则
|
|
2155
|
+
*/
|
|
2156
|
+
declare function stringTemplate(input: string, template: PlainObject, regex?: RegExp): string;
|
|
944
2157
|
//#endregion
|
|
945
2158
|
//#region src/utils/string/stringToJson.d.ts
|
|
2159
|
+
/**
|
|
2160
|
+
* 处理 JSON 字符串
|
|
2161
|
+
*
|
|
2162
|
+
* @param input 待处理字符串
|
|
2163
|
+
* @param safeValue 安全值
|
|
2164
|
+
*/
|
|
946
2165
|
declare function stringToJson<R$1 extends AnyObject = AnyObject, D extends R$1 = R$1>(input: string | null | undefined, safeValue: D): R$1;
|
|
947
2166
|
//#endregion
|
|
948
2167
|
//#region src/utils/string/stringToNumber.d.ts
|
|
949
2168
|
/**
|
|
950
|
-
*
|
|
2169
|
+
* 从字符串中提取数字字符串
|
|
2170
|
+
*
|
|
2171
|
+
* @param input 待处理字符串
|
|
951
2172
|
*/
|
|
952
2173
|
declare function stringToNumber(input: string): string;
|
|
953
2174
|
//#endregion
|
|
954
2175
|
//#region src/utils/string/stringToValues.d.ts
|
|
955
|
-
|
|
2176
|
+
/**
|
|
2177
|
+
* 字符串分割为数组
|
|
2178
|
+
*
|
|
2179
|
+
* @param input 待处理字符串
|
|
2180
|
+
* @param valueType 数组中每一项的类型
|
|
2181
|
+
* @param splitSymbol 分隔符,默认为 `,`
|
|
2182
|
+
*/
|
|
2183
|
+
declare function stringToValues(input: string | null | undefined, valueType?: "number" | undefined, splitSymbol?: string | undefined): number[];
|
|
2184
|
+
declare function stringToValues(input: string | null | undefined, valueType: "string", splitSymbol?: string | undefined): string[];
|
|
956
2185
|
//#endregion
|
|
957
2186
|
//#region src/utils/tree/types.d.ts
|
|
958
2187
|
type RowKey = "id";
|
|
@@ -1155,5 +2384,5 @@ declare function isWebSocket(value: unknown): value is WebSocket;
|
|
|
1155
2384
|
//#region src/utils/typeof/isWindow.d.ts
|
|
1156
2385
|
declare function isWindow(value: unknown): value is Window;
|
|
1157
2386
|
//#endregion
|
|
1158
|
-
export {
|
|
2387
|
+
export { arrayCast, arrayCompete, arrayCounting, arrayDifference, arrayFirst, arrayFork, arrayIntersection, arrayLast, arrayMerge, arrayPick, arrayReplace, arraySplit, cloneDeep, enumEntries, enumKeys, enumTypeCheck, enumValues, isAbortSignal, isArray, isAsyncFunction, isAsyncGeneratorFunction, isBigInt, isBlob, isBoolean, isClass, isDate, isEqual, isError, isFalsy, isFalsyLike, isFile, isFunction, isGeneratorFunction, isInfinity, isInfinityLike, isInteger, isIterable, isMap, isNaN, isNegativeInteger, isNull, isNumber, isObject, isPositiveInteger, isPromise, isPromiseLike, isReadableStream, isRegExp, isSet, isString, isSymbol, isTypedArray, isURLSearchParams, isUndefined, isWeakMap, isWeakSet, isWebSocket, isWindow, mapEntries, objectAssign, objectCrush, objectEntries, objectKeys, objectPick, objectSwitch, objectValues, rowsToTree, stringInitialCase, stringReplace, stringTemplate, stringToJson, stringToNumber, stringToValues, to, toMathBignumber, toMathDecimal, toMathEvaluate, treeFilter, treeFind, treeForEach, treeMap, treeToRows };
|
|
1159
2388
|
//# sourceMappingURL=index.d.ts.map
|