@esposter/shared 2.19.2 → 2.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -201
- package/dist/index.d.ts +1218 -133
- package/dist/index.js +129 -216
- package/dist/magic-string.es-CDi1Mjxn.js +1011 -0
- package/package.json +8 -6
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,11 @@ declare const AllSpecialValues: {
|
|
|
6
6
|
value: unknown;
|
|
7
7
|
}[];
|
|
8
8
|
//#endregion
|
|
9
|
+
//#region src/models/error/ForbiddenError.d.ts
|
|
10
|
+
declare class ForbiddenError extends Error {
|
|
11
|
+
constructor(message: string);
|
|
12
|
+
}
|
|
13
|
+
//#endregion
|
|
9
14
|
//#region src/models/shared/Operation.d.ts
|
|
10
15
|
declare enum Operation {
|
|
11
16
|
Create = "Create",
|
|
@@ -49,6 +54,7 @@ declare const RoutePath: {
|
|
|
49
54
|
readonly Index: "/";
|
|
50
55
|
readonly Login: "/login";
|
|
51
56
|
readonly Messages: (id: string) => string;
|
|
57
|
+
readonly MessagesFriends: "/messages/friends";
|
|
52
58
|
readonly MessagesIndex: "/messages";
|
|
53
59
|
readonly MessagesInvite: (code: string) => string;
|
|
54
60
|
readonly MessagesMessage: (id: string, rowKey: string) => string;
|
|
@@ -64,7 +70,67 @@ declare const RoutePath: {
|
|
|
64
70
|
};
|
|
65
71
|
type RoutePath = typeof RoutePath;
|
|
66
72
|
//#endregion
|
|
67
|
-
//#region
|
|
73
|
+
//#region src/util/types/GetProperties.d.ts
|
|
74
|
+
type GetProperties<T, P extends string = "", D extends unknown[] = [unknown, unknown, unknown, unknown, unknown], R extends boolean = true> = [T] extends [never] ? never : D extends [] ? never : NonNullable<T> extends infer O ? O extends unknown[] ? GetArrayProps<O, P, D, R> : O extends object ? GetObjectProps<O, P, D, R> : GetPrimitiveProps<O, P, D, R> : never;
|
|
75
|
+
type GetArrayProps<T extends unknown[], P extends string, D extends unknown[], R extends boolean> = (D extends [unknown, ...infer Rest] ? GetProperties<T[number], R extends true ? `${P}[number]` : `${P}.[number]`, Rest, false> : never) | {
|
|
76
|
+
path: R extends true ? "length" : `${P}.length`;
|
|
77
|
+
value: T["length"];
|
|
78
|
+
};
|
|
79
|
+
type GetObjectProps<T, P extends string, D extends unknown[], R extends boolean> = { [K in keyof KnownKeys<T> & (number | string)]: K extends `${number}` ? never : NonNullable<T[K]> extends Function ? never : (D extends [unknown, ...infer Rest] ? GetProperties<T[K], R extends true ? `${K}` : `${P}.${K}`, Rest, false> : never) | {
|
|
80
|
+
path: R extends true ? `${K}` : `${P}.${K}`;
|
|
81
|
+
value: T[K];
|
|
82
|
+
} }[keyof KnownKeys<T> & (number | string)];
|
|
83
|
+
type GetPrimitiveProps<T, P extends string, D extends unknown[], R extends boolean> = T extends string ? {
|
|
84
|
+
path: R extends true ? "length" : `${P}.length`;
|
|
85
|
+
value: number;
|
|
86
|
+
} : T extends symbol ? (D extends [unknown, ...infer Rest] ? GetProperties<string | undefined, R extends true ? "description" : `${P}.description`, Rest, false> : never) | {
|
|
87
|
+
path: R extends true ? "description" : `${P}.description`;
|
|
88
|
+
value: string | undefined;
|
|
89
|
+
} : never;
|
|
90
|
+
type KnownKeys<T> = { [K in keyof T as string extends K ? never : number extends K ? never : K]: T[K] };
|
|
91
|
+
//#endregion
|
|
92
|
+
//#region src/util/types/GetPaths.d.ts
|
|
93
|
+
type GetPaths<T> = GetProperties<T> extends infer U ? (U extends {
|
|
94
|
+
path: infer Path;
|
|
95
|
+
} ? Path : never) : never;
|
|
96
|
+
//#endregion
|
|
97
|
+
//#region src/util/types/PropertyNames.d.ts
|
|
98
|
+
type PropertyNames<T> = { [P in GetPaths<T>]: P };
|
|
99
|
+
//#endregion
|
|
100
|
+
//#region src/models/shared/ItemEntityType.d.ts
|
|
101
|
+
interface ItemEntityType<T extends string> {
|
|
102
|
+
type: T;
|
|
103
|
+
}
|
|
104
|
+
declare const ItemEntityTypePropertyNames: PropertyNames<ItemEntityType<string>>;
|
|
105
|
+
declare const createItemEntityTypeSchema: <T extends z.ZodType<string>>(schema: T) => z.ZodObject<{
|
|
106
|
+
type: T;
|
|
107
|
+
}>;
|
|
108
|
+
//#endregion
|
|
109
|
+
//#region src/models/shared/ItemMetadata.d.ts
|
|
110
|
+
declare class ItemMetadata {
|
|
111
|
+
createdAt: Date;
|
|
112
|
+
deletedAt: Date | null;
|
|
113
|
+
updatedAt: Date;
|
|
114
|
+
}
|
|
115
|
+
declare const ItemMetadataPropertyNames: PropertyNames<ItemMetadata>;
|
|
116
|
+
declare const itemMetadataSchema: z.ZodObject<{
|
|
117
|
+
createdAt: z.ZodDate;
|
|
118
|
+
deletedAt: z.ZodNullable<z.ZodDate>;
|
|
119
|
+
updatedAt: z.ZodDate;
|
|
120
|
+
}>;
|
|
121
|
+
//#endregion
|
|
122
|
+
//#region src/models/shared/Serializable.d.ts
|
|
123
|
+
declare abstract class Serializable {
|
|
124
|
+
toJSON(): this;
|
|
125
|
+
}
|
|
126
|
+
//#endregion
|
|
127
|
+
//#region src/models/shared/TakeOne.d.ts
|
|
128
|
+
interface TakeOne {
|
|
129
|
+
<T extends readonly unknown[]>(values: T, index?: number): T[number];
|
|
130
|
+
<T extends Record<PropertyKey, unknown>>(values: T, index: keyof T): T[keyof T];
|
|
131
|
+
}
|
|
132
|
+
//#endregion
|
|
133
|
+
//#region ../../node_modules/.pnpm/type-fest@5.5.0/node_modules/type-fest/source/primitive.d.ts
|
|
68
134
|
/**
|
|
69
135
|
Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive).
|
|
70
136
|
|
|
@@ -72,7 +138,7 @@ Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/
|
|
|
72
138
|
*/
|
|
73
139
|
type Primitive = null | undefined | string | number | boolean | symbol | bigint;
|
|
74
140
|
//#endregion
|
|
75
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
141
|
+
//#region ../../node_modules/.pnpm/type-fest@5.5.0/node_modules/type-fest/source/basic.d.ts
|
|
76
142
|
/**
|
|
77
143
|
Matches a [`class`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes).
|
|
78
144
|
|
|
@@ -83,7 +149,7 @@ type Class<T, Arguments extends unknown[] = any[]> = {
|
|
|
83
149
|
new (...arguments_: Arguments): T;
|
|
84
150
|
};
|
|
85
151
|
//#endregion
|
|
86
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
152
|
+
//#region ../../node_modules/.pnpm/type-fest@5.5.0/node_modules/type-fest/source/is-any.d.ts
|
|
87
153
|
/**
|
|
88
154
|
Returns a boolean for whether the given type is `any`.
|
|
89
155
|
|
|
@@ -114,7 +180,7 @@ const anyA = get(anyObject, 'a');
|
|
|
114
180
|
*/
|
|
115
181
|
type IsAny<T> = 0 extends 1 & NoInfer<T> ? true : false;
|
|
116
182
|
//#endregion
|
|
117
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
183
|
+
//#region ../../node_modules/.pnpm/type-fest@5.5.0/node_modules/type-fest/source/is-optional-key-of.d.ts
|
|
118
184
|
/**
|
|
119
185
|
Returns a boolean for whether the given key is an optional key of type.
|
|
120
186
|
|
|
@@ -157,7 +223,7 @@ type T5 = IsOptionalKeyOf<User | Admin, 'surname'>;
|
|
|
157
223
|
*/
|
|
158
224
|
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;
|
|
159
225
|
//#endregion
|
|
160
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
226
|
+
//#region ../../node_modules/.pnpm/type-fest@5.5.0/node_modules/type-fest/source/optional-keys-of.d.ts
|
|
161
227
|
/**
|
|
162
228
|
Extract all optional keys from the given type.
|
|
163
229
|
|
|
@@ -195,7 +261,7 @@ type OptionalKeysOf<Type extends object> = Type extends unknown // For distribut
|
|
|
195
261
|
? (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`
|
|
196
262
|
: never;
|
|
197
263
|
//#endregion
|
|
198
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
264
|
+
//#region ../../node_modules/.pnpm/type-fest@5.5.0/node_modules/type-fest/source/required-keys-of.d.ts
|
|
199
265
|
/**
|
|
200
266
|
Extract all required keys from the given type.
|
|
201
267
|
|
|
@@ -229,7 +295,7 @@ const validator3 = createValidation<User>('luckyNumber', value => value > 0);
|
|
|
229
295
|
type RequiredKeysOf<Type extends object> = Type extends unknown // For distributing `Type`
|
|
230
296
|
? Exclude<keyof Type, OptionalKeysOf<Type>> : never;
|
|
231
297
|
//#endregion
|
|
232
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
298
|
+
//#region ../../node_modules/.pnpm/type-fest@5.5.0/node_modules/type-fest/source/is-never.d.ts
|
|
233
299
|
/**
|
|
234
300
|
Returns a boolean for whether the given type is `never`.
|
|
235
301
|
|
|
@@ -285,7 +351,7 @@ type B = IsTrueFixed<never>;
|
|
|
285
351
|
*/
|
|
286
352
|
type IsNever<T> = [T] extends [never] ? true : false;
|
|
287
353
|
//#endregion
|
|
288
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
354
|
+
//#region ../../node_modules/.pnpm/type-fest@5.5.0/node_modules/type-fest/source/if.d.ts
|
|
289
355
|
/**
|
|
290
356
|
An if-else-like type that resolves depending on whether the given `boolean` type is `true` or `false`.
|
|
291
357
|
|
|
@@ -380,25 +446,445 @@ type Works = IncludesWithoutIf<HundredZeroes, '1'>;
|
|
|
380
446
|
*/
|
|
381
447
|
type If<Type extends boolean, IfBranch, ElseBranch> = IsNever<Type> extends true ? ElseBranch : Type extends true ? IfBranch : ElseBranch;
|
|
382
448
|
//#endregion
|
|
383
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
449
|
+
//#region ../../node_modules/.pnpm/type-fest@5.5.0/node_modules/type-fest/source/unknown-array.d.ts
|
|
450
|
+
/**
|
|
451
|
+
Represents an array with `unknown` value.
|
|
452
|
+
|
|
453
|
+
Use case: You want a type that all arrays can be assigned to, but you don't care about the value.
|
|
454
|
+
|
|
455
|
+
@example
|
|
456
|
+
```
|
|
457
|
+
import type {UnknownArray} from 'type-fest';
|
|
458
|
+
|
|
459
|
+
type IsArray<T> = T extends UnknownArray ? true : false;
|
|
460
|
+
|
|
461
|
+
type A = IsArray<['foo']>;
|
|
462
|
+
//=> true
|
|
463
|
+
|
|
464
|
+
type B = IsArray<readonly number[]>;
|
|
465
|
+
//=> true
|
|
466
|
+
|
|
467
|
+
type C = IsArray<string>;
|
|
468
|
+
//=> false
|
|
469
|
+
```
|
|
470
|
+
|
|
471
|
+
@category Type
|
|
472
|
+
@category Array
|
|
473
|
+
*/
|
|
474
|
+
type UnknownArray = readonly unknown[];
|
|
475
|
+
//#endregion
|
|
476
|
+
//#region ../../node_modules/.pnpm/type-fest@5.5.0/node_modules/type-fest/source/internal/type.d.ts
|
|
477
|
+
/**
|
|
478
|
+
Returns a boolean for whether A is false.
|
|
479
|
+
|
|
480
|
+
@example
|
|
481
|
+
```
|
|
482
|
+
type A = Not<true>;
|
|
483
|
+
//=> false
|
|
484
|
+
|
|
485
|
+
type B = Not<false>;
|
|
486
|
+
//=> true
|
|
487
|
+
```
|
|
488
|
+
*/
|
|
489
|
+
type Not<A extends boolean> = A extends true ? false : A extends false ? true : never;
|
|
490
|
+
/**
|
|
491
|
+
An if-else-like type that resolves depending on whether the given type is `any` or `never`.
|
|
492
|
+
|
|
493
|
+
@example
|
|
494
|
+
```
|
|
495
|
+
// When `T` is a NOT `any` or `never` (like `string`) => Returns `IfNotAnyOrNever` branch
|
|
496
|
+
type A = IfNotAnyOrNever<string, 'VALID', 'IS_ANY', 'IS_NEVER'>;
|
|
497
|
+
//=> 'VALID'
|
|
498
|
+
|
|
499
|
+
// When `T` is `any` => Returns `IfAny` branch
|
|
500
|
+
type B = IfNotAnyOrNever<any, 'VALID', 'IS_ANY', 'IS_NEVER'>;
|
|
501
|
+
//=> 'IS_ANY'
|
|
502
|
+
|
|
503
|
+
// When `T` is `never` => Returns `IfNever` branch
|
|
504
|
+
type C = IfNotAnyOrNever<never, 'VALID', 'IS_ANY', 'IS_NEVER'>;
|
|
505
|
+
//=> 'IS_NEVER'
|
|
506
|
+
```
|
|
507
|
+
|
|
508
|
+
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:
|
|
509
|
+
|
|
510
|
+
@example
|
|
511
|
+
```ts
|
|
512
|
+
import type {StringRepeat} from 'type-fest';
|
|
513
|
+
|
|
514
|
+
type NineHundredNinetyNineSpaces = StringRepeat<' ', 999>;
|
|
515
|
+
|
|
516
|
+
// The following implementation is not tail recursive
|
|
517
|
+
type TrimLeft<S extends string> = IfNotAnyOrNever<S, S extends ` ${infer R}` ? TrimLeft<R> : S>;
|
|
518
|
+
|
|
519
|
+
// Hence, instantiations with long strings will fail
|
|
520
|
+
// @ts-expect-error
|
|
521
|
+
type T1 = TrimLeft<NineHundredNinetyNineSpaces>;
|
|
522
|
+
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
523
|
+
// Error: Type instantiation is excessively deep and possibly infinite.
|
|
524
|
+
|
|
525
|
+
// To fix this, move the recursion into a helper type
|
|
526
|
+
type TrimLeftOptimised<S extends string> = IfNotAnyOrNever<S, _TrimLeftOptimised<S>>;
|
|
527
|
+
|
|
528
|
+
type _TrimLeftOptimised<S extends string> = S extends ` ${infer R}` ? _TrimLeftOptimised<R> : S;
|
|
529
|
+
|
|
530
|
+
type T2 = TrimLeftOptimised<NineHundredNinetyNineSpaces>;
|
|
531
|
+
//=> ''
|
|
532
|
+
```
|
|
533
|
+
*/
|
|
534
|
+
type IfNotAnyOrNever<T, IfNotAnyOrNever, IfAny = any, IfNever = never> = If<IsAny<T>, IfAny, If<IsNever<T>, IfNever, IfNotAnyOrNever>>;
|
|
535
|
+
/**
|
|
536
|
+
Indicates the value of `exactOptionalPropertyTypes` compiler option.
|
|
537
|
+
*/
|
|
538
|
+
type IsExactOptionalPropertyTypesEnabled = [(string | undefined)?] extends [string?] ? false : true;
|
|
539
|
+
//#endregion
|
|
540
|
+
//#region ../../node_modules/.pnpm/type-fest@5.5.0/node_modules/type-fest/source/internal/array.d.ts
|
|
541
|
+
/**
|
|
542
|
+
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.
|
|
543
|
+
|
|
544
|
+
@example
|
|
545
|
+
```
|
|
546
|
+
type A = CollapseRestElement<[string, string, ...number[]]>;
|
|
547
|
+
//=> [string, string, number]
|
|
548
|
+
|
|
549
|
+
type B = CollapseRestElement<[...string[], number, number]>;
|
|
550
|
+
//=> [string, number, number]
|
|
551
|
+
|
|
552
|
+
type C = CollapseRestElement<[string, string, ...Array<number | bigint>]>;
|
|
553
|
+
//=> [string, string, number | bigint]
|
|
554
|
+
|
|
555
|
+
type D = CollapseRestElement<[string, number]>;
|
|
556
|
+
//=> [string, number]
|
|
557
|
+
```
|
|
558
|
+
|
|
559
|
+
Note: Optional modifiers (`?`) are removed from elements unless the `exactOptionalPropertyTypes` compiler option is disabled. When disabled, there's an additional `| undefined` for optional elements.
|
|
560
|
+
|
|
561
|
+
@example
|
|
562
|
+
```
|
|
563
|
+
// `exactOptionalPropertyTypes` enabled
|
|
564
|
+
type A = CollapseRestElement<[string?, string?, ...number[]]>;
|
|
565
|
+
//=> [string, string, number]
|
|
566
|
+
|
|
567
|
+
// `exactOptionalPropertyTypes` disabled
|
|
568
|
+
type B = CollapseRestElement<[string?, string?, ...number[]]>;
|
|
569
|
+
//=> [string | undefined, string | undefined, number]
|
|
570
|
+
```
|
|
571
|
+
*/
|
|
572
|
+
type CollapseRestElement<TArray extends UnknownArray> = IfNotAnyOrNever<TArray, _CollapseRestElement<TArray>>;
|
|
573
|
+
type _CollapseRestElement<TArray extends UnknownArray, ForwardAccumulator extends UnknownArray = [], BackwardAccumulator extends UnknownArray = []> = TArray extends UnknownArray // For distributing `TArray`
|
|
574
|
+
? keyof TArray & `${number}` extends never // Enters this branch, if `TArray` is empty (e.g., []),
|
|
575
|
+
// or `TArray` contains no non-rest elements preceding the rest element (e.g., `[...string[]]` or `[...string[], string]`).
|
|
576
|
+
? TArray extends readonly [...infer Rest, infer Last] ? _CollapseRestElement<Rest, ForwardAccumulator, [Last, ...BackwardAccumulator]> // Accumulate elements that are present after the rest element.
|
|
577
|
+
: TArray extends readonly [] ? [...ForwardAccumulator, ...BackwardAccumulator] : [...ForwardAccumulator, TArray[number], ...BackwardAccumulator] // Add the rest element between the accumulated elements.
|
|
578
|
+
: 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.
|
|
579
|
+
: First], BackwardAccumulator> : never // Should never happen, since `[(infer First)?, ...infer Rest]` is a top-type for arrays.
|
|
580
|
+
: never; // Should never happen
|
|
581
|
+
//#endregion
|
|
582
|
+
//#region ../../node_modules/.pnpm/type-fest@5.5.0/node_modules/type-fest/source/internal/characters.d.ts
|
|
583
|
+
type Whitespace = '\u{9}' // '\t'
|
|
584
|
+
| '\u{A}' // '\n'
|
|
585
|
+
| '\u{B}' // '\v'
|
|
586
|
+
| '\u{C}' // '\f'
|
|
587
|
+
| '\u{D}' // '\r'
|
|
588
|
+
| '\u{20}' // ' '
|
|
589
|
+
| '\u{85}' | '\u{A0}' | '\u{1680}' | '\u{2000}' | '\u{2001}' | '\u{2002}' | '\u{2003}' | '\u{2004}' | '\u{2005}' | '\u{2006}' | '\u{2007}' | '\u{2008}' | '\u{2009}' | '\u{200A}' | '\u{2028}' | '\u{2029}' | '\u{202F}' | '\u{205F}' | '\u{3000}' | '\u{FEFF}';
|
|
590
|
+
type WordSeparators = '-' | '_' | Whitespace;
|
|
591
|
+
type AsciiPunctuation = '!' | '"' | '#' | '$' | '%' | '&' | '\'' | '(' | ')' | '*' | '+' | ',' | '-' | '.' | '/' | ':' | ';' | '<' | '=' | '>' | '?' | '@' | '[' | '\\' | ']' | '^' | '_' | '`' | '{' | '|' | '}' | '~';
|
|
592
|
+
//#endregion
|
|
593
|
+
//#region ../../node_modules/.pnpm/tagged-tag@1.0.0/node_modules/tagged-tag/index.d.ts
|
|
594
|
+
declare const tag: unique symbol;
|
|
595
|
+
//#endregion
|
|
596
|
+
//#region ../../node_modules/.pnpm/type-fest@5.5.0/node_modules/type-fest/source/tagged.d.ts
|
|
597
|
+
// eslint-disable-next-line type-fest/require-exported-types
|
|
598
|
+
type TagContainer<Token> = {
|
|
599
|
+
readonly [tag]: Token;
|
|
600
|
+
};
|
|
601
|
+
type Tag<Token extends PropertyKey, TagMetadata> = TagContainer<{ [K in Token]: TagMetadata }>;
|
|
602
|
+
/**
|
|
603
|
+
Attach a "tag" to an arbitrary type. This allows you to create distinct types, that aren't assignable to one another, for distinct concepts in your program that should not be interchangeable, even if their runtime values have the same type. (See examples.)
|
|
604
|
+
|
|
605
|
+
A type returned by `Tagged` can be passed to `Tagged` again, to create a type with multiple tags.
|
|
606
|
+
|
|
607
|
+
[Read more about tagged types.](https://medium.com/@KevinBGreene/surviving-the-typescript-ecosystem-branding-and-type-tagging-6cf6e516523d)
|
|
608
|
+
|
|
609
|
+
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.
|
|
610
|
+
|
|
611
|
+
A type `A` returned by `Tagged` is assignable to another type `B` returned by `Tagged` if and only if:
|
|
612
|
+
- the underlying (untagged) type of `A` is assignable to the underlying type of `B`;
|
|
613
|
+
- `A` contains at least all the tags `B` has;
|
|
614
|
+
- and the metadata type for each of `A`'s tags is assignable to the metadata type of `B`'s corresponding tag.
|
|
615
|
+
|
|
616
|
+
There have been several discussions about adding similar features to TypeScript. Unfortunately, nothing has (yet) moved forward:
|
|
617
|
+
- [Microsoft/TypeScript#202](https://github.com/microsoft/TypeScript/issues/202)
|
|
618
|
+
- [Microsoft/TypeScript#4895](https://github.com/microsoft/TypeScript/issues/4895)
|
|
619
|
+
- [Microsoft/TypeScript#33290](https://github.com/microsoft/TypeScript/pull/33290)
|
|
620
|
+
|
|
621
|
+
@example
|
|
622
|
+
```
|
|
623
|
+
import type {Tagged} from 'type-fest';
|
|
624
|
+
|
|
625
|
+
type AccountNumber = Tagged<number, 'AccountNumber'>;
|
|
626
|
+
type AccountBalance = Tagged<number, 'AccountBalance'>;
|
|
627
|
+
|
|
628
|
+
function createAccountNumber(): AccountNumber {
|
|
629
|
+
// As you can see, casting from a `number` (the underlying type being tagged) is allowed.
|
|
630
|
+
return 2 as AccountNumber;
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
declare function getMoneyForAccount(accountNumber: AccountNumber): AccountBalance;
|
|
634
|
+
|
|
635
|
+
// This will compile successfully.
|
|
636
|
+
getMoneyForAccount(createAccountNumber());
|
|
637
|
+
|
|
638
|
+
// But this won't, because it has to be explicitly passed as an `AccountNumber` type!
|
|
639
|
+
// Critically, you could not accidentally use an `AccountBalance` as an `AccountNumber`.
|
|
640
|
+
// @ts-expect-error
|
|
641
|
+
getMoneyForAccount(2);
|
|
642
|
+
|
|
643
|
+
// You can also use tagged values like their underlying, untagged type.
|
|
644
|
+
// I.e., this will compile successfully because an `AccountNumber` can be used as a regular `number`.
|
|
645
|
+
// In this sense, the underlying base type is not hidden, which differentiates tagged types from opaque types in other languages.
|
|
646
|
+
const accountNumber = createAccountNumber() + 2;
|
|
647
|
+
```
|
|
648
|
+
|
|
649
|
+
@example
|
|
650
|
+
```
|
|
651
|
+
import type {Tagged} from 'type-fest';
|
|
652
|
+
|
|
653
|
+
// You can apply multiple tags to a type by using `Tagged` repeatedly.
|
|
654
|
+
type Url = Tagged<string, 'URL'>;
|
|
655
|
+
type SpecialCacheKey = Tagged<Url, 'SpecialCacheKey'>;
|
|
656
|
+
|
|
657
|
+
// 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.
|
|
658
|
+
type SpecialCacheKey2 = Tagged<string, 'URL' | 'SpecialCacheKey'>;
|
|
659
|
+
```
|
|
660
|
+
|
|
661
|
+
@category Type
|
|
662
|
+
*/
|
|
663
|
+
type Tagged<Type, TagName extends PropertyKey, TagMetadata = never> = Type & Tag<TagName, TagMetadata>;
|
|
664
|
+
/**
|
|
665
|
+
Revert a tagged type back to its original type by removing all tags.
|
|
666
|
+
|
|
667
|
+
Why is this necessary?
|
|
668
|
+
|
|
669
|
+
1. Use a `Tagged` type as object keys
|
|
670
|
+
2. Prevent TS4058 error: "Return type of exported function has or is using name X from external module Y but cannot be named"
|
|
671
|
+
|
|
672
|
+
@example
|
|
673
|
+
```
|
|
674
|
+
import type {Tagged, UnwrapTagged} from 'type-fest';
|
|
675
|
+
|
|
676
|
+
type AccountType = Tagged<'SAVINGS' | 'CHECKING', 'AccountType'>;
|
|
677
|
+
|
|
678
|
+
const moneyByAccountType: Record<UnwrapTagged<AccountType>, number> = {
|
|
679
|
+
SAVINGS: 99,
|
|
680
|
+
CHECKING: 0.1,
|
|
681
|
+
};
|
|
682
|
+
|
|
683
|
+
// Without UnwrapTagged, the following expression would throw a type error.
|
|
684
|
+
const money = moneyByAccountType.SAVINGS; // TS error: Property 'SAVINGS' does not exist
|
|
685
|
+
|
|
686
|
+
// Attempting to pass a non-Tagged type to UnwrapTagged will raise a type error.
|
|
687
|
+
// @ts-expect-error
|
|
688
|
+
type WontWork = UnwrapTagged<string>;
|
|
689
|
+
```
|
|
690
|
+
|
|
691
|
+
@category Type
|
|
692
|
+
*/
|
|
693
|
+
type UnwrapTagged<TaggedType extends Tag<PropertyKey, any>> = RemoveAllTags<TaggedType>;
|
|
694
|
+
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;
|
|
695
|
+
/**
|
|
696
|
+
Note: The `Opaque` type is deprecated in favor of `Tagged`.
|
|
697
|
+
|
|
698
|
+
Attach a "tag" to an arbitrary type. This allows you to create distinct types, that aren't assignable to one another, for runtime values that would otherwise have the same type. (See examples.)
|
|
699
|
+
|
|
700
|
+
The generic type parameters can be anything.
|
|
701
|
+
|
|
702
|
+
Note that `Opaque` is somewhat of a misnomer here, in that, unlike [some alternative implementations](https://github.com/microsoft/TypeScript/issues/4895#issuecomment-425132582), the original, untagged type is not actually hidden. (E.g., functions that accept the untagged type can still be called with the "opaque" version -- but not vice-versa.)
|
|
703
|
+
|
|
704
|
+
Also note that this implementation is limited to a single tag. If you want to allow multiple tags, use `Tagged` instead.
|
|
705
|
+
|
|
706
|
+
[Read more about tagged types.](https://medium.com/@KevinBGreene/surviving-the-typescript-ecosystem-branding-and-type-tagging-6cf6e516523d)
|
|
707
|
+
|
|
708
|
+
There have been several discussions about adding similar features to TypeScript. Unfortunately, nothing has (yet) moved forward:
|
|
709
|
+
- [Microsoft/TypeScript#202](https://github.com/microsoft/TypeScript/issues/202)
|
|
710
|
+
- [Microsoft/TypeScript#15408](https://github.com/Microsoft/TypeScript/issues/15408)
|
|
711
|
+
- [Microsoft/TypeScript#15807](https://github.com/Microsoft/TypeScript/issues/15807)
|
|
712
|
+
|
|
713
|
+
@example
|
|
714
|
+
```
|
|
715
|
+
import type {Opaque} from 'type-fest';
|
|
716
|
+
|
|
717
|
+
type AccountNumber = Opaque<number, 'AccountNumber'>;
|
|
718
|
+
type AccountBalance = Opaque<number, 'AccountBalance'>;
|
|
719
|
+
|
|
720
|
+
// The `Token` parameter allows the compiler to differentiate between types, whereas "unknown" will not. For example, consider the following structures:
|
|
721
|
+
type ThingOne = Opaque<string>;
|
|
722
|
+
type ThingTwo = Opaque<string>;
|
|
723
|
+
|
|
724
|
+
// To the compiler, these types are allowed to be cast to each other as they have the same underlying type. They are both `string & { __opaque__: unknown }`.
|
|
725
|
+
// To avoid this behaviour, you would instead pass the "Token" parameter, like so.
|
|
726
|
+
type NewThingOne = Opaque<string, 'ThingOne'>;
|
|
727
|
+
type NewThingTwo = Opaque<string, 'ThingTwo'>;
|
|
728
|
+
|
|
729
|
+
// Now they're completely separate types, so the following will fail to compile.
|
|
730
|
+
function createNewThingOne(): NewThingOne {
|
|
731
|
+
// As you can see, casting from a string is still allowed. However, you may not cast NewThingOne to NewThingTwo, and vice versa.
|
|
732
|
+
return 'new thing one' as NewThingOne;
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
// This will fail to compile, as they are fundamentally different types.
|
|
736
|
+
// @ts-expect-error
|
|
737
|
+
const thingTwo = createNewThingOne() as NewThingTwo;
|
|
738
|
+
|
|
739
|
+
// Here's another example of opaque typing.
|
|
740
|
+
function createAccountNumber(): AccountNumber {
|
|
741
|
+
return 2 as AccountNumber;
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
declare function getMoneyForAccount(accountNumber: AccountNumber): AccountBalance;
|
|
745
|
+
|
|
746
|
+
// This will compile successfully.
|
|
747
|
+
getMoneyForAccount(createAccountNumber());
|
|
748
|
+
|
|
749
|
+
// But this won't, because it has to be explicitly passed as an `AccountNumber` type.
|
|
750
|
+
// @ts-expect-error
|
|
751
|
+
getMoneyForAccount(2);
|
|
752
|
+
|
|
753
|
+
// You can use opaque values like they aren't opaque too.
|
|
754
|
+
const accountNumber = createAccountNumber();
|
|
755
|
+
|
|
756
|
+
// This will compile successfully.
|
|
757
|
+
const newAccountNumber = accountNumber + 2;
|
|
758
|
+
|
|
759
|
+
// As a side note, you can (and should) use recursive types for your opaque types to make them stronger and hopefully easier to type.
|
|
760
|
+
type Person = {
|
|
761
|
+
id: Opaque<number, Person>;
|
|
762
|
+
name: string;
|
|
763
|
+
};
|
|
764
|
+
```
|
|
765
|
+
|
|
766
|
+
@category Type
|
|
767
|
+
@deprecated Use {@link Tagged} instead
|
|
768
|
+
*/
|
|
769
|
+
//#endregion
|
|
770
|
+
//#region ../../node_modules/.pnpm/type-fest@5.5.0/node_modules/type-fest/source/is-literal.d.ts
|
|
771
|
+
/**
|
|
772
|
+
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).
|
|
773
|
+
|
|
774
|
+
Useful for:
|
|
775
|
+
- providing strongly-typed string manipulation functions
|
|
776
|
+
- constraining strings to be a string literal
|
|
777
|
+
- type utilities, such as when constructing parsers and ASTs
|
|
778
|
+
|
|
779
|
+
The implementation of this type is inspired by the trick mentioned in this [StackOverflow answer](https://stackoverflow.com/a/68261113/420747).
|
|
780
|
+
|
|
781
|
+
@example
|
|
782
|
+
```
|
|
783
|
+
import type {IsStringLiteral} from 'type-fest';
|
|
784
|
+
|
|
785
|
+
type CapitalizedString<T extends string> = IsStringLiteral<T> extends true ? Capitalize<T> : string;
|
|
786
|
+
|
|
787
|
+
// https://github.com/yankeeinlondon/native-dash/blob/master/src/capitalize.ts
|
|
788
|
+
function capitalize<T extends Readonly<string>>(input: T): CapitalizedString<T> {
|
|
789
|
+
return (input.slice(0, 1).toUpperCase() + input.slice(1)) as CapitalizedString<T>;
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
const output = capitalize('hello, world!');
|
|
793
|
+
//=> 'Hello, world!'
|
|
794
|
+
```
|
|
795
|
+
|
|
796
|
+
@example
|
|
797
|
+
```
|
|
798
|
+
// String types with infinite set of possible values return `false`.
|
|
799
|
+
|
|
800
|
+
import type {IsStringLiteral} from 'type-fest';
|
|
801
|
+
|
|
802
|
+
type AllUppercaseStrings = IsStringLiteral<Uppercase<string>>;
|
|
803
|
+
//=> false
|
|
804
|
+
|
|
805
|
+
type StringsStartingWithOn = IsStringLiteral<`on${string}`>;
|
|
806
|
+
//=> false
|
|
807
|
+
|
|
808
|
+
// This behaviour is particularly useful in string manipulation utilities, as infinite string types often require separate handling.
|
|
809
|
+
|
|
810
|
+
type Length<S extends string, Counter extends never[] = []> =
|
|
811
|
+
IsStringLiteral<S> extends false
|
|
812
|
+
? number // return `number` for infinite string types
|
|
813
|
+
: S extends `${string}${infer Tail}`
|
|
814
|
+
? Length<Tail, [...Counter, never]>
|
|
815
|
+
: Counter['length'];
|
|
816
|
+
|
|
817
|
+
type L1 = Length<Lowercase<string>>;
|
|
818
|
+
//=> number
|
|
819
|
+
|
|
820
|
+
type L2 = Length<`${number}`>;
|
|
821
|
+
//=> number
|
|
822
|
+
```
|
|
823
|
+
|
|
824
|
+
@category Type Guard
|
|
825
|
+
@category Utilities
|
|
826
|
+
*/
|
|
827
|
+
type IsStringLiteral<S> = IfNotAnyOrNever<S, _IsStringLiteral<CollapseLiterals<S extends TagContainer<any> ? UnwrapTagged<S> : S>>, false, false>;
|
|
828
|
+
type _IsStringLiteral<S> = // If `T` is an infinite string type (e.g., `on${string}`), `Record<T, never>` produces an index signature,
|
|
829
|
+
// and since `{}` extends index signatures, the result becomes `false`.
|
|
830
|
+
S extends string ? {} extends Record<S, never> ? false : true : false;
|
|
831
|
+
//#endregion
|
|
832
|
+
//#region ../../node_modules/.pnpm/type-fest@5.5.0/node_modules/type-fest/source/trim.d.ts
|
|
833
|
+
/**
|
|
834
|
+
Remove spaces from the left side.
|
|
835
|
+
*/
|
|
836
|
+
type TrimLeft<V extends string> = V extends `${Whitespace}${infer R}` ? TrimLeft<R> : V;
|
|
837
|
+
/**
|
|
838
|
+
Remove spaces from the right side.
|
|
839
|
+
*/
|
|
840
|
+
type TrimRight<V extends string> = V extends `${infer R}${Whitespace}` ? TrimRight<R> : V;
|
|
384
841
|
/**
|
|
385
|
-
|
|
842
|
+
Remove leading and trailing spaces from a string.
|
|
843
|
+
|
|
844
|
+
@example
|
|
845
|
+
```
|
|
846
|
+
import type {Trim} from 'type-fest';
|
|
847
|
+
|
|
848
|
+
type Example = Trim<' foo '>;
|
|
849
|
+
//=> 'foo'
|
|
850
|
+
```
|
|
851
|
+
|
|
852
|
+
@category String
|
|
853
|
+
@category Template literal
|
|
386
854
|
*/
|
|
387
|
-
type
|
|
855
|
+
type Trim<V extends string> = TrimLeft<TrimRight<V>>;
|
|
856
|
+
//#endregion
|
|
857
|
+
//#region ../../node_modules/.pnpm/type-fest@5.5.0/node_modules/type-fest/source/internal/string.d.ts
|
|
388
858
|
/**
|
|
389
|
-
|
|
859
|
+
Returns a boolean for whether the given string `S` starts with the given string `SearchString`.
|
|
860
|
+
|
|
861
|
+
@example
|
|
862
|
+
```
|
|
863
|
+
type A = StartsWith<'abcde', 'abc'>;
|
|
864
|
+
//=> true
|
|
865
|
+
|
|
866
|
+
type B = StartsWith<'abcde', 'bc'>;
|
|
867
|
+
//=> false
|
|
868
|
+
|
|
869
|
+
type C = StartsWith<string, 'bc'>;
|
|
870
|
+
//=> never
|
|
871
|
+
|
|
872
|
+
type D = StartsWith<'abcde', string>;
|
|
873
|
+
//=> never
|
|
874
|
+
```
|
|
390
875
|
|
|
391
|
-
|
|
876
|
+
@category String
|
|
877
|
+
@category Template literal
|
|
878
|
+
*/
|
|
879
|
+
type StartsWith<S extends string, SearchString extends string> = string extends S | SearchString ? never : S extends `${SearchString}${infer T}` ? true : false;
|
|
880
|
+
/**
|
|
881
|
+
Returns a boolean for whether the string is numeric.
|
|
392
882
|
|
|
393
|
-
|
|
394
|
-
@see https://github.com/microsoft/TypeScript/issues/29732
|
|
883
|
+
This type is a workaround for [Microsoft/TypeScript#46109](https://github.com/microsoft/TypeScript/issues/46109#issuecomment-930307987).
|
|
395
884
|
*/
|
|
396
|
-
type
|
|
397
|
-
(...arguments_: infer A): unknown;
|
|
398
|
-
(...arguments_: infer B): unknown;
|
|
399
|
-
} ? B extends A ? A extends B ? false : true : true : false;
|
|
885
|
+
type IsNumeric<T extends string> = T extends `${number}` ? Trim<T> extends T ? true : false : false;
|
|
400
886
|
//#endregion
|
|
401
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
887
|
+
//#region ../../node_modules/.pnpm/type-fest@5.5.0/node_modules/type-fest/source/simplify.d.ts
|
|
402
888
|
/**
|
|
403
889
|
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.
|
|
404
890
|
|
|
@@ -459,7 +945,7 @@ fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface`
|
|
|
459
945
|
*/
|
|
460
946
|
type Simplify<T> = { [KeyType in keyof T]: T[KeyType] } & {};
|
|
461
947
|
//#endregion
|
|
462
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
948
|
+
//#region ../../node_modules/.pnpm/type-fest@5.5.0/node_modules/type-fest/source/is-equal.d.ts
|
|
463
949
|
/**
|
|
464
950
|
Returns a boolean for whether the two given types are equal.
|
|
465
951
|
|
|
@@ -490,7 +976,7 @@ type IsEqual<A, B> = [A] extends [B] ? [B] extends [A] ? _IsEqual<A, B> : false
|
|
|
490
976
|
// This version fails the `equalWrappedTupleIntersectionToBeNeverAndNeverExpanded` test in `test-d/is-equal.ts`.
|
|
491
977
|
type _IsEqual<A, B> = (<G>() => G extends A & G | G ? 1 : 2) extends (<G>() => G extends B & G | G ? 1 : 2) ? true : false;
|
|
492
978
|
//#endregion
|
|
493
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
979
|
+
//#region ../../node_modules/.pnpm/type-fest@5.5.0/node_modules/type-fest/source/omit-index-signature.d.ts
|
|
494
980
|
/**
|
|
495
981
|
Omit any index signatures from the given object type, leaving only explicitly defined properties.
|
|
496
982
|
|
|
@@ -584,7 +1070,7 @@ type ExampleWithoutIndexSignatures = OmitIndexSignature<Example>;
|
|
|
584
1070
|
*/
|
|
585
1071
|
type OmitIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? never : KeyType]: ObjectType[KeyType] };
|
|
586
1072
|
//#endregion
|
|
587
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
1073
|
+
//#region ../../node_modules/.pnpm/type-fest@5.5.0/node_modules/type-fest/source/pick-index-signature.d.ts
|
|
588
1074
|
/**
|
|
589
1075
|
Pick only index signatures from the given object type, leaving out all explicitly defined properties.
|
|
590
1076
|
|
|
@@ -632,12 +1118,37 @@ type ExampleIndexSignature = PickIndexSignature<Example>;
|
|
|
632
1118
|
*/
|
|
633
1119
|
type PickIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? KeyType : never]: ObjectType[KeyType] };
|
|
634
1120
|
//#endregion
|
|
635
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
1121
|
+
//#region ../../node_modules/.pnpm/type-fest@5.5.0/node_modules/type-fest/source/merge.d.ts
|
|
636
1122
|
// Merges two objects without worrying about index signatures.
|
|
637
1123
|
type SimpleMerge<Destination, Source> = Simplify<{ [Key in keyof Destination as Key extends keyof Source ? never : Key]: Destination[Key] } & Source>;
|
|
638
1124
|
/**
|
|
639
1125
|
Merge two types into a new type. Keys of the second type overrides keys of the first type.
|
|
640
1126
|
|
|
1127
|
+
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`.
|
|
1128
|
+
|
|
1129
|
+
@example
|
|
1130
|
+
```
|
|
1131
|
+
import type {Merge} from 'type-fest';
|
|
1132
|
+
|
|
1133
|
+
type Foo = {
|
|
1134
|
+
a: string;
|
|
1135
|
+
b: number;
|
|
1136
|
+
};
|
|
1137
|
+
|
|
1138
|
+
type Bar = {
|
|
1139
|
+
a: number; // Conflicts with Foo['a']
|
|
1140
|
+
c: boolean;
|
|
1141
|
+
};
|
|
1142
|
+
|
|
1143
|
+
// With `&`, `a` becomes `string & number` which is `never`. Not what you want.
|
|
1144
|
+
type WithIntersection = (Foo & Bar)['a'];
|
|
1145
|
+
//=> never
|
|
1146
|
+
|
|
1147
|
+
// With `Merge`, `a` is cleanly overridden to `number`.
|
|
1148
|
+
type WithMerge = Merge<Foo, Bar>['a'];
|
|
1149
|
+
//=> number
|
|
1150
|
+
```
|
|
1151
|
+
|
|
641
1152
|
@example
|
|
642
1153
|
```
|
|
643
1154
|
import type {Merge} from 'type-fest';
|
|
@@ -679,7 +1190,7 @@ type Merge<Destination, Source> = Destination extends unknown // For distributin
|
|
|
679
1190
|
// Should never happen
|
|
680
1191
|
type _Merge<Destination, Source> = Simplify<SimpleMerge<PickIndexSignature<Destination>, PickIndexSignature<Source>> & SimpleMerge<OmitIndexSignature<Destination>, OmitIndexSignature<Source>>>;
|
|
681
1192
|
//#endregion
|
|
682
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
1193
|
+
//#region ../../node_modules/.pnpm/type-fest@5.5.0/node_modules/type-fest/source/internal/object.d.ts
|
|
683
1194
|
/**
|
|
684
1195
|
Merges user specified options with default options.
|
|
685
1196
|
|
|
@@ -733,14 +1244,362 @@ type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOp
|
|
|
733
1244
|
```
|
|
734
1245
|
*/
|
|
735
1246
|
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>>>>;
|
|
736
|
-
|
|
737
|
-
//#region ../../node_modules/.pnpm/type-fest@5.4.3/node_modules/type-fest/source/except.d.ts
|
|
1247
|
+
// `& Required<Options>` ensures that `ApplyDefaultOptions<SomeOption, ...>` is always assignable to `Required<SomeOption>`
|
|
738
1248
|
/**
|
|
739
|
-
|
|
1249
|
+
Collapses literal types in a union into their corresponding primitive types, when possible. For example, `CollapseLiterals<'foo' | 'bar' | (string & {})>` returns `string`.
|
|
740
1250
|
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
1251
|
+
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>`.
|
|
1252
|
+
|
|
1253
|
+
Use-case: For collapsing unions created using {@link LiteralUnion}.
|
|
1254
|
+
|
|
1255
|
+
@example
|
|
1256
|
+
```
|
|
1257
|
+
import type {LiteralUnion} from 'type-fest';
|
|
1258
|
+
|
|
1259
|
+
type A = CollapseLiterals<'foo' | 'bar' | (string & {})>;
|
|
1260
|
+
//=> string
|
|
1261
|
+
|
|
1262
|
+
type B = CollapseLiterals<LiteralUnion<1 | 2 | 3, number>>;
|
|
1263
|
+
//=> number
|
|
1264
|
+
|
|
1265
|
+
type C = CollapseLiterals<LiteralUnion<'onClick' | 'onChange', `on${string}`>>;
|
|
1266
|
+
//=> `on${string}`
|
|
1267
|
+
|
|
1268
|
+
type D = CollapseLiterals<'click' | 'change' | (`on${string}` & {})>;
|
|
1269
|
+
//=> 'click' | 'change' | `on${string}`
|
|
1270
|
+
|
|
1271
|
+
type E = CollapseLiterals<LiteralUnion<'foo' | 'bar', string> | null | undefined>;
|
|
1272
|
+
//=> string | null | undefined
|
|
1273
|
+
```
|
|
1274
|
+
*/
|
|
1275
|
+
type CollapseLiterals<T> = {} extends T ? T : T extends infer U & {} ? U : T;
|
|
1276
|
+
//#endregion
|
|
1277
|
+
//#region ../../node_modules/.pnpm/type-fest@5.5.0/node_modules/type-fest/source/some-extend.d.ts
|
|
1278
|
+
/**
|
|
1279
|
+
@see {@link SomeExtend}
|
|
1280
|
+
*/
|
|
1281
|
+
type SomeExtendOptions = {
|
|
1282
|
+
/**
|
|
1283
|
+
Consider `never` elements to match the target type only if the target type itself is `never` (or `any`).
|
|
1284
|
+
- 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`).
|
|
1285
|
+
- When set to `false`, `never` is treated as a bottom type, and behaves as it normally would.
|
|
1286
|
+
@default true
|
|
1287
|
+
@example
|
|
1288
|
+
```
|
|
1289
|
+
import type {SomeExtend} from 'type-fest';
|
|
1290
|
+
type A = SomeExtend<[1, 2, never], string, {strictNever: true}>;
|
|
1291
|
+
//=> false
|
|
1292
|
+
type B = SomeExtend<[1, 2, never], string, {strictNever: false}>;
|
|
1293
|
+
//=> true
|
|
1294
|
+
type C = SomeExtend<[1, never], never, {strictNever: true}>;
|
|
1295
|
+
//=> true
|
|
1296
|
+
type D = SomeExtend<[1, never], never, {strictNever: false}>;
|
|
1297
|
+
//=> true
|
|
1298
|
+
type E = SomeExtend<[never], any, {strictNever: true}>;
|
|
1299
|
+
//=> true
|
|
1300
|
+
type F = SomeExtend<[never], any, {strictNever: false}>;
|
|
1301
|
+
//=> true
|
|
1302
|
+
```
|
|
1303
|
+
*/
|
|
1304
|
+
strictNever?: boolean;
|
|
1305
|
+
};
|
|
1306
|
+
type DefaultSomeExtendOptions = {
|
|
1307
|
+
strictNever: true;
|
|
1308
|
+
};
|
|
1309
|
+
/**
|
|
1310
|
+
Returns a boolean for whether some element in an array type extends another type.
|
|
1311
|
+
|
|
1312
|
+
@example
|
|
1313
|
+
```
|
|
1314
|
+
import type {SomeExtend} from 'type-fest';
|
|
1315
|
+
|
|
1316
|
+
type A = SomeExtend<['1', '2', 3], number>;
|
|
1317
|
+
//=> true
|
|
1318
|
+
|
|
1319
|
+
type B = SomeExtend<[1, 2, 3], string>;
|
|
1320
|
+
//=> false
|
|
1321
|
+
|
|
1322
|
+
type C = SomeExtend<[string, number | string], number>;
|
|
1323
|
+
//=> boolean
|
|
1324
|
+
|
|
1325
|
+
type D = SomeExtend<[true, boolean, true], false>;
|
|
1326
|
+
//=> boolean
|
|
1327
|
+
```
|
|
1328
|
+
|
|
1329
|
+
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.
|
|
1330
|
+
|
|
1331
|
+
```
|
|
1332
|
+
// @exactOptionalPropertyTypes: true
|
|
1333
|
+
import type {SomeExtend} from 'type-fest';
|
|
1334
|
+
|
|
1335
|
+
type A = SomeExtend<[1?, 2?, '3'?], string>;
|
|
1336
|
+
//=> true
|
|
1337
|
+
```
|
|
1338
|
+
|
|
1339
|
+
```
|
|
1340
|
+
// @exactOptionalPropertyTypes: false
|
|
1341
|
+
import type {SomeExtend} from 'type-fest';
|
|
1342
|
+
|
|
1343
|
+
type A = SomeExtend<[1?, 2?, '3'?], string>;
|
|
1344
|
+
//=> boolean
|
|
1345
|
+
|
|
1346
|
+
type B = SomeExtend<[1?, 2?, '3'?], string | undefined>;
|
|
1347
|
+
//=> true
|
|
1348
|
+
```
|
|
1349
|
+
|
|
1350
|
+
@see {@link SomeExtendOptions}
|
|
1351
|
+
|
|
1352
|
+
@category Utilities
|
|
1353
|
+
@category Array
|
|
1354
|
+
*/
|
|
1355
|
+
type SomeExtend<TArray extends UnknownArray, Type, Options extends SomeExtendOptions = {}> = _SomeExtend<CollapseRestElement<TArray>, Type, ApplyDefaultOptions<SomeExtendOptions, DefaultSomeExtendOptions, Options>>;
|
|
1356
|
+
type _SomeExtend<TArray extends UnknownArray, Type, Options extends Required<SomeExtendOptions>> = IfNotAnyOrNever<TArray, TArray extends readonly [infer First, ...infer Rest] ? IsNever<First> extends true ? Or<Or<IsNever<Type>, IsAny<Type>>, Not<Options['strictNever']>> extends true // If target `Type` is also `never`, or is `any`, or `strictNever` is disabled, return `true`.
|
|
1357
|
+
? true : _SomeExtend<Rest, Type, Options> : First extends Type ? true : _SomeExtend<Rest, Type, Options> : false, false, false>;
|
|
1358
|
+
//#endregion
|
|
1359
|
+
//#region ../../node_modules/.pnpm/type-fest@5.5.0/node_modules/type-fest/source/or-all.d.ts
|
|
1360
|
+
/**
|
|
1361
|
+
Returns a boolean for whether any of the given elements is `true`.
|
|
1362
|
+
|
|
1363
|
+
Use-cases:
|
|
1364
|
+
- Check if at least one condition in a list of booleans is met.
|
|
1365
|
+
|
|
1366
|
+
@example
|
|
1367
|
+
```
|
|
1368
|
+
import type {OrAll} from 'type-fest';
|
|
1369
|
+
|
|
1370
|
+
type FFT = OrAll<[false, false, true]>;
|
|
1371
|
+
//=> true
|
|
1372
|
+
|
|
1373
|
+
type FFF = OrAll<[false, false, false]>;
|
|
1374
|
+
//=> false
|
|
1375
|
+
```
|
|
1376
|
+
|
|
1377
|
+
Note: When `boolean` is passed as an element, it is distributed into separate cases, and the final result is a union of those cases.
|
|
1378
|
+
For example, `OrAll<[false, boolean]>` expands to `OrAll<[false, true]> | OrAll<[false, false]>`, which simplifies to `true | false` (i.e., `boolean`).
|
|
1379
|
+
|
|
1380
|
+
@example
|
|
1381
|
+
```
|
|
1382
|
+
import type {OrAll} from 'type-fest';
|
|
1383
|
+
|
|
1384
|
+
type A = OrAll<[false, boolean]>;
|
|
1385
|
+
//=> boolean
|
|
1386
|
+
|
|
1387
|
+
type B = OrAll<[true, boolean]>;
|
|
1388
|
+
//=> true
|
|
1389
|
+
```
|
|
1390
|
+
|
|
1391
|
+
Note: If `never` is passed as an element, it is treated as `false` and the result is computed accordingly.
|
|
1392
|
+
|
|
1393
|
+
@example
|
|
1394
|
+
```
|
|
1395
|
+
import type {OrAll} from 'type-fest';
|
|
1396
|
+
|
|
1397
|
+
type A = OrAll<[never, never, true]>;
|
|
1398
|
+
//=> true
|
|
1399
|
+
|
|
1400
|
+
type B = OrAll<[never, never, false]>;
|
|
1401
|
+
//=> false
|
|
1402
|
+
|
|
1403
|
+
type C = OrAll<[never, never, never]>;
|
|
1404
|
+
//=> false
|
|
1405
|
+
|
|
1406
|
+
type D = OrAll<[never, never, boolean]>;
|
|
1407
|
+
//=> boolean
|
|
1408
|
+
```
|
|
1409
|
+
|
|
1410
|
+
Note: If `any` is passed as an element, it is treated as `boolean` and the result is computed accordingly.
|
|
1411
|
+
|
|
1412
|
+
@example
|
|
1413
|
+
```
|
|
1414
|
+
import type {OrAll} from 'type-fest';
|
|
1415
|
+
|
|
1416
|
+
type A = OrAll<[false, any]>;
|
|
1417
|
+
//=> boolean
|
|
1418
|
+
|
|
1419
|
+
type B = OrAll<[true, any]>;
|
|
1420
|
+
//=> true
|
|
1421
|
+
```
|
|
1422
|
+
|
|
1423
|
+
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.).
|
|
1424
|
+
|
|
1425
|
+
@see {@link Or}
|
|
1426
|
+
@see {@link AndAll}
|
|
1427
|
+
*/
|
|
1428
|
+
type OrAll<T extends readonly boolean[]> = SomeExtend<T, true>;
|
|
1429
|
+
//#endregion
|
|
1430
|
+
//#region ../../node_modules/.pnpm/type-fest@5.5.0/node_modules/type-fest/source/or.d.ts
|
|
1431
|
+
/**
|
|
1432
|
+
Returns a boolean for whether either of two given types is true.
|
|
1433
|
+
|
|
1434
|
+
Use-case: Constructing complex conditional types where at least one condition must be satisfied.
|
|
1435
|
+
|
|
1436
|
+
@example
|
|
1437
|
+
```
|
|
1438
|
+
import type {Or} from 'type-fest';
|
|
1439
|
+
|
|
1440
|
+
type TT = Or<true, true>;
|
|
1441
|
+
//=> true
|
|
1442
|
+
|
|
1443
|
+
type TF = Or<true, false>;
|
|
1444
|
+
//=> true
|
|
1445
|
+
|
|
1446
|
+
type FT = Or<false, true>;
|
|
1447
|
+
//=> true
|
|
1448
|
+
|
|
1449
|
+
type FF = Or<false, false>;
|
|
1450
|
+
//=> false
|
|
1451
|
+
```
|
|
1452
|
+
|
|
1453
|
+
Note: When `boolean` is passed as an argument, it is distributed into separate cases, and the final result is a union of those cases.
|
|
1454
|
+
For example, `Or<false, boolean>` expands to `Or<false, true> | Or<false, false>`, which simplifies to `true | false` (i.e., `boolean`).
|
|
1455
|
+
|
|
1456
|
+
@example
|
|
1457
|
+
```
|
|
1458
|
+
import type {Or} from 'type-fest';
|
|
1459
|
+
|
|
1460
|
+
type A = Or<false, boolean>;
|
|
1461
|
+
//=> boolean
|
|
1462
|
+
|
|
1463
|
+
type B = Or<boolean, false>;
|
|
1464
|
+
//=> boolean
|
|
1465
|
+
|
|
1466
|
+
type C = Or<true, boolean>;
|
|
1467
|
+
//=> true
|
|
1468
|
+
|
|
1469
|
+
type D = Or<boolean, true>;
|
|
1470
|
+
//=> true
|
|
1471
|
+
|
|
1472
|
+
type E = Or<boolean, boolean>;
|
|
1473
|
+
//=> boolean
|
|
1474
|
+
```
|
|
1475
|
+
|
|
1476
|
+
Note: If `never` is passed as an argument, it is treated as `false` and the result is computed accordingly.
|
|
1477
|
+
|
|
1478
|
+
@example
|
|
1479
|
+
```
|
|
1480
|
+
import type {Or} from 'type-fest';
|
|
1481
|
+
|
|
1482
|
+
type A = Or<true, never>;
|
|
1483
|
+
//=> true
|
|
1484
|
+
|
|
1485
|
+
type B = Or<never, true>;
|
|
1486
|
+
//=> true
|
|
1487
|
+
|
|
1488
|
+
type C = Or<false, never>;
|
|
1489
|
+
//=> false
|
|
1490
|
+
|
|
1491
|
+
type D = Or<never, false>;
|
|
1492
|
+
//=> false
|
|
1493
|
+
|
|
1494
|
+
type E = Or<boolean, never>;
|
|
1495
|
+
//=> boolean
|
|
1496
|
+
|
|
1497
|
+
type F = Or<never, boolean>;
|
|
1498
|
+
//=> boolean
|
|
1499
|
+
|
|
1500
|
+
type G = Or<never, never>;
|
|
1501
|
+
//=> false
|
|
1502
|
+
```
|
|
1503
|
+
|
|
1504
|
+
@see {@link OrAll}
|
|
1505
|
+
@see {@link And}
|
|
1506
|
+
@see {@link Xor}
|
|
1507
|
+
*/
|
|
1508
|
+
type Or<A extends boolean, B extends boolean> = OrAll<[A, B]>;
|
|
1509
|
+
//#endregion
|
|
1510
|
+
//#region ../../node_modules/.pnpm/type-fest@5.5.0/node_modules/type-fest/source/all-extend.d.ts
|
|
1511
|
+
/**
|
|
1512
|
+
@see {@link AllExtend}
|
|
1513
|
+
*/
|
|
1514
|
+
type AllExtendOptions = {
|
|
1515
|
+
/**
|
|
1516
|
+
Consider `never` elements to match the target type only if the target type itself is `never` (or `any`).
|
|
1517
|
+
- 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`).
|
|
1518
|
+
- When set to `false`, `never` is treated as a bottom type, and behaves as it normally would.
|
|
1519
|
+
@default true
|
|
1520
|
+
@example
|
|
1521
|
+
```
|
|
1522
|
+
import type {AllExtend} from 'type-fest';
|
|
1523
|
+
type A = AllExtend<[1, 2, never], number, {strictNever: true}>;
|
|
1524
|
+
//=> false
|
|
1525
|
+
type B = AllExtend<[1, 2, never], number, {strictNever: false}>;
|
|
1526
|
+
//=> true
|
|
1527
|
+
type C = AllExtend<[never, never], never, {strictNever: true}>;
|
|
1528
|
+
//=> true
|
|
1529
|
+
type D = AllExtend<[never, never], never, {strictNever: false}>;
|
|
1530
|
+
//=> true
|
|
1531
|
+
type E = AllExtend<['a', 'b', never], any, {strictNever: true}>;
|
|
1532
|
+
//=> true
|
|
1533
|
+
type F = AllExtend<['a', 'b', never], any, {strictNever: false}>;
|
|
1534
|
+
//=> true
|
|
1535
|
+
type G = AllExtend<[never, 1], never, {strictNever: true}>;
|
|
1536
|
+
//=> false
|
|
1537
|
+
type H = AllExtend<[never, 1], never, {strictNever: false}>;
|
|
1538
|
+
//=> false
|
|
1539
|
+
```
|
|
1540
|
+
*/
|
|
1541
|
+
strictNever?: boolean;
|
|
1542
|
+
};
|
|
1543
|
+
type DefaultAllExtendOptions = {
|
|
1544
|
+
strictNever: true;
|
|
1545
|
+
};
|
|
1546
|
+
/**
|
|
1547
|
+
Returns a boolean for whether every element in an array type extends another type.
|
|
1548
|
+
|
|
1549
|
+
@example
|
|
1550
|
+
```
|
|
1551
|
+
import type {AllExtend} from 'type-fest';
|
|
1552
|
+
|
|
1553
|
+
type A = AllExtend<[1, 2, 3], number>;
|
|
1554
|
+
//=> true
|
|
1555
|
+
|
|
1556
|
+
type B = AllExtend<[1, 2, '3'], number>;
|
|
1557
|
+
//=> false
|
|
1558
|
+
|
|
1559
|
+
type C = AllExtend<[number, number | string], number>;
|
|
1560
|
+
//=> boolean
|
|
1561
|
+
|
|
1562
|
+
type D = AllExtend<[true, boolean, true], true>;
|
|
1563
|
+
//=> boolean
|
|
1564
|
+
```
|
|
1565
|
+
|
|
1566
|
+
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.
|
|
1567
|
+
|
|
1568
|
+
```
|
|
1569
|
+
// @exactOptionalPropertyTypes: true
|
|
1570
|
+
import type {AllExtend} from 'type-fest';
|
|
1571
|
+
|
|
1572
|
+
type A = AllExtend<[1?, 2?, 3?], number>;
|
|
1573
|
+
//=> true
|
|
1574
|
+
```
|
|
1575
|
+
|
|
1576
|
+
```
|
|
1577
|
+
// @exactOptionalPropertyTypes: false
|
|
1578
|
+
import type {AllExtend} from 'type-fest';
|
|
1579
|
+
|
|
1580
|
+
type A = AllExtend<[1?, 2?, 3?], number>;
|
|
1581
|
+
//=> boolean
|
|
1582
|
+
|
|
1583
|
+
type B = AllExtend<[1?, 2?, 3?], number | undefined>;
|
|
1584
|
+
//=> true
|
|
1585
|
+
```
|
|
1586
|
+
|
|
1587
|
+
@see {@link AllExtendOptions}
|
|
1588
|
+
|
|
1589
|
+
@category Utilities
|
|
1590
|
+
@category Array
|
|
1591
|
+
*/
|
|
1592
|
+
type AllExtend<TArray extends UnknownArray, Type, Options extends AllExtendOptions = {}> = _AllExtend<CollapseRestElement<TArray>, Type, ApplyDefaultOptions<AllExtendOptions, DefaultAllExtendOptions, Options>>;
|
|
1593
|
+
type _AllExtend<TArray extends UnknownArray, Type, Options extends Required<AllExtendOptions>> = IfNotAnyOrNever<TArray, TArray extends readonly [infer First, ...infer Rest] ? IsNever<First> extends true ? Or<Or<IsNever<Type>, IsAny<Type>>, Not<Options['strictNever']>> extends true // If target `Type` is also `never`, or is `any`, or `strictNever` is disabled, recurse further.
|
|
1594
|
+
? _AllExtend<Rest, Type, Options> : false : First extends Type ? _AllExtend<Rest, Type, Options> : false : true, false, false>;
|
|
1595
|
+
//#endregion
|
|
1596
|
+
//#region ../../node_modules/.pnpm/type-fest@5.5.0/node_modules/type-fest/source/except.d.ts
|
|
1597
|
+
/**
|
|
1598
|
+
Filter out keys from an object.
|
|
1599
|
+
|
|
1600
|
+
Returns `never` if `Exclude` is strictly equal to `Key`.
|
|
1601
|
+
Returns `never` if `Key` extends `Exclude`.
|
|
1602
|
+
Returns `Key` otherwise.
|
|
744
1603
|
|
|
745
1604
|
@example
|
|
746
1605
|
```
|
|
@@ -832,105 +1691,324 @@ type PostPayloadFixed = Except<UserData, 'email'>;
|
|
|
832
1691
|
type Except<ObjectType, KeysType extends keyof ObjectType, Options extends ExceptOptions = {}> = _Except<ObjectType, KeysType, ApplyDefaultOptions<ExceptOptions, DefaultExceptOptions, Options>>;
|
|
833
1692
|
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>> : {});
|
|
834
1693
|
//#endregion
|
|
835
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
1694
|
+
//#region ../../node_modules/.pnpm/type-fest@5.5.0/node_modules/type-fest/source/is-lowercase.d.ts
|
|
836
1695
|
/**
|
|
837
|
-
|
|
1696
|
+
Returns a boolean for whether the given string literal is lowercase.
|
|
838
1697
|
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
1698
|
+
@example
|
|
1699
|
+
```
|
|
1700
|
+
import type {IsLowercase} from 'type-fest';
|
|
1701
|
+
|
|
1702
|
+
type A = IsLowercase<'abc'>;
|
|
1703
|
+
//=> true
|
|
1704
|
+
|
|
1705
|
+
type B = IsLowercase<'Abc'>;
|
|
1706
|
+
//=> false
|
|
1707
|
+
|
|
1708
|
+
type C = IsLowercase<string>;
|
|
1709
|
+
//=> boolean
|
|
1710
|
+
```
|
|
1711
|
+
*/
|
|
1712
|
+
type IsLowercase<S extends string> = AllExtend<_IsLowercase<S>, true>;
|
|
1713
|
+
/**
|
|
1714
|
+
Loops through each part in the string and returns a boolean array indicating whether each part is lowercase.
|
|
1715
|
+
*/
|
|
1716
|
+
type _IsLowercase<S extends string, Accumulator extends boolean[] = []> = S extends `${infer First}${infer Rest}` ? _IsLowercase<Rest, [...Accumulator, IsLowercaseHelper<First>]> : [...Accumulator, IsLowercaseHelper<S>];
|
|
1717
|
+
/**
|
|
1718
|
+
Returns a boolean for whether an individual part of the string is lowercase.
|
|
1719
|
+
*/
|
|
1720
|
+
type IsLowercaseHelper<S extends string> = S extends Lowercase<string> ? true : S extends Uppercase<string> | Capitalize<string> | `${string}${Uppercase<string>}${string}` ? false : boolean;
|
|
1721
|
+
//#endregion
|
|
1722
|
+
//#region ../../node_modules/.pnpm/type-fest@5.5.0/node_modules/type-fest/source/is-uppercase.d.ts
|
|
1723
|
+
/**
|
|
1724
|
+
Returns a boolean for whether the given string literal is uppercase.
|
|
842
1725
|
|
|
843
1726
|
@example
|
|
844
1727
|
```
|
|
845
|
-
import type {
|
|
1728
|
+
import type {IsUppercase} from 'type-fest';
|
|
846
1729
|
|
|
847
|
-
type
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
1730
|
+
type A = IsUppercase<'ABC'>;
|
|
1731
|
+
//=> true
|
|
1732
|
+
|
|
1733
|
+
type B = IsUppercase<'Abc'>;
|
|
1734
|
+
//=> false
|
|
1735
|
+
|
|
1736
|
+
type C = IsUppercase<string>;
|
|
1737
|
+
//=> boolean
|
|
1738
|
+
```
|
|
1739
|
+
*/
|
|
1740
|
+
type IsUppercase<S extends string> = AllExtend<_IsUppercase<S>, true>;
|
|
1741
|
+
/**
|
|
1742
|
+
Loops through each part in the string and returns a boolean array indicating whether each part is uppercase.
|
|
1743
|
+
*/
|
|
1744
|
+
type _IsUppercase<S extends string, Accumulator extends boolean[] = []> = S extends `${infer First}${infer Rest}` ? _IsUppercase<Rest, [...Accumulator, IsUppercaseHelper<First>]> : [...Accumulator, IsUppercaseHelper<S>];
|
|
1745
|
+
/**
|
|
1746
|
+
Returns a boolean for whether an individual part of the string is uppercase.
|
|
1747
|
+
*/
|
|
1748
|
+
type IsUppercaseHelper<S extends string> = S extends Uppercase<string> ? true : S extends Lowercase<string> | Uncapitalize<string> | `${string}${Lowercase<string>}${string}` ? false : boolean;
|
|
1749
|
+
//#endregion
|
|
1750
|
+
//#region ../../node_modules/.pnpm/type-fest@5.5.0/node_modules/type-fest/source/words.d.ts
|
|
1751
|
+
type SkipEmptyWord<Word extends string> = Word extends '' ? [] : [Word];
|
|
1752
|
+
type RemoveLastCharacter<Sentence extends string, Character extends string> = Sentence extends `${infer LeftSide}${Character}` ? SkipEmptyWord<LeftSide> : never;
|
|
1753
|
+
/**
|
|
1754
|
+
Words options.
|
|
1755
|
+
|
|
1756
|
+
@see {@link Words}
|
|
1757
|
+
*/
|
|
1758
|
+
type WordsOptions = {
|
|
1759
|
+
/**
|
|
1760
|
+
Split on numeric sequence.
|
|
1761
|
+
@default true
|
|
1762
|
+
@example
|
|
1763
|
+
```
|
|
1764
|
+
import type {Words} from 'type-fest';
|
|
1765
|
+
type Example1 = Words<'p2pNetwork', {splitOnNumbers: true}>;
|
|
1766
|
+
//=> ['p', '2', 'p', 'Network']
|
|
1767
|
+
type Example2 = Words<'p2pNetwork', {splitOnNumbers: false}>;
|
|
1768
|
+
//=> ['p2p', 'Network']
|
|
1769
|
+
```
|
|
1770
|
+
*/
|
|
1771
|
+
splitOnNumbers?: boolean;
|
|
855
1772
|
};
|
|
1773
|
+
type _DefaultWordsOptions = {
|
|
1774
|
+
splitOnNumbers: true;
|
|
1775
|
+
};
|
|
1776
|
+
/**
|
|
1777
|
+
Split a string (almost) like Lodash's `_.words()` function.
|
|
856
1778
|
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
// fontWeight: number | undefined;
|
|
863
|
-
// };
|
|
864
|
-
// autocomplete: boolean;
|
|
865
|
-
// autosave: boolean | undefined;
|
|
866
|
-
// }
|
|
1779
|
+
- Split on each word that begins with a capital letter.
|
|
1780
|
+
- Split on each {@link WordSeparators}.
|
|
1781
|
+
- Split on numeric sequence.
|
|
1782
|
+
|
|
1783
|
+
@example
|
|
867
1784
|
```
|
|
1785
|
+
import type {Words} from 'type-fest';
|
|
868
1786
|
|
|
869
|
-
|
|
1787
|
+
type Words0 = Words<'helloWorld'>;
|
|
1788
|
+
//=> ['hello', 'World']
|
|
870
1789
|
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
1790
|
+
type Words1 = Words<'helloWORLD'>;
|
|
1791
|
+
//=> ['hello', 'WORLD']
|
|
1792
|
+
|
|
1793
|
+
type Words2 = Words<'hello-world'>;
|
|
1794
|
+
//=> ['hello', 'world']
|
|
1795
|
+
|
|
1796
|
+
type Words3 = Words<'--hello the_world'>;
|
|
1797
|
+
//=> ['hello', 'the', 'world']
|
|
1798
|
+
|
|
1799
|
+
type Words4 = Words<'lifeIs42'>;
|
|
1800
|
+
//=> ['life', 'Is', '42']
|
|
1801
|
+
|
|
1802
|
+
type Words5 = Words<'p2pNetwork', {splitOnNumbers: false}>;
|
|
1803
|
+
//=> ['p2p', 'Network']
|
|
1804
|
+
```
|
|
1805
|
+
|
|
1806
|
+
@category Change case
|
|
1807
|
+
@category Template literal
|
|
876
1808
|
*/
|
|
877
|
-
type
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
}
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
1809
|
+
type Words<Sentence extends string, Options extends WordsOptions = {}> = WordsImplementation<Sentence, ApplyDefaultOptions<WordsOptions, _DefaultWordsOptions, Options>>;
|
|
1810
|
+
type WordsImplementation<Sentence extends string, Options extends Required<WordsOptions>, LastCharacter extends string = '', CurrentWord extends string = ''> = Sentence extends `${infer FirstCharacter}${infer RemainingCharacters}` ? FirstCharacter extends WordSeparators // Skip word separator
|
|
1811
|
+
? [...SkipEmptyWord<CurrentWord>, ...WordsImplementation<RemainingCharacters, Options>] : LastCharacter extends '' // Fist char of word
|
|
1812
|
+
? WordsImplementation<RemainingCharacters, Options, FirstCharacter, FirstCharacter> // Case change: non-numeric to numeric
|
|
1813
|
+
: [false, true] extends [IsNumeric<LastCharacter>, IsNumeric<FirstCharacter>] ? Options['splitOnNumbers'] extends true // Split on number: push word
|
|
1814
|
+
? [...SkipEmptyWord<CurrentWord>, ...WordsImplementation<RemainingCharacters, Options, FirstCharacter, FirstCharacter>] // No split on number: concat word
|
|
1815
|
+
: WordsImplementation<RemainingCharacters, Options, FirstCharacter, `${CurrentWord}${FirstCharacter}`> // Case change: numeric to non-numeric
|
|
1816
|
+
: [true, false] extends [IsNumeric<LastCharacter>, IsNumeric<FirstCharacter>] ? Options['splitOnNumbers'] extends true // Split on number: push word
|
|
1817
|
+
? [...SkipEmptyWord<CurrentWord>, ...WordsImplementation<RemainingCharacters, Options, FirstCharacter, FirstCharacter>] // No split on number: concat word
|
|
1818
|
+
: WordsImplementation<RemainingCharacters, Options, FirstCharacter, `${CurrentWord}${FirstCharacter}`> // No case change: concat word
|
|
1819
|
+
: [true, true] extends [IsNumeric<LastCharacter>, IsNumeric<FirstCharacter>] ? WordsImplementation<RemainingCharacters, Options, FirstCharacter, `${CurrentWord}${FirstCharacter}`> // Case change: lower to upper, push word
|
|
1820
|
+
: [true, true] extends [IsLowercase<LastCharacter>, IsUppercase<FirstCharacter>] ? [...SkipEmptyWord<CurrentWord>, ...WordsImplementation<RemainingCharacters, Options, FirstCharacter, FirstCharacter>] // Case change: upper to lower, brings back the last character, push word
|
|
1821
|
+
: [true, true] extends [IsUppercase<LastCharacter>, IsLowercase<FirstCharacter>] ? [...RemoveLastCharacter<CurrentWord, LastCharacter>, ...WordsImplementation<RemainingCharacters, Options, FirstCharacter, `${LastCharacter}${FirstCharacter}`>] // No case change: concat word
|
|
1822
|
+
: WordsImplementation<RemainingCharacters, Options, FirstCharacter, `${CurrentWord}${FirstCharacter}`> : [...SkipEmptyWord<CurrentWord>];
|
|
1823
|
+
//#endregion
|
|
1824
|
+
//#region ../../node_modules/.pnpm/type-fest@5.5.0/node_modules/type-fest/source/remove-prefix.d.ts
|
|
1825
|
+
/**
|
|
1826
|
+
@see {@link RemovePrefix}
|
|
1827
|
+
*/
|
|
1828
|
+
type RemovePrefixOptions = {
|
|
1829
|
+
/**
|
|
1830
|
+
When enabled, instantiations with non-literal prefixes (e.g., `string`, `Uppercase<string>`, `` `on${string}` ``) simply return `string`, since their precise structure cannot be statically determined.
|
|
1831
|
+
Note: Disabling this option can produce misleading results that might not reflect the actual runtime behavior.
|
|
1832
|
+
For example, ``RemovePrefix<'on-change', `${string}-`, {strict: false}>`` returns `'change'`, but at runtime, prefix could be `'handle-'` (which satisfies `` `${string}-` ``) and removing `'handle-'` from `'on-change'` would not result in `'change'`.
|
|
1833
|
+
So, it is recommended to not disable this option unless you are aware of the implications.
|
|
1834
|
+
@default true
|
|
1835
|
+
@example
|
|
1836
|
+
```
|
|
1837
|
+
import type {RemovePrefix} from 'type-fest';
|
|
1838
|
+
type A = RemovePrefix<'on-change', `${string}-`, {strict: true}>;
|
|
1839
|
+
//=> string
|
|
1840
|
+
type B = RemovePrefix<'on-change', `${string}-`, {strict: false}>;
|
|
1841
|
+
//=> 'change'
|
|
1842
|
+
type C = RemovePrefix<'on-change', string, {strict: true}>;
|
|
1843
|
+
//=> string
|
|
1844
|
+
type D = RemovePrefix<'on-change', string, {strict: false}>;
|
|
1845
|
+
//=> 'n-change'
|
|
1846
|
+
type E = RemovePrefix<`${string}/${number}`, `${string}/`, {strict: true}>;
|
|
1847
|
+
//=> string
|
|
1848
|
+
type F = RemovePrefix<`${string}/${number}`, `${string}/`, {strict: false}>;
|
|
1849
|
+
//=> `${number}`
|
|
1850
|
+
```
|
|
1851
|
+
Note: This option has no effect when only the input string type is non-literal. For example, ``RemovePrefix<`on-${string}`, 'on-'>`` will always return `string`.
|
|
1852
|
+
@example
|
|
1853
|
+
```
|
|
1854
|
+
import type {RemovePrefix} from 'type-fest';
|
|
1855
|
+
type A = RemovePrefix<`on-${string}`, 'on-', {strict: true}>;
|
|
1856
|
+
//=> string
|
|
1857
|
+
type B = RemovePrefix<`on-${string}`, 'on-', {strict: false}>;
|
|
1858
|
+
//=> string
|
|
1859
|
+
type C = RemovePrefix<`id-${number}`, 'id-', {strict: true}>;
|
|
1860
|
+
//=> `${number}`
|
|
1861
|
+
type D = RemovePrefix<`id-${number}`, 'id-', {strict: false}>;
|
|
1862
|
+
//=> `${number}`
|
|
1863
|
+
```
|
|
1864
|
+
Note: If it can be statically determined that the input string can never start with the specified non-literal prefix, then the input string is returned as-is, regardless of the value of this option.
|
|
1865
|
+
For example, ``RemovePrefix<`${string}/${number}`, `${string}:`>`` returns `` `${string}/${number}` ``, since a string of type `` `${string}/${number}` `` can never start with a prefix of type `` `${string}:` ``.
|
|
1866
|
+
```
|
|
1867
|
+
import type {RemovePrefix} from 'type-fest';
|
|
1868
|
+
type A = RemovePrefix<`${string}/${number}`, `${string}:`, {strict: true}>;
|
|
1869
|
+
//=> `${string}/${number}`
|
|
1870
|
+
type B = RemovePrefix<`${string}/${number}`, `${string}:`, {strict: false}>;
|
|
1871
|
+
//=> `${string}/${number}`
|
|
1872
|
+
type C = RemovePrefix<'on-change', `${number}-`, {strict: true}>;
|
|
1873
|
+
//=> 'on-change'
|
|
1874
|
+
type D = RemovePrefix<'on-change', `${number}-`, {strict: false}>;
|
|
1875
|
+
//=> 'on-change'
|
|
1876
|
+
```
|
|
1877
|
+
*/
|
|
1878
|
+
strict?: boolean;
|
|
1879
|
+
};
|
|
1880
|
+
type DefaultRemovePrefixOptions = {
|
|
1881
|
+
strict: true;
|
|
1882
|
+
};
|
|
1883
|
+
/**
|
|
1884
|
+
Remove the specified prefix from the start of a string.
|
|
1885
|
+
|
|
1886
|
+
@example
|
|
1887
|
+
```
|
|
1888
|
+
import type {RemovePrefix} from 'type-fest';
|
|
1889
|
+
|
|
1890
|
+
type A = RemovePrefix<'on-change', 'on-'>;
|
|
1891
|
+
//=> 'change'
|
|
1892
|
+
|
|
1893
|
+
type B = RemovePrefix<'sm:flex' | 'sm:p-4' | 'sm:gap-2', 'sm:'>;
|
|
1894
|
+
//=> 'flex' | 'p-4' | 'gap-2'
|
|
1895
|
+
|
|
1896
|
+
type C = RemovePrefix<'on-change', 'off-'>;
|
|
1897
|
+
//=> 'on-change'
|
|
1898
|
+
|
|
1899
|
+
type D = RemovePrefix<`handle${Capitalize<string>}`, 'handle'>;
|
|
1900
|
+
//=> Capitalize<string>
|
|
1901
|
+
```
|
|
1902
|
+
|
|
1903
|
+
@see {@link RemovePrefixOptions}
|
|
1904
|
+
|
|
1905
|
+
@category String
|
|
1906
|
+
@category Template literal
|
|
1907
|
+
*/
|
|
1908
|
+
type RemovePrefix<S extends string, Prefix extends string, Options extends RemovePrefixOptions = {}> = IfNotAnyOrNever<S, IfNotAnyOrNever<Prefix, _RemovePrefix<S, Prefix, ApplyDefaultOptions<RemovePrefixOptions, DefaultRemovePrefixOptions, Options>>, string, S>>;
|
|
1909
|
+
type _RemovePrefix<S extends string, Prefix extends string, Options extends Required<RemovePrefixOptions>> = Prefix extends string // For distributing `Prefix`
|
|
1910
|
+
? S extends `${Prefix}${infer Rest}` ? Or<IsStringLiteral<Prefix>, Not<Options['strict']>> extends true ? Rest : string // Fallback to `string` when `Prefix` is non-literal and `strict` is disabled
|
|
1911
|
+
: S // Return back `S` when `Prefix` is not present at the start of `S`
|
|
1912
|
+
: never;
|
|
892
1913
|
//#endregion
|
|
893
|
-
//#region
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
deletedAt: Date | null;
|
|
897
|
-
updatedAt: Date;
|
|
898
|
-
}
|
|
899
|
-
declare const ItemMetadataPropertyNames: PropertyNames<ItemMetadata>;
|
|
900
|
-
declare const itemMetadataSchema: z.ZodObject<{
|
|
901
|
-
createdAt: z.ZodDate;
|
|
902
|
-
deletedAt: z.ZodNullable<z.ZodDate>;
|
|
903
|
-
updatedAt: z.ZodDate;
|
|
1914
|
+
//#region ../../node_modules/.pnpm/type-fest@5.5.0/node_modules/type-fest/source/delimiter-case.d.ts
|
|
1915
|
+
type _DefaultDelimiterCaseOptions = Merge<_DefaultWordsOptions, {
|
|
1916
|
+
splitOnNumbers: false;
|
|
904
1917
|
}>;
|
|
1918
|
+
/**
|
|
1919
|
+
Convert an array of words to delimiter case starting with a delimiter with input capitalization.
|
|
1920
|
+
*/
|
|
1921
|
+
type DelimiterCaseFromArray<Words extends string[], Delimiter extends string, OutputString extends string = ''> = Words extends [infer FirstWord extends string, ...infer RemainingWords extends string[]] ? DelimiterCaseFromArray<RemainingWords, Delimiter, `${OutputString}${StartsWith<FirstWord, AsciiPunctuation> extends true ? '' : Delimiter}${FirstWord}`> : OutputString;
|
|
1922
|
+
/**
|
|
1923
|
+
Convert a string literal to a custom string delimiter casing.
|
|
1924
|
+
|
|
1925
|
+
This can be useful when, for example, converting a camel-cased object property to an oddly cased one.
|
|
1926
|
+
|
|
1927
|
+
@see {@link KebabCase}
|
|
1928
|
+
@see {@link SnakeCase}
|
|
1929
|
+
|
|
1930
|
+
@example
|
|
1931
|
+
```
|
|
1932
|
+
import type {DelimiterCase} from 'type-fest';
|
|
1933
|
+
|
|
1934
|
+
// Simple
|
|
1935
|
+
|
|
1936
|
+
const someVariable: DelimiterCase<'fooBar', '#'> = 'foo#bar';
|
|
1937
|
+
const someVariableNoSplitOnNumbers: DelimiterCase<'p2pNetwork', '#', {splitOnNumbers: false}> = 'p2p#network';
|
|
1938
|
+
|
|
1939
|
+
// Advanced
|
|
1940
|
+
|
|
1941
|
+
type OddlyCasedProperties<T> = {
|
|
1942
|
+
[K in keyof T as DelimiterCase<K, '#'>]: T[K]
|
|
1943
|
+
};
|
|
1944
|
+
|
|
1945
|
+
type SomeOptions = {
|
|
1946
|
+
dryRun: boolean;
|
|
1947
|
+
includeFile: string;
|
|
1948
|
+
foo: number;
|
|
1949
|
+
};
|
|
1950
|
+
|
|
1951
|
+
const rawCliOptions: OddlyCasedProperties<SomeOptions> = {
|
|
1952
|
+
'dry#run': true,
|
|
1953
|
+
'include#file': 'bar.js',
|
|
1954
|
+
foo: 123,
|
|
1955
|
+
};
|
|
1956
|
+
```
|
|
1957
|
+
|
|
1958
|
+
@category Change case
|
|
1959
|
+
@category Template literal
|
|
1960
|
+
*/
|
|
1961
|
+
type DelimiterCase<Value, Delimiter extends string, Options extends WordsOptions = {}> = Value extends string ? IsStringLiteral<Value> extends false ? Value : Lowercase<RemovePrefix<DelimiterCaseFromArray<Words<Value, ApplyDefaultOptions<WordsOptions, _DefaultDelimiterCaseOptions, Options>>, Delimiter>, string, {
|
|
1962
|
+
strict: false;
|
|
1963
|
+
}>> : Value;
|
|
905
1964
|
//#endregion
|
|
906
|
-
//#region
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
1965
|
+
//#region ../../node_modules/.pnpm/type-fest@5.5.0/node_modules/type-fest/source/kebab-case.d.ts
|
|
1966
|
+
/**
|
|
1967
|
+
Convert a string literal to kebab-case.
|
|
1968
|
+
|
|
1969
|
+
This can be useful when, for example, converting a camel-cased object property to a kebab-cased CSS class name or a command-line flag.
|
|
1970
|
+
|
|
1971
|
+
@example
|
|
1972
|
+
```
|
|
1973
|
+
import type {KebabCase} from 'type-fest';
|
|
1974
|
+
|
|
1975
|
+
// Simple
|
|
1976
|
+
|
|
1977
|
+
const someVariable: KebabCase<'fooBar'> = 'foo-bar';
|
|
1978
|
+
const someVariableNoSplitOnNumbers: KebabCase<'p2pNetwork', {splitOnNumbers: false}> = 'p2p-network';
|
|
1979
|
+
|
|
1980
|
+
// Advanced
|
|
1981
|
+
|
|
1982
|
+
type KebabCasedProperties<T> = {
|
|
1983
|
+
[K in keyof T as KebabCase<K>]: T[K]
|
|
1984
|
+
};
|
|
1985
|
+
|
|
1986
|
+
type CliOptions = {
|
|
1987
|
+
dryRun: boolean;
|
|
1988
|
+
includeFile: string;
|
|
1989
|
+
foo: number;
|
|
1990
|
+
};
|
|
1991
|
+
|
|
1992
|
+
const rawCliOptions: KebabCasedProperties<CliOptions> = {
|
|
1993
|
+
'dry-run': true,
|
|
1994
|
+
'include-file': 'bar.js',
|
|
1995
|
+
foo: 123,
|
|
1996
|
+
};
|
|
1997
|
+
```
|
|
1998
|
+
|
|
1999
|
+
@category Change case
|
|
2000
|
+
@category Template literal
|
|
2001
|
+
*/
|
|
2002
|
+
type KebabCase<Value, Options extends WordsOptions = {}> = DelimiterCase<Value, '-', ApplyDefaultOptions<WordsOptions, _DefaultDelimiterCaseOptions, Options>>;
|
|
919
2003
|
//#endregion
|
|
920
2004
|
//#region src/util/types/DeepOmit.d.ts
|
|
921
|
-
type DeepOmit<T, TKey> = T extends Primitive ? T :
|
|
922
|
-
//#endregion
|
|
923
|
-
//#region src/util/types/DeepOptionalProperties.d.ts
|
|
924
|
-
type DeepOptionalProperties<T> = { [K in keyof T as undefined extends T[K] ? K : never]?: DeepOptionalProperties<T[K]> };
|
|
925
|
-
//#endregion
|
|
926
|
-
//#region src/util/types/DeepRequiredProperties.d.ts
|
|
927
|
-
type DeepRequiredProperties<T> = { [K in keyof T as undefined extends T[K] ? never : K]: DeepRequiredProperties<T[K]> };
|
|
2005
|
+
type DeepOmit<T, TKey extends PropertyKey> = [T] extends [Date | Function | Primitive] ? T : [Record<string, unknown>] extends [T] ? T : T extends object ? T extends unknown[] ? T extends readonly unknown[] ? { [K in keyof T]: DeepOmit<T[K], TKey> } : DeepOmit<T[number], TKey>[] : { [P in keyof T as P extends TKey ? never : P]: DeepOmit<T[P], TKey> } : T;
|
|
928
2006
|
//#endregion
|
|
929
2007
|
//#region src/util/types/DeepOptionalUndefined.d.ts
|
|
930
|
-
type DeepOptionalUndefined<T> = T extends
|
|
2008
|
+
type DeepOptionalUndefined<T> = T extends Date | Function | Primitive ? T : T extends unknown[] ? { [K in keyof T]: DeepOptionalUndefined<T[K]> } : T extends object ? { [K in keyof T as undefined extends T[K] ? K : never]?: DeepOptionalUndefined<T[K]> } & { [K in keyof T as undefined extends T[K] ? never : K]: DeepOptionalUndefined<T[K]> } extends infer O ? { [K in keyof O]: O[K] } : never : T;
|
|
931
2009
|
//#endregion
|
|
932
2010
|
//#region src/models/shared/ToData.d.ts
|
|
933
|
-
type ToData<T
|
|
2011
|
+
type ToData<T> = DeepOptionalUndefined<DeepOmit<T, "toJSON">>;
|
|
934
2012
|
//#endregion
|
|
935
2013
|
//#region src/models/shared/WithMetadata.d.ts
|
|
936
2014
|
interface WithMetadata<TBase extends Class<NonNullable<unknown>>> {
|
|
@@ -946,8 +2024,10 @@ declare const MENTION_ID_ATTRIBUTE = "data-id";
|
|
|
946
2024
|
declare const MENTION_LABEL_ATTRIBUTE = "data-label";
|
|
947
2025
|
declare const MENTION_TYPE_ATTRIBUTE = "data-type";
|
|
948
2026
|
declare const MENTION_TYPE = "mention";
|
|
2027
|
+
declare const MENTION_HERE_ID = "@here";
|
|
2028
|
+
declare const MENTION_EVERYONE_ID = "@everyone";
|
|
949
2029
|
//#endregion
|
|
950
|
-
//#region ../../node_modules/.pnpm/node-html-parser@7.0
|
|
2030
|
+
//#region ../../node_modules/.pnpm/node-html-parser@7.1.0/node_modules/node-html-parser/dist/void-tag.d.ts
|
|
951
2031
|
declare class VoidTag {
|
|
952
2032
|
addClosingSlash: boolean;
|
|
953
2033
|
private voidTags;
|
|
@@ -956,14 +2036,14 @@ declare class VoidTag {
|
|
|
956
2036
|
isVoidElement(tag: string): boolean;
|
|
957
2037
|
}
|
|
958
2038
|
//#endregion
|
|
959
|
-
//#region ../../node_modules/.pnpm/node-html-parser@7.0
|
|
2039
|
+
//#region ../../node_modules/.pnpm/node-html-parser@7.1.0/node_modules/node-html-parser/dist/nodes/type.d.ts
|
|
960
2040
|
declare enum NodeType {
|
|
961
2041
|
ELEMENT_NODE = 1,
|
|
962
2042
|
TEXT_NODE = 3,
|
|
963
2043
|
COMMENT_NODE = 8
|
|
964
2044
|
}
|
|
965
2045
|
//#endregion
|
|
966
|
-
//#region ../../node_modules/.pnpm/node-html-parser@7.0
|
|
2046
|
+
//#region ../../node_modules/.pnpm/node-html-parser@7.1.0/node_modules/node-html-parser/dist/nodes/node.d.ts
|
|
967
2047
|
/**
|
|
968
2048
|
* Node Class as base class for TextNode and HTMLElement.
|
|
969
2049
|
*/
|
|
@@ -987,7 +2067,7 @@ declare abstract class Node {
|
|
|
987
2067
|
set textContent(val: string);
|
|
988
2068
|
}
|
|
989
2069
|
//#endregion
|
|
990
|
-
//#region ../../node_modules/.pnpm/node-html-parser@7.0
|
|
2070
|
+
//#region ../../node_modules/.pnpm/node-html-parser@7.1.0/node_modules/node-html-parser/dist/nodes/html.d.ts
|
|
991
2071
|
interface KeyAttributes {
|
|
992
2072
|
id?: string;
|
|
993
2073
|
class?: string;
|
|
@@ -1119,6 +2199,12 @@ declare class HTMLElement extends Node {
|
|
|
1119
2199
|
* @return {(HTMLElement|null)} matching node
|
|
1120
2200
|
*/
|
|
1121
2201
|
querySelector(selector: string): HTMLElement | null;
|
|
2202
|
+
/**
|
|
2203
|
+
* Tests whether the node matches a given CSS selector.
|
|
2204
|
+
* @param {string} selector Simplified CSS selector
|
|
2205
|
+
* @return {boolean}
|
|
2206
|
+
*/
|
|
2207
|
+
matches(selector: string): boolean;
|
|
1122
2208
|
/**
|
|
1123
2209
|
* find elements by their tagName
|
|
1124
2210
|
* @param {string} tagName the tagName of the elements to select
|
|
@@ -1220,6 +2306,10 @@ interface Options {
|
|
|
1220
2306
|
*/
|
|
1221
2307
|
fixNestedATags?: boolean;
|
|
1222
2308
|
parseNoneClosedTags?: boolean;
|
|
2309
|
+
/**
|
|
2310
|
+
* When true, preserves invalid HTML nesting (e.g., <p><p>bar</p></p>) instead of auto-closing tags
|
|
2311
|
+
*/
|
|
2312
|
+
preserveTagNesting?: boolean;
|
|
1223
2313
|
blockTextElements: {
|
|
1224
2314
|
[tag: string]: boolean;
|
|
1225
2315
|
};
|
|
@@ -1233,6 +2323,7 @@ interface Options {
|
|
|
1233
2323
|
*/
|
|
1234
2324
|
closingSlash?: boolean;
|
|
1235
2325
|
};
|
|
2326
|
+
closeAllByClosing?: boolean;
|
|
1236
2327
|
}
|
|
1237
2328
|
//#endregion
|
|
1238
2329
|
//#region src/services/message/getMentions.d.ts
|
|
@@ -1266,7 +2357,7 @@ declare const getPropertyNames: <T>() => PropertyNames<T>;
|
|
|
1266
2357
|
declare const isPlainObject: (data: unknown) => data is object;
|
|
1267
2358
|
//#endregion
|
|
1268
2359
|
//#region src/util/object/jsonDateParse.d.ts
|
|
1269
|
-
declare const jsonDateParse: (text: string) =>
|
|
2360
|
+
declare const jsonDateParse: <T = any>(text: string) => T;
|
|
1270
2361
|
//#endregion
|
|
1271
2362
|
//#region src/util/types/MergeObjectsStrict.d.ts
|
|
1272
2363
|
type MergeObjectsStrict<T extends object[]> = T extends [infer TFirst, infer TSecond, ...infer TRemaining] ? TSecond extends { [K in keyof TSecond]: K extends keyof TFirst ? never : TSecond[K] } ? TRemaining extends object[] ? MergeObjectsStrict<[TSecond, ...TRemaining]> & TFirst : TFirst & TSecond : never : T extends [infer TFirst] ? TFirst : never;
|
|
@@ -1289,11 +2380,8 @@ declare const capitalize: (string: string) => string;
|
|
|
1289
2380
|
//#region src/util/text/streamToText.d.ts
|
|
1290
2381
|
declare const streamToText: (readable: NodeJS.ReadableStream) => Promise<string>;
|
|
1291
2382
|
//#endregion
|
|
1292
|
-
//#region src/util/types/CamelToKebab.d.ts
|
|
1293
|
-
type CamelToKebab<S extends string> = S extends `${infer T}${infer U}` ? U extends Uncapitalize<U> ? `${Uncapitalize<T>}${CamelToKebab<U>}` : `${Uncapitalize<T>}-${CamelToKebab<U>}` : S;
|
|
1294
|
-
//#endregion
|
|
1295
2383
|
//#region src/util/text/toKebabCase.d.ts
|
|
1296
|
-
declare const toKebabCase: <T extends string>(string: T) =>
|
|
2384
|
+
declare const toKebabCase: <T extends string>(string: T) => KebabCase<T>;
|
|
1297
2385
|
//#endregion
|
|
1298
2386
|
//#region src/util/text/truncate.d.ts
|
|
1299
2387
|
declare const truncate: (string: string, length: number) => string;
|
|
@@ -1307,29 +2395,20 @@ declare const hrtime: (previousHrTime?: [number, number]) => [number, number];
|
|
|
1307
2395
|
//#region src/util/time/now.d.ts
|
|
1308
2396
|
declare const now: () => string;
|
|
1309
2397
|
//#endregion
|
|
2398
|
+
//#region src/util/types/BuildTuple.d.ts
|
|
2399
|
+
type BuildTuple<N extends number, T = unknown, R extends unknown[] = []> = R["length"] extends N ? R : BuildTuple<N, T, [...R, T]>;
|
|
2400
|
+
//#endregion
|
|
1310
2401
|
//#region src/util/types/FunctionProperties.d.ts
|
|
1311
2402
|
type FunctionProperties<T> = { [K in keyof T]: T[K] extends Function ? K : never };
|
|
1312
2403
|
//#endregion
|
|
1313
2404
|
//#region src/util/types/ExcludeFunctionProperties.d.ts
|
|
1314
2405
|
type ExcludeFunctionProperties<T> = Except<T, FunctionProperties<T>[keyof T]>;
|
|
1315
2406
|
//#endregion
|
|
1316
|
-
//#region src/util/types/KebabToCamel.d.ts
|
|
1317
|
-
type KebabToCamel<S extends string> = S extends `${infer T}-${infer U}` ? `${T}${Capitalize<KebabToCamel<U>>}` : S;
|
|
1318
|
-
//#endregion
|
|
1319
2407
|
//#region src/util/types/MapValue.d.ts
|
|
1320
2408
|
type MapValue<BaseType> = BaseType extends Map<unknown, infer ValueType> ? ValueType : never;
|
|
1321
2409
|
//#endregion
|
|
1322
|
-
//#region src/util/types/PartialByKeys.d.ts
|
|
1323
|
-
type PartialByKeys<T, K extends keyof T = keyof T> = Except<T, K> & Partial<Pick<T, Extract<keyof T, K>>>;
|
|
1324
|
-
//#endregion
|
|
1325
|
-
//#region src/util/types/TupleSplitHead.d.ts
|
|
1326
|
-
type TupleSplitHead<T extends unknown[], N extends number> = T["length"] extends N ? T : T extends [...infer R, unknown] ? TupleSplitHead<R, N> : never;
|
|
1327
|
-
//#endregion
|
|
1328
|
-
//#region src/util/types/TupleSplitTail.d.ts
|
|
1329
|
-
type TupleSplitTail<T, N extends number, O extends unknown[] = []> = O["length"] extends N ? T : T extends [infer F, ...infer R] ? TupleSplitTail<[...R], N, [...O, F]> : never;
|
|
1330
|
-
//#endregion
|
|
1331
2410
|
//#region src/util/types/TupleSplit.d.ts
|
|
1332
|
-
type TupleSplit<T extends unknown[], N extends number> = [
|
|
2411
|
+
type TupleSplit<T extends unknown[], N extends number> = T extends [...BuildTuple<N>, ...infer R] ? [T extends [...infer H, ...R] ? H : BuildTuple<N, T[number]>, R] : [T, []];
|
|
1333
2412
|
//#endregion
|
|
1334
2413
|
//#region src/util/types/SkipFirst.d.ts
|
|
1335
2414
|
type SkipFirst<T extends unknown[], N extends number> = TupleSplit<T, N>[1];
|
|
@@ -1338,7 +2417,13 @@ type SkipFirst<T extends unknown[], N extends number> = TupleSplit<T, N>[1];
|
|
|
1338
2417
|
type TakeFirst<T extends unknown[], N extends number> = TupleSplit<T, N>[0];
|
|
1339
2418
|
//#endregion
|
|
1340
2419
|
//#region src/util/types/TupleSlice.d.ts
|
|
1341
|
-
type TupleSlice<T extends unknown[], S extends number, E extends number = T["length"]> = SkipFirst<TakeFirst<T, E>, S>;
|
|
2420
|
+
type TupleSlice<T extends unknown[], S extends number, E extends number = T["length"]> = E extends T["length"] ? SkipFirst<T, S> : SkipFirst<TakeFirst<T, E>, S>;
|
|
2421
|
+
//#endregion
|
|
2422
|
+
//#region src/util/types/TupleSplitHead.d.ts
|
|
2423
|
+
type TupleSplitHead<T extends unknown[], N extends number> = TupleSplit<T, N>[0];
|
|
2424
|
+
//#endregion
|
|
2425
|
+
//#region src/util/types/TupleSplitTail.d.ts
|
|
2426
|
+
type TupleSplitTail<T extends unknown[], N extends number> = TupleSplit<T, N>[1];
|
|
1342
2427
|
//#endregion
|
|
1343
2428
|
//#region src/util/validation/exhaustiveGuard.d.ts
|
|
1344
2429
|
declare const exhaustiveGuard: (value: never) => never;
|
|
@@ -1350,4 +2435,4 @@ declare const UUIDV4_REGEX: RegExp;
|
|
|
1350
2435
|
//#region src/util/id/uuid/uuidValidateV4.d.ts
|
|
1351
2436
|
declare const uuidValidateV4: (uuid: string) => boolean;
|
|
1352
2437
|
//#endregion
|
|
1353
|
-
export { AllSpecialValues,
|
|
2438
|
+
export { AllSpecialValues, BuildTuple, DeepOmit, DeepOptionalUndefined, ExcludeFunctionProperties, ForbiddenError, FunctionProperties, GetPaths, GetProperties, ID_SEPARATOR, InvalidOperationError, ItemEntityType, ItemEntityTypePropertyNames, ItemMetadata, ItemMetadataPropertyNames, MENTION_EVERYONE_ID, MENTION_HERE_ID, MENTION_ID_ATTRIBUTE, MENTION_LABEL_ATTRIBUTE, MENTION_TYPE, MENTION_TYPE_ATTRIBUTE, MapValue, MergeObjectsStrict, NIL, NotFoundError, NotInitializedError, Operation, PropertyNames, RoutePath, SITE_NAME, SURVEY_DISPLAY_NAME, Serializable, SkipFirst, TakeFirst, TakeOne, ToData, TupleSlice, TupleSplit, TupleSplitHead, TupleSplitTail, UUIDV4_REGEX, WithMetadata, applyItemMetadataMixin, capitalize, createItemEntityTypeSchema, css, escapeRegExp, exhaustiveGuard, getIsServer, getMentions, getPropertyNames, getRawData, hrtime, html, isPlainObject, itemMetadataSchema, jsonDateParse, mergeObjectsStrict, now, streamToText, takeOne, toKebabCase, toRawDeep, truncate, uncapitalize, uuidValidateV4 };
|