@rzl-zone/utils-js 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +21 -0
- package/README.md +215 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +4309 -0
- package/dist/index.js +1 -0
- package/dist/next/index.cjs +1 -0
- package/dist/next/index.d.ts +184 -0
- package/dist/next/index.js +1 -0
- package/dist/next/server/index.cjs +1 -0
- package/dist/next/server/index.d.ts +42 -0
- package/dist/next/server/index.js +1 -0
- package/dist/rzl-utils.global.js +1 -0
- package/dist/types/index.d.ts +2057 -0
- package/package.json +148 -0
|
@@ -0,0 +1,2057 @@
|
|
|
1
|
+
|
|
2
|
+
/** --------------------------------------------------
|
|
3
|
+
* * ***A union type of all valid named CSS colors including `transparent`.***
|
|
4
|
+
* --------------------------------------------------
|
|
5
|
+
*
|
|
6
|
+
* This type includes standard color names as defined in the CSS Color Module Specification,
|
|
7
|
+
* and can be used for validating CSS color inputs in strongly typed UI libraries, themes, or design systems.
|
|
8
|
+
*
|
|
9
|
+
* It ensures that only recognized, browser-supported color keywords are accepted.
|
|
10
|
+
*
|
|
11
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/named
|
|
12
|
+
* @see https://drafts.csswg.org/css-color-4/#named-colors
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* const textColor: ColorCssValidBase = "rebeccapurple"; // ✅ valid
|
|
16
|
+
* const invalidColor: ColorCssValidBase = "superblue"; // ❌ Type error
|
|
17
|
+
*/
|
|
18
|
+
type ColorCssValidBase="aliceblue" | "antiquewhite" | "aqua" | "aquamarine" | "azure" | "beige" | "bisque" | "black" | "blanchedalmond" | "blue" | "blueviolet" | "brown" | "burlywood" | "cadetblue" | "chartreuse" | "chocolate" | "coral" | "cornflowerblue" | "cornsilk" | "crimson" | "cyan" | "darkblue" | "darkcyan" | "darkgoldenrod" | "darkgray" | "darkgreen" | "darkgrey" | "darkkhaki" | "darkmagenta" | "darkolivegreen" | "darkorange" | "darkorchid" | "darkred" | "darksalmon" | "darkseagreen" | "darkslateblue" | "darkslategray" | "darkslategrey" | "darkturquoise" | "darkviolet" | "deeppink" | "deepskyblue" | "dimgray" | "dimgrey" | "dodgerblue" | "firebrick" | "floralwhite" | "forestgreen" | "fuchsia" | "gainsboro" | "ghostwhite" | "gold" | "goldenrod" | "gray" | "green" | "greenyellow" | "grey" | "honeydew" | "hotpink" | "indianred" | "indigo" | "ivory" | "khaki" | "lavender" | "lavenderblush" | "lawngreen" | "lemonchiffon" | "lightblue" | "lightcoral" | "lightcyan" | "lightgoldenrodyellow" | "lightgray" | "lightgreen" | "lightgrey" | "lightpink" | "lightsalmon" | "lightseagreen" | "lightskyblue" | "lightslategray" | "lightslategrey" | "lightsteelblue" | "lightyellow" | "lime" | "limegreen" | "linen" | "magenta" | "maroon" | "mediumaquamarine" | "mediumblue" | "mediumorchid" | "mediumpurple" | "mediumseagreen" | "mediumslateblue" | "mediumspringgreen" | "mediumturquoise" | "mediumvioletred" | "midnightblue" | "mintcream" | "mistyrose" | "moccasin" | "navajowhite" | "navy" | "oldlace" | "olive" | "olivedrab" | "orange" | "orangered" | "orchid" | "palegoldenrod" | "palegreen" | "paleturquoise" | "palevioletred" | "papayawhip" | "peachpuff" | "peru" | "pink" | "plum" | "powderblue" | "purple" | "rebeccapurple" | "red" | "rosybrown" | "royalblue" | "saddlebrown" | "salmon" | "sandybrown" | "seagreen" | "seashell" | "sienna" | "silver" | "skyblue" | "slateblue" | "slategray" | "slategrey" | "snow" | "springgreen" | "steelblue" | "tan" | "teal" | "thistle" | "tomato" | "transparent" | "turquoise" | "violet" | "wheat" | "white" | "whitesmoke" | "yellow" | "yellowgreen";
|
|
19
|
+
/**
|
|
20
|
+
* Returns the second argument if the first argument is `true` (defaults to `true`), otherwise returns the third argument (defaults to `false`)
|
|
21
|
+
* ```ts
|
|
22
|
+
* // valid
|
|
23
|
+
* type Case1 = If<true, 'valid'>
|
|
24
|
+
* // invalid
|
|
25
|
+
* type Case2 = If<false, 'valid', 'invalid'>
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
type If<Condition,IfTrue=true,IfFalse=false>=Condition extends true ? IfTrue:IfFalse;
|
|
29
|
+
/**
|
|
30
|
+
* Returns a boolean if the passed type is `never`
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* // true
|
|
34
|
+
* type Case1 = IsNever<never>
|
|
35
|
+
* // false
|
|
36
|
+
* type Case2 = IsNever<true>
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
type IsNever<T>=[T] extends [never] ? true:false;
|
|
40
|
+
/**
|
|
41
|
+
* Returns the second argument if the first argument is `never` (defaults to `true`), otherwise returns the third argument (defaults to `false`)
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* // 'valid'
|
|
45
|
+
* type Case1 = IfNever<never, 'valid'>
|
|
46
|
+
* // 'invalid'
|
|
47
|
+
* type Case2 = IfNever<never, 'valid', 'invalid'>
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
type IfNever<T,IfTrue=true,IfFalse=false>=If<IsNever<T>,IfTrue,IfFalse>;type NeverifyPropertiesOptions={makeOptional:boolean;};
|
|
51
|
+
/**
|
|
52
|
+
* Turns all properties of an object to type `unknown`.
|
|
53
|
+
* If `makeOptional` option is `true`, makes all properties optional
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* // {a:never; b:never}
|
|
57
|
+
* type Result = NeverifyProperties<{a: string; b: string}>
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
type NeverifyProperties<T extends object,Options extends NeverifyPropertiesOptions={makeOptional:false;}>={[K in keyof T]:never;}extends infer Result ? If<Options["makeOptional"],Partial<Result>,Result>:never;
|
|
61
|
+
/**
|
|
62
|
+
* Returns the first argument if it is an empty array, otherwise returns `never`
|
|
63
|
+
* @example
|
|
64
|
+
* ```ts
|
|
65
|
+
* // never
|
|
66
|
+
* type Result = EmptyArray<[1]>
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
type EmptyArray<T extends readonly unknown[]>=T extends readonly [unknown,...unknown[]] ? never:T;
|
|
70
|
+
/**
|
|
71
|
+
* Returns the first argument if it is a non empty array, otherwise returns `never`
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* // never
|
|
75
|
+
* type Result = EmptyArray<[1]>
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
type NonEmptyArray<T extends readonly unknown[]>=If<IsNever<EmptyArray<T>>,T,never>;
|
|
79
|
+
/**
|
|
80
|
+
* Returns a boolean whether the passed argument is an empty array
|
|
81
|
+
* @example
|
|
82
|
+
* ```ts
|
|
83
|
+
* // false
|
|
84
|
+
* type Result - IsEmptyArray<[1]>
|
|
85
|
+
*/
|
|
86
|
+
type IsEmptyArray<T extends readonly unknown[]>=If<IsNever<EmptyArray<T>>,false,true>;
|
|
87
|
+
/**
|
|
88
|
+
* Returns a boolean whether the passed argument is a non empty array
|
|
89
|
+
* @example
|
|
90
|
+
* ```ts
|
|
91
|
+
* // true
|
|
92
|
+
* type Result - IsEmptyArray<[1]>
|
|
93
|
+
*/
|
|
94
|
+
type IsNonEmptyArray<T extends readonly unknown[]>=If<IsNever<EmptyArray<T>>,true,false>;
|
|
95
|
+
/**
|
|
96
|
+
* Returns the second argument if the first argument is an empty array (defaults to `true`), otherwise returns the third argument (defaults to `false`)
|
|
97
|
+
* @example
|
|
98
|
+
* ```ts
|
|
99
|
+
* // string
|
|
100
|
+
* type Result = IfEmptyArray<[], string, number>
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
type IfEmptyArray<T extends readonly unknown[],IfTrue=true,IfFalse=false>=If<IsEmptyArray<T>,IfTrue,IfFalse>;
|
|
104
|
+
/**
|
|
105
|
+
* Returns the second argument if the first argument is a non empty array (defaults to `true`), otherwise returns the third argument (defaults to `false`)
|
|
106
|
+
* @example
|
|
107
|
+
* ```ts
|
|
108
|
+
* // string
|
|
109
|
+
* type Result = IfEmptyArray<[1], string, number>
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
type IfNonEmptyArray<T extends readonly unknown[],IfTrue=true,IfFalse=false>=If<IsNonEmptyArray<T>,IfTrue,IfFalse>;
|
|
113
|
+
/**
|
|
114
|
+
* Accepts a boolean and returns `true` if the passed type is `false`, otherwise returns `true`
|
|
115
|
+
* @example
|
|
116
|
+
* ```ts
|
|
117
|
+
* // false
|
|
118
|
+
* type Case1 = Not<true>
|
|
119
|
+
* // true
|
|
120
|
+
* type Case2 = Not<false>
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
type Not<T extends boolean>=T extends true ? false:true;type PopOptions={includeRemoved:boolean;};
|
|
124
|
+
/**
|
|
125
|
+
* Removes last element from the first array argument.
|
|
126
|
+
* If the `includeRemoved` option is `true` return removed element with the new array in the format of [rest, removed]
|
|
127
|
+
* @example
|
|
128
|
+
* ```ts
|
|
129
|
+
* // [1, 2]
|
|
130
|
+
* type Case1 = Pop<[1, 2, 3]>
|
|
131
|
+
* // [[1, 2], 3]
|
|
132
|
+
* type Case2 = Pop<[1, 2, 3], {includeRemoved: true}>
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
type Pop<T extends readonly unknown[],Options extends PopOptions={includeRemoved:false;}>=IsEmptyArray<T>extends true ? never:T extends readonly [...infer Rest extends readonly unknown[],infer Removed] ? If<Options["includeRemoved"],[Rest,Removed],Rest>:never;
|
|
136
|
+
/**
|
|
137
|
+
* Returns boolean whether the first argument extends the second argument
|
|
138
|
+
* @example
|
|
139
|
+
* ```ts
|
|
140
|
+
* // true
|
|
141
|
+
* type Case1 = Extends<1, number>
|
|
142
|
+
* // false
|
|
143
|
+
* type Case2 = Extends<number, 1>
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
type Extends<T,Base>=[T] extends [Base] ? true:false;
|
|
147
|
+
/**
|
|
148
|
+
* Returns boolean whether the first argument doesn't extend the second argument
|
|
149
|
+
* @example
|
|
150
|
+
* ```ts
|
|
151
|
+
* // false
|
|
152
|
+
* type Case1 = Extends<1, number>
|
|
153
|
+
* // true
|
|
154
|
+
* type Case2 = Extends<number, 1>
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
type NotExtends<T,Base>=Not<Extends<T,Base>>;
|
|
158
|
+
/**
|
|
159
|
+
* Returns the third argument if the first argument extends the second argument (defaults to `true`), otherwise returns the fourth argument (defaults to `false`)
|
|
160
|
+
* @example
|
|
161
|
+
* ```ts
|
|
162
|
+
* // 'valid'
|
|
163
|
+
* type Case1 = IfExtends<1, number, 'valid'>
|
|
164
|
+
* // 'invalid'
|
|
165
|
+
* type Case2 = IfExtends<1, string, 'valid', 'invalid'>
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
type IfExtends<T,Base,IfTrue=true,IfFalse=false>=If<Extends<T,Base>,IfTrue,IfFalse>;
|
|
169
|
+
/**
|
|
170
|
+
* Returns the third argument if the first argument doesn't extend the second argument (defaults to `true`), otherwise returns the fourth argument (defaults to `false`)
|
|
171
|
+
* @example
|
|
172
|
+
* ```ts
|
|
173
|
+
* // 'valid'
|
|
174
|
+
* type Case1 = IfExtends<1, string, 'valid'>
|
|
175
|
+
* // 'invalid'
|
|
176
|
+
* type Case2 = IfExtends<1, number, 'valid', 'invalid'>
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
type IfNotExtends<T,Base,IfTrue=true,IfFalse=false>=If<NotExtends<T,Base>,IfTrue,IfFalse>;
|
|
180
|
+
/**
|
|
181
|
+
* Returns boolean whether the every element of first array argument extend the second argument
|
|
182
|
+
* @example
|
|
183
|
+
* ```ts
|
|
184
|
+
* // true
|
|
185
|
+
* type Case1 = ExtendsArr<[1, 2, 3], number>
|
|
186
|
+
* // false
|
|
187
|
+
* type Case1 = ExtendsArr<[1, '2', 3], number>
|
|
188
|
+
* ```
|
|
189
|
+
*/
|
|
190
|
+
type ExtendsArr<T extends readonly unknown[],Base>=IsEmptyArray<T>extends true ? true:Pop<T,{includeRemoved:true;}>extends readonly [infer Rest extends readonly unknown[],infer Removed] ? Extends<Removed,Base>extends true ? ExtendsArr<Rest,Base>:false:false;
|
|
191
|
+
/**
|
|
192
|
+
* Returns result of logical multiplication of two params.
|
|
193
|
+
* @example
|
|
194
|
+
* ```ts
|
|
195
|
+
* // true
|
|
196
|
+
* type Case1 = And<true, true>
|
|
197
|
+
* // false
|
|
198
|
+
* type Case2 = And<false, true>
|
|
199
|
+
* ```
|
|
200
|
+
*/
|
|
201
|
+
type And<Condition1,Condition2>=IfExtends<Condition1,true,Extends<Condition2,true>>;
|
|
202
|
+
/**
|
|
203
|
+
* Returns result of logical multiplication of all elements inside the passed array type
|
|
204
|
+
* @example
|
|
205
|
+
* ```ts
|
|
206
|
+
* // true
|
|
207
|
+
* type Case1 = And<[true, true, true]>
|
|
208
|
+
* // false
|
|
209
|
+
* type Case2 = And<[true, true, false]>
|
|
210
|
+
* ```
|
|
211
|
+
*/
|
|
212
|
+
type AndArr<Conditions extends readonly unknown[]>=Extends<Conditions[number],true>;
|
|
213
|
+
/**
|
|
214
|
+
* Returns a boolean whether the passed argument is literal string
|
|
215
|
+
* @example
|
|
216
|
+
* ```ts
|
|
217
|
+
* // true
|
|
218
|
+
* type Case1 = IsStringLiteral<'a'>
|
|
219
|
+
* // false
|
|
220
|
+
* type Case2 = IsStringLiteral<string>
|
|
221
|
+
* ```
|
|
222
|
+
*/
|
|
223
|
+
type IsStringLiteral<T extends string>=string extends T ? false:true;
|
|
224
|
+
/**
|
|
225
|
+
* Returns the second argument if the first argument is `false` (defaults to `true`), otherwise returns the third argument (defaults to `false`)
|
|
226
|
+
* @example
|
|
227
|
+
* ```ts
|
|
228
|
+
* // valid
|
|
229
|
+
* type Case1 = IfNot<false, 'valid'>
|
|
230
|
+
* // invalid
|
|
231
|
+
* type Case2 = IfNot<false, 'valid', 'invalid'>
|
|
232
|
+
* ```
|
|
233
|
+
*/
|
|
234
|
+
type IfNot<Condition,IfTrue=true,IfFalse=false>=If<Condition,IfFalse,IfTrue>;type EmptyString<T extends string>="" extends T ? string extends T ? never:T:never;type NonEmptyString<T extends string>=string extends T ? string:If<IsNever<EmptyString<T>>,T,never>;type IsEmptyString<T extends string>=IfNot<IsNever<EmptyString<T>>>;type IsNonEmptyString<T extends string>=IfNot<IsNever<NonEmptyString<T>>>;type IfEmptyString<T extends string,IfTrue=true,IfFalse=false>=IfNot<IsNever<EmptyString<T>>,IfTrue,IfFalse>;type IfNonEmptyString<T extends string,IfTrue=true,IfFalse=false>=IfNot<IsNever<NonEmptyString<T>>,IfTrue,IfFalse>;type _AreAnagrams<Str1 extends string,Str2 extends string>=IsEmptyString<Str1>extends true ? IsEmptyString<Str2>extends true ? true:false:Str1 extends `${infer First extends string}${infer Rest1 extends string}` ? Str2 extends `${infer Prev extends string}${First}${infer Rest2 extends string}` ? _AreAnagrams<Rest1,`${Prev}${Rest2}`>:false:never;
|
|
235
|
+
/**
|
|
236
|
+
* Returns a boolean whether two passed string literals are anagrams
|
|
237
|
+
* @example
|
|
238
|
+
* ```ts
|
|
239
|
+
* // true
|
|
240
|
+
* type Case1 = AreAnagrams<"name", "eman">
|
|
241
|
+
* // false
|
|
242
|
+
* type Case1 = AreAnagrams<"name", "emand">
|
|
243
|
+
* ```
|
|
244
|
+
*/
|
|
245
|
+
type AreAnagrams<Str1 extends string,Str2 extends string>=And<IsStringLiteral<Str1>,IsStringLiteral<Str2>>extends true ? _AreAnagrams<Str1,Str2>:false;
|
|
246
|
+
/**
|
|
247
|
+
* Returns a boolean whether the passed type is `any`
|
|
248
|
+
* @example
|
|
249
|
+
* ```ts
|
|
250
|
+
* // true
|
|
251
|
+
* type Result = IsAny<any>
|
|
252
|
+
* ```
|
|
253
|
+
*/
|
|
254
|
+
type IsAny<T>=0 extends 1 & T ? true:false;
|
|
255
|
+
/**
|
|
256
|
+
* Returns the second argument if the first argument is `any` (defaults to `true`), otherwise returns the third argument (defaults to `false`)
|
|
257
|
+
* @example
|
|
258
|
+
* ```ts
|
|
259
|
+
* // string
|
|
260
|
+
* type Result = IfAny<any, string, number>
|
|
261
|
+
* ```
|
|
262
|
+
*/
|
|
263
|
+
type IfAny<T,IfTrue=true,IfFalse=false>=If<IsAny<T>,IfTrue,IfFalse>;type AnifyPropertiesOptions={makeOptional:boolean;};
|
|
264
|
+
/**
|
|
265
|
+
* Turns all properties of an object to type `any`.
|
|
266
|
+
* If `makeOptional` option is `true`, makes all properties optional
|
|
267
|
+
* @example
|
|
268
|
+
* ```ts
|
|
269
|
+
* // {a:any; b:any}
|
|
270
|
+
* type Result = AnifyProperties<{a: string; b: string}>
|
|
271
|
+
* ```
|
|
272
|
+
*/
|
|
273
|
+
type AnifyProperties<T extends object,Options extends AnifyPropertiesOptions={makeOptional:false;}>={[K in keyof T]:any;}extends infer Result ? If<Options["makeOptional"],Partial<Result>,Result>:never;
|
|
274
|
+
/**
|
|
275
|
+
* Returns the type of the element of the passed array argument
|
|
276
|
+
* @example
|
|
277
|
+
* ```ts
|
|
278
|
+
* // string
|
|
279
|
+
* type Case1 = ArrayElementType<string[]>
|
|
280
|
+
* // "a" | "b"
|
|
281
|
+
* type Case1 = ArrayElementType<readonly ("a" | "b")[]>
|
|
282
|
+
* ```
|
|
283
|
+
*/
|
|
284
|
+
type ArrayElementType<T extends readonly unknown[]>=T extends Readonly<Array<infer Item>>? Item:never;type LastCharacterOptions={includeRest:boolean;};type _LastCharacter<T extends string,Options extends LastCharacterOptions={includeRest:false;},Previous extends string="">=string extends T ? string:T extends `${infer First}${infer Rest}` ? IsEmptyString<Rest>extends true ? If<Options["includeRest"],[First,Previous],First>:_LastCharacter<Rest,Options,`${Previous}${First}`>:T;
|
|
285
|
+
/**
|
|
286
|
+
* Accepts a string argument and returns its first character.
|
|
287
|
+
* If the `includeRest` options is `true`, returns the first character and the rest of the string in the format of: [last, rest]
|
|
288
|
+
* @example
|
|
289
|
+
* ```ts
|
|
290
|
+
* // 'c'
|
|
291
|
+
* type Case1 = LastCharacter<'abc'>
|
|
292
|
+
* // ['c', 'ab']
|
|
293
|
+
* type Case2 = LastCharacter<'abc', {includeRest: true}>
|
|
294
|
+
* ```
|
|
295
|
+
*/
|
|
296
|
+
type LastCharacter<T extends string,Options extends LastCharacterOptions={includeRest:false;}>=_LastCharacter<T,Options>;type EvenDigit="0" | "2" | "4" | "6" | "8";type Integer<T extends number>=`${T}` extends `${string}.${string}` ? never:T;type Float<T extends number>=If<IsNever<Integer<T>>,T,never>;type Negative<T extends number>=`${T}` extends `-${string}` ? T:never;type Positive<T extends number>=If<IsNever<Negative<T>>,T,never>;type PositiveInteger<T extends number>=Positive<Integer<T>>;type NegativeInteger<T extends number>=Negative<Integer<T>>;type PositiveFloat<T extends number>=Positive<Float<T>>;type NegativeFloat<T extends number>=Negative<Float<T>>;type Even<T extends number>=IfNot<IsNever<Integer<T>>,`${T}` extends `${string}${EvenDigit}` ? T:never,never>;type Odd<T extends number>=IfNot<IsNever<Integer<T>>,If<IsNever<Even<T>>,T,never>,never>;type IsInteger<T extends number>=Not<IsNever<Integer<T>>>;type IsFloat<T extends number>=Not<IsNever<Float<T>>>;type IsEven<T extends number>=If<IsInteger<T>,`${T}` extends `${string}${EvenDigit}` ? true:false>;type IsOdd<T extends number>=If<IsInteger<T>,Not<IsEven<T>>>;type IsPositive<T extends number>=Not<IsNever<Positive<T>>>;type IsNegative<T extends number>=Not<IsNever<Negative<T>>>;type IsPositiveInteger<T extends number>=Not<IsNever<PositiveInteger<T>>>;type IsNegativeInteger<T extends number>=Not<IsNever<NegativeInteger<T>>>;type IsPositiveFloat<T extends number>=Not<IsNever<PositiveFloat<T>>>;type IsNegativeFloat<T extends number>=Not<IsNever<NegativeFloat<T>>>;type IfInteger<T extends number,IfTrue=true,IfFalse=false>=If<IsInteger<T>,IfTrue,IfFalse>;type IfFloat<T extends number,IfTrue=true,IfFalse=false>=If<IsFloat<T>,IfTrue,IfFalse>;type IfEven<T extends number,IfTrue=true,IfFalse=false>=If<IsEven<T>,IfTrue,IfFalse>;type IfOdd<T extends number,IfTrue=true,IfFalse=false>=If<IsOdd<T>,IfTrue,IfFalse>;type IfPositive<T extends number,IfTrue=true,IfFalse=false>=If<IsPositive<T>,IfTrue,IfFalse>;type IfNegative<T extends number,IfTrue=true,IfFalse=false>=If<IsNegative<T>,IfTrue,IfFalse>;type IfPositiveInteger<T extends number,IfTrue=true,IfFalse=false>=If<IsPositiveInteger<T>,IfTrue,IfFalse>;type IfNegativeInteger<T extends number,IfTrue=true,IfFalse=false>=If<IsNegativeInteger<T>,IfTrue,IfFalse>;type IfPositiveFloat<T extends number,IfTrue=true,IfFalse=false>=If<IsPositiveFloat<T>,IfTrue,IfFalse>;type IfNegativeFloat<T extends number,IfTrue=true,IfFalse=false>=If<IsNegativeFloat<T>,IfTrue,IfFalse>;type ParseNumber<T extends string | number>=T extends `${infer NumT extends number}` ? NumT:never;type Abs<T extends number>=`${T}` extends `-${infer PositiveT extends number}` ? PositiveT:T;type Negate<T extends number>=ParseNumber<`-${Abs<T>}`>;
|
|
297
|
+
/**
|
|
298
|
+
* Returns a boolean whether the first array argument is fixed length tuple
|
|
299
|
+
* @example
|
|
300
|
+
* ```ts
|
|
301
|
+
* // true
|
|
302
|
+
* type Case1 = IsTuple<[1, 2, 3]>
|
|
303
|
+
* // false
|
|
304
|
+
* type Case2 = IsTuple<number[]>
|
|
305
|
+
* ```
|
|
306
|
+
*/
|
|
307
|
+
type IsTuple<T extends readonly unknown[]>=NotExtends<number,T["length"]>;
|
|
308
|
+
/**
|
|
309
|
+
* Type version of `Array.prototype.join()`. Joins the first array argument by the second argument
|
|
310
|
+
* @example
|
|
311
|
+
* ```ts
|
|
312
|
+
* // 'a-p-p-l-e'
|
|
313
|
+
* type Case1 = Join<["a", "p", "p", "l", "e"], "-">
|
|
314
|
+
* // '21212'
|
|
315
|
+
* type Case2 = Join<["2", "2", "2"], 1>
|
|
316
|
+
* // 'o'
|
|
317
|
+
* type Case3 = Join<["o"], "u">
|
|
318
|
+
* ```
|
|
319
|
+
*/
|
|
320
|
+
type Join<T extends readonly(string | number)[],Glue extends string | number>=IsTuple<T>extends true ? T extends readonly [infer First extends string | number,...infer Rest extends readonly(string | number)[]] ? IfEmptyArray<Rest,First,`${First}${Glue}${Join<Rest,Glue>}`>:never:never;
|
|
321
|
+
/**
|
|
322
|
+
* Transform numbers, booleans, strings, bigints to string.
|
|
323
|
+
* ```ts
|
|
324
|
+
* // 'true'
|
|
325
|
+
* type Result = Stringify<true>
|
|
326
|
+
*
|
|
327
|
+
* ```
|
|
328
|
+
*/
|
|
329
|
+
type Stringify<T>=T extends number | boolean | string | bigint ? `${T}`:never;type DecrementMap=[-1,0,1,2,3,4,5,6,7,8];type NegativeCarryMap={"-1":9;};type _Decrement<Number extends string,Result extends string="">=Number extends "" ? ParseNumber<Result>:ParseNumber<LastCharacter<Number>>extends infer LastDigit extends number ? DecrementMap[LastDigit] extends infer Decremented extends number ? Number extends `${infer Rest}${LastDigit}` ? `${Decremented}` extends keyof NegativeCarryMap ? _Decrement<Rest,`${NegativeCarryMap[`${Decremented}`]}${Result}`>:`${Rest}${Decremented}${Result}` extends infer FinalResult extends string ? ParseNumber<FinalResult extends `0${infer FinalResultWithoutLeadingZero extends string}` ? FinalResultWithoutLeadingZero extends "" ? FinalResult:FinalResultWithoutLeadingZero:FinalResult>:never:never:never:never;type _DecrementNegativeOrZero<T extends number>=_Increment<Stringify<T>>extends infer PositiveDecrementResult extends number ? PositiveDecrementResult extends 0 ? PositiveDecrementResult:Negate<PositiveDecrementResult>:never;
|
|
330
|
+
/**
|
|
331
|
+
* Accepts an integer and returns the decremented value of it. Range: `[Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER]`
|
|
332
|
+
* @example
|
|
333
|
+
* ```ts
|
|
334
|
+
* // 5
|
|
335
|
+
* type Case1 = Decrement<6>
|
|
336
|
+
* // -7
|
|
337
|
+
* type Case2 = Decrement<-6>
|
|
338
|
+
* ```
|
|
339
|
+
*/
|
|
340
|
+
type Decrement<T extends number>=IsNegative<T>extends true ? _DecrementNegativeOrZero<Abs<T>>:T extends 0 ? _DecrementNegativeOrZero<T>:_Decrement<Stringify<T>>;type IncrementMap=[1,2,3,4,5,6,7,8,9,10];type LastDigitMap={10:0;};type _Increment<Number extends string,Result extends string="">=IsEmptyString<Number>extends true ? ParseNumber<`1${Result}`>:LastCharacter<Number>extends `${infer LastDigit extends number}` ? IncrementMap[LastDigit] extends infer Incremented extends number ? Number extends `${infer Rest}${LastDigit}` ? Incremented extends keyof LastDigitMap ? _Increment<Rest,`${LastDigitMap[Incremented]}${Result}`>:ParseNumber<`${Rest}${Incremented}${Result}`>:never:never:never;
|
|
341
|
+
/**
|
|
342
|
+
* Accepts an integer and returns the incremented value of it. Range: `[Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER]`
|
|
343
|
+
* @example
|
|
344
|
+
* ```ts
|
|
345
|
+
* // 2
|
|
346
|
+
* type Case1 = Increment<1>
|
|
347
|
+
* // -9
|
|
348
|
+
* type Case1 = Increment<-10>
|
|
349
|
+
* ```
|
|
350
|
+
*/
|
|
351
|
+
type Increment<T extends number>=IsNegative<T>extends true ? _Decrement<Stringify<Abs<T>>>extends infer NegativeIncrementResult extends number ? NegativeIncrementResult extends 0 ? NegativeIncrementResult:Negate<NegativeIncrementResult>:never:_Increment<Stringify<T>>;
|
|
352
|
+
/**
|
|
353
|
+
* Returns a tuple of whole and fraction part of the passed float number
|
|
354
|
+
* @example
|
|
355
|
+
* ```ts
|
|
356
|
+
* [12, 25]
|
|
357
|
+
* type Case1 = GetFloatNumberParts<12.25>
|
|
358
|
+
* [12, 25]
|
|
359
|
+
* type Case2 = GetFloatNumberParts<-12.25>
|
|
360
|
+
* ```
|
|
361
|
+
*/
|
|
362
|
+
type GetFloatNumberParts<T extends number>=IsFloat<T>extends true ? `${Abs<T>}` extends `${infer Whole extends number}.${infer Fraction extends number}` ? [Whole,Fraction]:never:never;
|
|
363
|
+
/**
|
|
364
|
+
* Type version of `Math.ceil()`. Returns ceiled value of the passed number
|
|
365
|
+
* @example
|
|
366
|
+
* ```ts
|
|
367
|
+
* // 2
|
|
368
|
+
* type Case1 = Ceil<1.2>
|
|
369
|
+
* // -1
|
|
370
|
+
* type Case2 = Ceil<-1.2>
|
|
371
|
+
* ```
|
|
372
|
+
*/
|
|
373
|
+
type Ceil<T extends number>=IsFloat<T>extends true ? GetFloatNumberParts<T>extends [infer Whole extends number,unknown] ? IsNegative<T>extends true ? Negate<Whole>:Increment<Whole>:never:T;
|
|
374
|
+
/**
|
|
375
|
+
* Returns a boolean whether the passed two arguments are equal
|
|
376
|
+
* @example
|
|
377
|
+
* ```ts
|
|
378
|
+
* // true
|
|
379
|
+
* type Case1 = IsEqual<string, string>
|
|
380
|
+
* // false
|
|
381
|
+
* type Case2 = IsEqual<1, 4>
|
|
382
|
+
* ```
|
|
383
|
+
*/
|
|
384
|
+
type IsEqual<T,U>=(<F>()=>F extends T ? 1:2)extends<F>()=>F extends U ? 1:2 ? true:false;
|
|
385
|
+
/**
|
|
386
|
+
* Returns a boolean whether the passed two arguments are not equal
|
|
387
|
+
* @example
|
|
388
|
+
* ```ts
|
|
389
|
+
* // true
|
|
390
|
+
* type Case1 = IsNotEqual<1, 4>
|
|
391
|
+
* // false
|
|
392
|
+
* type Case2 = IsNotEqual<string, string>
|
|
393
|
+
* ```
|
|
394
|
+
*/
|
|
395
|
+
type IsNotEqual<T,U>=Not<IsEqual<T,U>>;
|
|
396
|
+
/**
|
|
397
|
+
* Accepts two types and returns the third argument if the first two are equal (defaults to `true`), otherwise returns the fourth argument (defaults to `false`)
|
|
398
|
+
* @example
|
|
399
|
+
* ```ts
|
|
400
|
+
* // 'valid'
|
|
401
|
+
* type Case1 = IfEqual<string, string, 'valid'>
|
|
402
|
+
* // 'invalid'
|
|
403
|
+
* type Case1 = IfEqual<1, 4, 'valid', 'invalid'>
|
|
404
|
+
* ```
|
|
405
|
+
*/
|
|
406
|
+
type IfEqual<T,U,IfTrue=true,IfFalse=false>=If<IsEqual<T,U>,IfTrue,IfFalse>;
|
|
407
|
+
/**
|
|
408
|
+
* Accepts two types and returns the third argument if the first two are not equal (defaults to `true`), otherwise returns the fourth argument (defaults to `false`)
|
|
409
|
+
* @example
|
|
410
|
+
* ```ts
|
|
411
|
+
* // 'valid'
|
|
412
|
+
* type Case1 = IfNotEqual<1, 4, 'valid'>
|
|
413
|
+
* // 'invalid'
|
|
414
|
+
* type Case1 = IfNotEqual<string, string, 'valid', 'invalid'>
|
|
415
|
+
* ```
|
|
416
|
+
*/
|
|
417
|
+
type IfNotEqual<T,U,IfTrue=true,IfFalse=false>=If<IsNotEqual<T,U>,IfTrue,IfFalse>;
|
|
418
|
+
/**
|
|
419
|
+
* Accepts a string and removes leading characters specified in the second argument
|
|
420
|
+
* @example
|
|
421
|
+
* ```ts
|
|
422
|
+
* // 'bc'
|
|
423
|
+
* type Case1 = RemoveLeading<'aaabc', 'a'>
|
|
424
|
+
* // 'abc'
|
|
425
|
+
* type Case2 = RemoveLeading<'abc', 'd'>
|
|
426
|
+
* // ''
|
|
427
|
+
* type Case3 = RemoveLeading<'aaa', 'a'>
|
|
428
|
+
* // 'a'
|
|
429
|
+
* type Case3 = RemoveLeading<'aaa', 'aa'>
|
|
430
|
+
* ```
|
|
431
|
+
*/
|
|
432
|
+
type RemoveLeading<T extends string,Characters extends string>=T extends `${Characters}${infer Rest extends string}` ? IsEmptyString<Rest>extends true ? Rest:RemoveLeading<Rest,Characters>:T;type SubDecrementMap={"-9":-10;"-8":-9;"-7":-8;"-6":-7;"-5":-6;"-4":-5;"-3":-4;"-2":-3;"-1":-2;"0":-1;"1":0;"2":1;"3":2;"4":3;"5":4;"6":5;"7":6;"8":7;"9":8;};type SubNegativeCarryMap={"-10":0;"-9":1;"-8":2;"-7":3;"-6":4;"-5":5;"-4":6;"-3":7;"-2":8;"-1":9;};type SubMap={0:[0,-1,-2,-3,-4,-5,-6,-7,-8,-9];1:[1,0,-1,-2,-3,-4,-5,-6,-7,-8];2:[2,1,0,-1,-2,-3,-4,-5,-6,-7];3:[3,2,1,0,-1,-2,-3,-4,-5,-6];4:[4,3,2,1,0,-1,-2,-3,-4,-5];5:[5,4,3,2,1,0,-1,-2,-3,-4];6:[6,5,4,3,2,1,0,-1,-2,-3];7:[7,6,5,4,3,2,1,0,-1,-2];8:[8,7,6,5,4,3,2,1,0,-1];9:[9,8,7,6,5,4,3,2,1,0];};type _RemoveLeadingZeros<T extends string>=ParseNumber<RemoveLeading<T,"0">extends infer WithoutLeadingZeros extends string ? IfEmptyString<WithoutLeadingZeros,"0",WithoutLeadingZeros>:never>;type _Sub<Num1 extends string,Num2 extends string,NegativeCarry extends 0 | 1=0,Result extends string="">=IsEmptyString<Num2>extends true ? NegativeCarry extends 0 ? `${Num1}${Result}`:`${Decrement<ParseNumber<Num1>>}${Result}`:LastCharacter<Num1>extends `${infer Num1LastDigit extends keyof SubMap & number}` ? LastCharacter<Num2>extends `${infer Num2LastDigit extends keyof SubMap[Num1LastDigit] & number}` ? `${SubMap[Num1LastDigit][Num2LastDigit]}` extends infer DigitsSub extends keyof SubDecrementMap ?(NegativeCarry extends 1 ? Stringify<SubDecrementMap[DigitsSub]>:DigitsSub)extends infer DigitsSubWithCarry extends string ? Num1 extends `${infer Num1Rest}${Num1LastDigit}` ? Num2 extends `${infer Num2Rest}${Num2LastDigit}` ? DigitsSubWithCarry extends keyof SubNegativeCarryMap ? _Sub<Num1Rest,Num2Rest,1,`${SubNegativeCarryMap[DigitsSubWithCarry]}${Result}`>:_Sub<Num1Rest,Num2Rest,0,`${DigitsSubWithCarry}${Result}`>:never:never:never:never:never:never;
|
|
433
|
+
/**
|
|
434
|
+
* Accepts two integers and returns their subtraction. Range: `[Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER]`
|
|
435
|
+
* @example
|
|
436
|
+
* ```ts
|
|
437
|
+
* // 8
|
|
438
|
+
* type Case1 = Sub<10, 2>
|
|
439
|
+
* // -8
|
|
440
|
+
* type Case2 = Sub<2, 10>
|
|
441
|
+
* // 12
|
|
442
|
+
* type Case3 = Sub<2, -10>
|
|
443
|
+
* // -12
|
|
444
|
+
* type Case4 = Sub<-2, 10>
|
|
445
|
+
* ```
|
|
446
|
+
*/
|
|
447
|
+
type Sub<Num1 extends number,Num2 extends number>=IsNegativeInteger<Num1>extends true ? IsNegativeInteger<Num2>extends true ? IsLowerThan<Num1,Num2>extends true ? Negate<_RemoveLeadingZeros<_Sub<Stringify<Abs<Num1>>,Stringify<Abs<Num2>>>>>:_RemoveLeadingZeros<_Sub<Stringify<Abs<Num2>>,Stringify<Abs<Num1>>>>:Sum<Abs<Num1>,Num2>extends infer Result extends number ? Negate<Result>:never:IsNegativeInteger<Num2>extends true ? Sum<Num1,Abs<Num2>>:IsLowerThan<Num1,Num2>extends true ? Negate<_RemoveLeadingZeros<_Sub<Stringify<Num2>,Stringify<Num1>>>>:_RemoveLeadingZeros<_Sub<Stringify<Num1>,Stringify<Num2>>>;type SumIncrementMap=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19];type SumLastDigitMap={10:0;11:1;12:2;13:3;14:4;15:5;16:6;17:7;18:8;19:9;};type SumMap={0:[0,1,2,3,4,5,6,7,8,9];1:[1,2,3,4,5,6,7,8,9,10];2:[2,3,4,5,6,7,8,9,10,11];3:[3,4,5,6,7,8,9,10,11,12];4:[4,5,6,7,8,9,10,11,12,13];5:[5,6,7,8,9,10,11,12,13,14];6:[6,7,8,9,10,11,12,13,14,15];7:[7,8,9,10,11,12,13,14,15,16];8:[8,9,10,11,12,13,14,15,16,17];9:[9,10,11,12,13,14,15,16,17,18];};type _Sum<Num1 extends string,Num2 extends string,Carry extends 0 | 1=0,Result extends string="">=IsEmptyString<Num1>extends true ? Carry extends 0 ? ParseNumber<`${Num2}${Result}`>:_Increment<Num2,Result>:IsEmptyString<Num2>extends true ? Carry extends 0 ? ParseNumber<`${Num1}${Result}`>:_Increment<Num1,Result>:LastCharacter<Num1>extends `${infer Num1LastDigit extends keyof SumMap & number}` ? LastCharacter<Num2>extends `${infer Num2LastDigit extends keyof SumMap[Num1LastDigit] & number}` ? SumMap[Num1LastDigit][Num2LastDigit] extends infer DigitsSum extends number ?(Carry extends 1 ? SumIncrementMap[DigitsSum]:DigitsSum)extends infer DigitsSumWithCarry extends number ? Num1 extends `${infer Num1Rest}${Num1LastDigit}` ? Num2 extends `${infer Num2Rest}${Num2LastDigit}` ? DigitsSumWithCarry extends keyof SumLastDigitMap ? _Sum<Num1Rest,Num2Rest,1,`${SumLastDigitMap[DigitsSumWithCarry]}${Result}`>:_Sum<Num1Rest,Num2Rest,0,`${DigitsSumWithCarry}${Result}`>:never:never:never:never:never:never;
|
|
448
|
+
/**
|
|
449
|
+
* Accepts two integers and returns their sum. Range: `[Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER]`
|
|
450
|
+
* @example
|
|
451
|
+
* ```ts
|
|
452
|
+
* // 13
|
|
453
|
+
* type Case1 = Sum<4, 9>
|
|
454
|
+
* // 5
|
|
455
|
+
* type Case2 = Sum<-4, 9>
|
|
456
|
+
* // -5
|
|
457
|
+
* type Case3 = Sum<4, -9>
|
|
458
|
+
* // -13
|
|
459
|
+
* type Case4 = Sum<-4, -9>
|
|
460
|
+
* ```
|
|
461
|
+
*/
|
|
462
|
+
type Sum<Num1 extends number,Num2 extends number>=IsNegativeInteger<Num1>extends true ? IsNegativeInteger<Num2>extends true ? Negate<_Sum<Stringify<Abs<Num1>>,Stringify<Abs<Num2>>>>:Sub<Num2,Abs<Num1>>:IsNegativeInteger<Num2>extends true ? Sub<Num1,Abs<Num2>>:_Sum<Stringify<Num1>,Stringify<Num2>>;type _SumArr<T extends readonly number[],CurrentSum extends number=0>=IsEmptyArray<T>extends true ? CurrentSum:Pop<T,{includeRemoved:true;}>extends infer PopResult ? IsNever<PopResult>extends true ? CurrentSum:PopResult extends [infer Rest extends number[],infer Num1 extends number] ? _SumArr<Rest,Sum<CurrentSum,Num1>>:never:CurrentSum;
|
|
463
|
+
/**
|
|
464
|
+
* Accepts an array of integers and returns the sum of its elements. Range: `[Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER]`
|
|
465
|
+
* @example
|
|
466
|
+
* ```ts
|
|
467
|
+
* // 10
|
|
468
|
+
* type Case1 = SumArr<[1, 2, 3, 4]>
|
|
469
|
+
* // 2
|
|
470
|
+
* type Case2 = SumArr<[1, 2, 3, -4]>
|
|
471
|
+
* ```
|
|
472
|
+
*/
|
|
473
|
+
type SumArr<T extends readonly number[]>=IsTuple<T>extends true ? _SumArr<T>:never;type _StringLength<S extends string,Parts extends [string[],string[],string[],string[]]=[[],[],[],[]]>=S extends "" ? Sum<Sum<Parts[0]["length"],Parts[1]["length"]>,Sum<Parts[2]["length"],Parts[3]["length"]>>:S extends `${infer C1 extends string}${infer Rest1 extends string}` ? Rest1 extends `${infer C2 extends string}${infer Rest2 extends string}` ? Rest2 extends `${infer C3 extends string}${infer Rest3 extends string}` ? Rest3 extends `${infer C4 extends string}${infer Rest4 extends string}` ? _StringLength<Rest4,[[...Parts[0],C1],[...Parts[1],C2],[...Parts[2],C3],[...Parts[3],C4]]>:_StringLength<Rest3,[[...Parts[0],C1],[...Parts[1],C2],[...Parts[2],C3],Parts[3]]>:_StringLength<Rest2,[[...Parts[0],C1],[...Parts[1],C2],Parts[2],Parts[3]]>:_StringLength<Rest1,[[...Parts[0],C1],Parts[1],Parts[2],Parts[3]]>:_StringLength<S,Parts>;
|
|
474
|
+
/**
|
|
475
|
+
* Returns the length of the passed string. Range of string length `[0, 3968]`
|
|
476
|
+
* @example
|
|
477
|
+
* ```ts
|
|
478
|
+
* // 0
|
|
479
|
+
* type Case1 = StringLength<''>
|
|
480
|
+
* // 3
|
|
481
|
+
* type Case2 = StringLength<'xxx'>
|
|
482
|
+
* ```
|
|
483
|
+
*/
|
|
484
|
+
type StringLength<S extends string>=_StringLength<S>;
|
|
485
|
+
/**
|
|
486
|
+
* Accepts two strings, returns the third argument (defaults to `never`) if the first string is shorter, otherwise returns the fourth argument (defaults to `never`) if the second argument is shorter, if strings have the same length returns the fifth argument (defaults to `never`)
|
|
487
|
+
* @example
|
|
488
|
+
* ```ts
|
|
489
|
+
* // 'first shorter'
|
|
490
|
+
* type Case1 = CompareStringLength<'a', 'ab', 'first shorter'>
|
|
491
|
+
* // 'first longer'
|
|
492
|
+
* type Case2 = CompareStringLength<'abc', 'ab', 'first shorter', 'first longer'>
|
|
493
|
+
* // 'equal'
|
|
494
|
+
* type Case3 = CompareStringLength<'ab', 'ab', 'first shorter', 'first longer', 'equal'>
|
|
495
|
+
* ```
|
|
496
|
+
*/
|
|
497
|
+
type CompareStringLength<Str1 extends string,Str2 extends string,IfStr1Shorter=never,IfStr2Shorter=never,IfEqual=never>=IsEmptyString<Str1>extends true ? IsEmptyString<Str2>extends true ? IfEqual:IfStr1Shorter:IsEmptyString<Str2>extends true ? IfStr2Shorter:Str1 extends `${string}${infer Str1Rest extends string}` ? Str2 extends `${string}${infer Str2Rest extends string}` ? CompareStringLength<Str1Rest,Str2Rest,IfStr1Shorter,IfStr2Shorter,IfEqual>:never:never;
|
|
498
|
+
/**
|
|
499
|
+
* Accepts two strings, returns a boolean whether the first string is shorter
|
|
500
|
+
* @example
|
|
501
|
+
* ```ts
|
|
502
|
+
* // true
|
|
503
|
+
* type Case1 = IsShorterString<'a', 'ab'>
|
|
504
|
+
* // false
|
|
505
|
+
* type Case2 = IsShorterString<'abc', 'ab'>
|
|
506
|
+
* ```
|
|
507
|
+
*/
|
|
508
|
+
type IsShorterString<Str1 extends string,Str2 extends string>=CompareStringLength<Str1,Str2,true,false,false>;
|
|
509
|
+
/**
|
|
510
|
+
* Accepts two strings, returns a boolean whether the first string is longer
|
|
511
|
+
* @example
|
|
512
|
+
* ```ts
|
|
513
|
+
* // true
|
|
514
|
+
* type Case1 = IsLongerString<'ab', 'a'>
|
|
515
|
+
* // false
|
|
516
|
+
* type Case2 = IsLongerString<'a', 'ab'>
|
|
517
|
+
* ```
|
|
518
|
+
*/
|
|
519
|
+
type IsLongerString<Str1 extends string,Str2 extends string>=CompareStringLength<Str1,Str2,false,true,false>;
|
|
520
|
+
/**
|
|
521
|
+
* Accepts two strings, returns a boolean whether strings have the same length
|
|
522
|
+
* @example
|
|
523
|
+
* ```ts
|
|
524
|
+
* // true
|
|
525
|
+
* type Case1 = IsSameLengthString<'ab', 'ab'>
|
|
526
|
+
* // false
|
|
527
|
+
* type Case2 = IsSameLengthString<'ab', 'abc'>
|
|
528
|
+
* ```
|
|
529
|
+
*/
|
|
530
|
+
type IsSameLengthString<Str1 extends string,Str2 extends string>=CompareStringLength<Str1,Str2,false,false,true>;
|
|
531
|
+
/**
|
|
532
|
+
* Returns number of digits of the passed number
|
|
533
|
+
* @example
|
|
534
|
+
* ```ts
|
|
535
|
+
* // 3
|
|
536
|
+
* type Case1 = NumberLength<100>
|
|
537
|
+
* // 15
|
|
538
|
+
* type Case2 = NumberLength<100000000000000>
|
|
539
|
+
* ```
|
|
540
|
+
*/
|
|
541
|
+
type NumberLength<T extends number>=StringLength<Stringify<T>>;
|
|
542
|
+
/**
|
|
543
|
+
* Accepts two numbers, returns the third argument (defaults to `never`) if the first number is shorter, otherwise returns the fourth argument (defaults to `never`) if the second argument is shorter, if numbers have the same length returns the fifth argument (defaults to `never`)
|
|
544
|
+
* @example
|
|
545
|
+
* ```ts
|
|
546
|
+
* // 'first shorter'
|
|
547
|
+
* type Case1 = CompareNumberLength<1, 12, 'first shorter'>
|
|
548
|
+
* // 'first longer'
|
|
549
|
+
* type Case2 = CompareNumberLength<123, 12, 'first shorter', 'first longer'>
|
|
550
|
+
* // 'equal'
|
|
551
|
+
* type Case3 = CompareNumberLength<12, 12, 'first shorter', 'first longer', 'equal'>
|
|
552
|
+
* ```
|
|
553
|
+
*/
|
|
554
|
+
type CompareNumberLength<Num1 extends number,Num2 extends number,IfNum1Shorter=never,IfNum2Shorter=never,IfEqual=never>=CompareStringLength<Stringify<Num1>,Stringify<Num2>,IfNum1Shorter,IfNum2Shorter,IfEqual>;
|
|
555
|
+
/**
|
|
556
|
+
* Accepts two numbers, returns a boolean whether the first number is shorter
|
|
557
|
+
* @example
|
|
558
|
+
* ```ts
|
|
559
|
+
* // true
|
|
560
|
+
* type Case1 = IsShorterNumber<1, 10>
|
|
561
|
+
* // false
|
|
562
|
+
* type Case2 = IsShorterNumber<100, 10>
|
|
563
|
+
* ```
|
|
564
|
+
*/
|
|
565
|
+
type IsShorterNumber<Num1 extends number,Num2 extends number>=CompareNumberLength<Num1,Num2,true,false,false>;
|
|
566
|
+
/**
|
|
567
|
+
* Accepts two numbers, returns a boolean whether the first number is longer
|
|
568
|
+
* @example
|
|
569
|
+
* ```ts
|
|
570
|
+
* // true
|
|
571
|
+
* type Case1 = IsLongerNumber<10, 1>
|
|
572
|
+
* // false
|
|
573
|
+
* type Case2 = IsLongerNumber<10, 100>
|
|
574
|
+
* ```
|
|
575
|
+
*/
|
|
576
|
+
type IsLongerNumber<Num1 extends number,Num2 extends number>=CompareNumberLength<Num1,Num2,false,true,false>;
|
|
577
|
+
/**
|
|
578
|
+
* Accepts two numbers, returns a boolean whether numbers have the same length
|
|
579
|
+
* @example
|
|
580
|
+
* ```ts
|
|
581
|
+
* // true
|
|
582
|
+
* type Case1 = IsSameLengthNumber<10, 10>
|
|
583
|
+
* // false
|
|
584
|
+
* type Case2 = IsSameLengthNumber<10, 100>
|
|
585
|
+
* ```
|
|
586
|
+
*/
|
|
587
|
+
type IsSameLengthNumber<Num1 extends number,Num2 extends number>=CompareNumberLength<Num1,Num2,false,false,true>;type LowerThanMap={"0":["1","2","3","4","5","6","7","8","9"];"1":["2","3","4","5","6","7","8","9"];"2":["3","4","5","6","7","8","9"];"3":["4","5","6","7","8","9"];"4":["5","6","7","8","9"];"5":["6","7","8","9"];"6":["7","8","9"];"7":["8","9"];"8":["9"];"9":[];};type _IsLowerThan<Num1 extends string,Num2 extends string>=Num1 extends `${infer Num1Character extends keyof LowerThanMap}${infer Num1Rest extends string}` ? Num2 extends `${infer Num2Character extends string}${infer Num2Rest extends string}` ? IsEqual<Num1Character,Num2Character>extends true ? _IsLowerThan<Num1Rest,Num2Rest>:Num2Character extends LowerThanMap[Num1Character][number] ? true:false:true:false;
|
|
588
|
+
/**
|
|
589
|
+
* Returns a boolean whether the first passed integer is lower than the second integer. Range: `[Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER]`
|
|
590
|
+
* @example
|
|
591
|
+
* ```ts
|
|
592
|
+
* // true
|
|
593
|
+
* type Case1 = IsLowerThan<1, 10>
|
|
594
|
+
* // false
|
|
595
|
+
* type Case2 = IsLowerThan<1, -10>
|
|
596
|
+
* ```
|
|
597
|
+
*/
|
|
598
|
+
type IsLowerThan<Num1 extends number,Num2 extends number>=IsEqual<Num1,Num2>extends true ? false:IsNegative<Num1>extends true ? IsNegative<Num2>extends false ? true:CompareNumberLength<Num1,Num2,false,true,Not<_IsLowerThan<Stringify<Abs<Num1>>,Stringify<Abs<Num2>>>>>:IsNegative<Num2>extends true ? false:CompareNumberLength<Num1,Num2,true,false,_IsLowerThan<Stringify<Abs<Num1>>,Stringify<Abs<Num2>>>>;
|
|
599
|
+
/**
|
|
600
|
+
* Returns a boolean whether the first passed integer is lower than the second integer. Range: `[Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER]`
|
|
601
|
+
* @example
|
|
602
|
+
* ```ts
|
|
603
|
+
* // 'valid'
|
|
604
|
+
* type Case1 = IfLowerThan<1, 10, 'valid'>
|
|
605
|
+
* // 'invalid'
|
|
606
|
+
* type Case2 = IfLowerThan<1, -10, 'valid', 'invalid'>
|
|
607
|
+
* ```
|
|
608
|
+
*/
|
|
609
|
+
type IfLowerThan<Num1 extends number,Num2 extends number,IfTrue=true,IfFalse=false>=If<IsLowerThan<Num1,Num2>,IfTrue,IfFalse>;type IsLowerOrEqual<Num1 extends number,Num2 extends number>=IsEqual<Num1,Num2>extends true ? true:IsLowerThan<Num1,Num2>;
|
|
610
|
+
/**
|
|
611
|
+
* Returns a boolean whether the first passed integer is greater than the second integer. Range: `[Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER]`
|
|
612
|
+
* @example
|
|
613
|
+
* ```ts
|
|
614
|
+
* // true
|
|
615
|
+
* type Case1 = IsGreaterThan<10, 1>
|
|
616
|
+
* // false
|
|
617
|
+
* type Case2 = IsGreaterThan<-10, 1>
|
|
618
|
+
* ```
|
|
619
|
+
*/
|
|
620
|
+
type IsGreaterThan<Num1 extends number,Num2 extends number>=IsLowerThan<Num2,Num1>;
|
|
621
|
+
/**
|
|
622
|
+
* Returns the third argument if the first argument (integer) is greater than the second argument (integer) (defaults to `true`), otherwise returns the fourth argument (defaults to `false`). Range: `[Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER]`
|
|
623
|
+
* @example
|
|
624
|
+
* ```ts
|
|
625
|
+
* 'valid'
|
|
626
|
+
* type Case1 = IfGreaterThan<10, 1, 'valid'>
|
|
627
|
+
* // 'invalid'
|
|
628
|
+
* type Case2 = IfGreaterThan<-10, 1, 'valid', 'invalid'>
|
|
629
|
+
* ```
|
|
630
|
+
*/
|
|
631
|
+
type IfGreaterThan<Num1 extends number,Num2 extends number,IfTrue=true,IfFalse=false>=IfLowerThan<Num2,Num1,IfTrue,IfFalse>;
|
|
632
|
+
/**
|
|
633
|
+
* Returns a boolean whether the first passed integer is greater than the second integer or equal. Range: `[Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER]`
|
|
634
|
+
* @example
|
|
635
|
+
* ```ts
|
|
636
|
+
* // true
|
|
637
|
+
* type Case1 = IsGreaterThan<10, 1>
|
|
638
|
+
* // false
|
|
639
|
+
* type Case2 = IsGreaterThan<-10, 1>
|
|
640
|
+
* // true
|
|
641
|
+
* type Case3 = IsGreaterThan<10, 10>
|
|
642
|
+
* ```
|
|
643
|
+
*/
|
|
644
|
+
type IsGreaterOrEqual<Num1 extends number,Num2 extends number>=IsEqual<Num1,Num2>extends true ? true:IsGreaterThan<Num1,Num2>;
|
|
645
|
+
/**
|
|
646
|
+
* Returns the third argument if the first argument (integer) is greater than the second argument (integer) or equal (defaults to `true`), otherwise returns the fourth argument (defaults to `false`). Range: `[Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER]`
|
|
647
|
+
* @example
|
|
648
|
+
* ```ts
|
|
649
|
+
* 'valid'
|
|
650
|
+
* type Case1 = IfGreaterThan<10, 1, 'valid'>
|
|
651
|
+
* // 'invalid'
|
|
652
|
+
* type Case2 = IfGreaterThan<-10, 1, 'valid', 'invalid'>
|
|
653
|
+
* ```
|
|
654
|
+
*/
|
|
655
|
+
type IfGreaterOrEqual<Num1 extends number,Num2 extends number,IfTrue=true,IfFalse=false>=If<IsEqual<Num1,Num2>extends true ? true:IsGreaterThan<Num1,Num2>,IfTrue,IfFalse>;type IsBetweenOptions={minIncluded?:boolean;maxIncluded?:boolean;};
|
|
656
|
+
/**
|
|
657
|
+
* Returns a boolean whether the first integer argument is between the second and the third integer argument
|
|
658
|
+
* By default borders of the interval are included, which can be modified by the second argument.
|
|
659
|
+
* `minIncluded`, `maxIncluded` options show whether to include the lower and the higher borders respectively. Range: `[Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER]`
|
|
660
|
+
* @example
|
|
661
|
+
* ```ts
|
|
662
|
+
* // true
|
|
663
|
+
* type Case1 = IsBetween<1, 1, 10>
|
|
664
|
+
* // false
|
|
665
|
+
* type Case2 = IsBetween<1, 1, 10, {minIncluded: false}>
|
|
666
|
+
* // false
|
|
667
|
+
* type Case3 = IsBetween<10, 1, 10, {maxIncluded: false}>
|
|
668
|
+
* ```
|
|
669
|
+
*/
|
|
670
|
+
type IsBetween<Num extends number,Min extends number,Max extends number,Options extends IsBetweenOptions={minIncluded:true;maxIncluded:true;}>=IsEqual<Num,Min>extends true ? Options["minIncluded"]:IsEqual<Num,Max>extends true ? Options["maxIncluded"]:And<IsGreaterThan<Num,Min>,IsLowerThan<Num,Max>>;
|
|
671
|
+
/**
|
|
672
|
+
* Type version of `String.prototype.split()`. Splits the first string argument by the second string argument
|
|
673
|
+
* @example
|
|
674
|
+
* ```ts
|
|
675
|
+
* // ['a', 'b', 'c']
|
|
676
|
+
* type Case1 = Split<'abc', ''>
|
|
677
|
+
* // ['a', 'b', 'c']
|
|
678
|
+
* type Case2 = Split<'a,b,c', ','>
|
|
679
|
+
* ```
|
|
680
|
+
*/
|
|
681
|
+
type Split<Str extends string,Del extends string | number>=string extends Str ? string[]:"" extends Str ? []:Str extends `${infer T}${Del}${infer U}` ? [T,...Split<U,Del>]:[Str];type _IsValidRGBParameter<T extends number>=IsInteger<T>extends true ? IsBetween<T,0,255>:false;type RGBOptions={separator:string;};type DefaultRGBOptions={separator:",";};
|
|
682
|
+
/**
|
|
683
|
+
* Returns the first string argument if it is a valid RGB color, otherwise returns `never`.
|
|
684
|
+
* The second argument is an object type with `separator: string` property, which shows the separator between color parameters (defaults to `', '`)
|
|
685
|
+
* @example
|
|
686
|
+
* ```ts
|
|
687
|
+
* // rgb(23, 242, 0)
|
|
688
|
+
* type Case1 = RGB<'rgb(23, 242, 0)'>
|
|
689
|
+
* // never
|
|
690
|
+
* type Case2 = RGB<'rgb(324, 123, 3)'>
|
|
691
|
+
* // rgb(23,242,0)
|
|
692
|
+
* type Case3 = RGB<'rgb(23,242,0)', { separator: ',' }>
|
|
693
|
+
* ```
|
|
694
|
+
*/
|
|
695
|
+
type RGB<T extends string,Options extends RGBOptions=DefaultRGBOptions>=T extends `rgb(${infer R extends number}${Options["separator"]}${infer G extends number}${Options["separator"]}${infer B extends number})` ? AndArr<[_IsValidRGBParameter<R>,_IsValidRGBParameter<G>,_IsValidRGBParameter<B>]>extends true ? T:never:never;
|
|
696
|
+
/**
|
|
697
|
+
* Returns a boolean whether the first string argument is a valid RGB color.
|
|
698
|
+
* The second argument is an object type with `separator: string` property, which shows the separator between color parameters (defaults to `', '`)
|
|
699
|
+
* @example
|
|
700
|
+
* ```ts
|
|
701
|
+
* // true
|
|
702
|
+
* type Case1 = IsRGB<'rgb(23, 242, 0)'>
|
|
703
|
+
* // false
|
|
704
|
+
* type Case2 = IsRGB<'rgb(324, 123, 3)'>
|
|
705
|
+
* // true
|
|
706
|
+
* type Case3 = IsRGB<'rgb(23,242,0)', { separator: ',' }>
|
|
707
|
+
* ```
|
|
708
|
+
*/
|
|
709
|
+
type IsRGB<T extends string,Options extends RGBOptions=DefaultRGBOptions>=Not<IsNever<RGB<T,Options>>>;
|
|
710
|
+
/**
|
|
711
|
+
* Returns the third argument if the first argument is valid RGB color (defaults to `true`), otherwise returns the fourth argument (defaults to `false`)
|
|
712
|
+
* The second argument is an object type with `separator: string` property, which shows the separator between color parameters (defaults to `', '`)
|
|
713
|
+
* @example
|
|
714
|
+
* ```ts
|
|
715
|
+
* // 'true'
|
|
716
|
+
* type Case1 = IfRGB<'rgb(23, 242, 0)', 'true'>
|
|
717
|
+
* // 'invalid'
|
|
718
|
+
* type Case2 = IfRGB<'rgb(324, 123, 3)', 'valid', 'invalid'>
|
|
719
|
+
* // true
|
|
720
|
+
* type Case3 = IfRGB<'rgb(23,242,0)', { separator: ',' }>
|
|
721
|
+
* ```
|
|
722
|
+
*/
|
|
723
|
+
type IfRGB<T extends string,Options extends RGBOptions=DefaultRGBOptions,IfTrue=true,IfFalse=false>=If<IsRGB<T,Options>,IfTrue,IfFalse>;type _ValidHEXCharacters=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"];type _AllowedHEXLength=3 | 4 | 6 | 8;
|
|
724
|
+
/**
|
|
725
|
+
* Returns the first string argument if it is a valid HEX color, otherwise returns `never`
|
|
726
|
+
* @example
|
|
727
|
+
* // '#000'
|
|
728
|
+
* type Case1 = HEX<'#000'>
|
|
729
|
+
* // never
|
|
730
|
+
* type Case2 = HEX<'#g00'>
|
|
731
|
+
* // '#0000'
|
|
732
|
+
* type Case3 = HEX<'#0000'>
|
|
733
|
+
* // never
|
|
734
|
+
* type Case4 = HEX<'#00000'>
|
|
735
|
+
* // '#000000'
|
|
736
|
+
* type Case5 = HEX<'#000000'>
|
|
737
|
+
* // '#00000000'
|
|
738
|
+
* type Case6 = HEX<'#00000000'>
|
|
739
|
+
*/
|
|
740
|
+
type HEX<T extends string>=(Uppercase<T>extends `#${infer HEXWithoutHashTag extends string}` ? StringLength<HEXWithoutHashTag>extends _AllowedHEXLength ? ExtendsArr<Split<HEXWithoutHashTag,"">,_ValidHEXCharacters[number]>:false:false)extends true ? T:never;
|
|
741
|
+
/**
|
|
742
|
+
* Returns a boolean whether the first string argument is a valid HEX color.
|
|
743
|
+
* @example
|
|
744
|
+
* ```ts
|
|
745
|
+
* // true
|
|
746
|
+
* type Case1 = IsHEX<'#000'>
|
|
747
|
+
* // false
|
|
748
|
+
* type Case2 = IsHEX<'#g00'>
|
|
749
|
+
* ```
|
|
750
|
+
*/
|
|
751
|
+
type IsHEX<T extends string>=Not<IsNever<HEX<T>>>;
|
|
752
|
+
/**
|
|
753
|
+
* Returns the second argument if the first argument is valid HEX color (defaults to `true`), otherwise returns the third argument (defaults to `false`)
|
|
754
|
+
* @example
|
|
755
|
+
* ```ts
|
|
756
|
+
* // true
|
|
757
|
+
* type Case1 = IfHEX<'#000'>
|
|
758
|
+
* // false
|
|
759
|
+
* type Case2 = IfHEX<'#g00'>
|
|
760
|
+
* // 'valid'
|
|
761
|
+
* type Case3 = IfHEX<'#0000', 'valid'>
|
|
762
|
+
* // 'invalid'
|
|
763
|
+
* type Case4 = IfHEX<'#00000', 'valid', 'invalid'>
|
|
764
|
+
* ```
|
|
765
|
+
*/
|
|
766
|
+
type IfHEX<T extends string,IfTrue=true,IfFalse=false>=If<IsHEX<T>,IfTrue,IfFalse>;type HSLOptions={separator:string;};type DefaultHSLOptions={separator:",";};
|
|
767
|
+
/**
|
|
768
|
+
* Returns the first string argument if it is a valid HSL color, otherwise returns `never`.
|
|
769
|
+
* The second argument is an object type with `separator: string` property, which shows the separator between color parameters (defaults to `', '`)
|
|
770
|
+
* @example
|
|
771
|
+
* ```ts
|
|
772
|
+
* // hsl(100, 34%, 56%)
|
|
773
|
+
* type Case1 = HSL<'hsl(100, 34%, 56%)'>
|
|
774
|
+
* // never
|
|
775
|
+
* type Case2 = HSL<'hsl(100, 200%, 3)'>
|
|
776
|
+
* // hsl(100,34%,56%)
|
|
777
|
+
* type Case3 = HSL<'hsl(100,34%,56%)', { separator: ',' }>
|
|
778
|
+
* ```
|
|
779
|
+
*/
|
|
780
|
+
type HSL<T extends string,Options extends HSLOptions=DefaultHSLOptions>=(T extends `hsl(${infer H extends number}${Options["separator"]}${infer S extends number}%${Options["separator"]}${infer L extends number}%)` ? AndArr<[IsInteger<H>,IsInteger<S>,IsInteger<L>]>extends true ? AndArr<[IsBetween<S,0,100>,IsBetween<L,0,100>]>:false:false)extends true ? T:never;
|
|
781
|
+
/**
|
|
782
|
+
* Returns a boolean whether the first string argument is a valid HSL color.
|
|
783
|
+
* The second argument is an object type with `separator: string` property, which shows the separator between color parameters (defaults to `', '`)
|
|
784
|
+
* @example
|
|
785
|
+
* ```ts
|
|
786
|
+
* // true
|
|
787
|
+
* type Case1 = IsHSL<'hsl(100, 34%, 56%)'>
|
|
788
|
+
* // false
|
|
789
|
+
* type Case2 = IsHSL<'hsl(101, 200%, 3)'>
|
|
790
|
+
* // true
|
|
791
|
+
* type Case3 = IsHSL<'hsl(100,34%,56%)', { separator: ',' }>
|
|
792
|
+
* ```
|
|
793
|
+
*/
|
|
794
|
+
type IsHSL<T extends string,Options extends HSLOptions=DefaultHSLOptions>=Not<IsNever<HSL<T,Options>>>;
|
|
795
|
+
/**
|
|
796
|
+
* Returns the third argument if the first argument is valid HSL color (defaults to `true`), otherwise returns the fourth argument (defaults to `false`)
|
|
797
|
+
* The second argument is an object type with `separator: string` property, which shows the separator between color parameters (defaults to `', '`)
|
|
798
|
+
* @example
|
|
799
|
+
* ```ts
|
|
800
|
+
* // 'true'
|
|
801
|
+
* type Case1 = IfHSL<'hsl(100, 34%, 56%)', 'true'>
|
|
802
|
+
* // 'invalid'
|
|
803
|
+
* type Case2 = IfHSL<'hsl(101, 200%, 3)', 'valid', 'invalid'>
|
|
804
|
+
* // true
|
|
805
|
+
* type Case3 = IfHSL<'hsl(100,34%,56%)', { separator: ',' }>
|
|
806
|
+
* ```
|
|
807
|
+
*/
|
|
808
|
+
type IfHSL<T extends string,Options extends HSLOptions=DefaultHSLOptions,IfTrue=true,IfFalse=false>=If<IsHSL<T,Options>,IfTrue,IfFalse>;type ColorOptions={rgbOptions?:RGBOptions;hslOptions?:HSLOptions;};type DefaultColorOptions={rgbOptions:DefaultRGBOptions;hslOptions:DefaultHSLOptions;};
|
|
809
|
+
/**
|
|
810
|
+
* Returns the first string argument if it is a valid RGB or HEX or HSL color, otherwise returns `never`.
|
|
811
|
+
* The second argument is an object type with `rgbOptions: RGBOptions` and `hslOptions: hslOptions` properties, which can accept the separator between color parameters (defaults to `', '`)
|
|
812
|
+
* @example
|
|
813
|
+
* ```ts
|
|
814
|
+
* // rgb(23, 242, 0)
|
|
815
|
+
* type Case1 = Color<'rgb(23, 242, 0)'>
|
|
816
|
+
* // never
|
|
817
|
+
* type Case2 = Color<'rgb(324, 123, 3)'>
|
|
818
|
+
* // '#000000'
|
|
819
|
+
* type Case3 = HEX<'#000000'>
|
|
820
|
+
* // 'hsl(100,34%,56%)'
|
|
821
|
+
* type Case4 = Color<'hsl(100,34%,56%)', { hslOptions: { separator: ',' } }>
|
|
822
|
+
* ```
|
|
823
|
+
*/
|
|
824
|
+
type Color<T extends string,Options extends ColorOptions=DefaultColorOptions>=RGB<T,Options["rgbOptions"]>| HEX<T>| HSL<T,Options["hslOptions"]>;
|
|
825
|
+
/**
|
|
826
|
+
* Returns a boolean whether the first string argument is a valid RGB or HEX or HSL color.
|
|
827
|
+
* The second argument is an object type with `rgbOptions: RGBOptions` and `hslOptions: hslOptions` properties, which can accept the separator between color parameters (defaults to `', '`)
|
|
828
|
+
* @example
|
|
829
|
+
* ```ts
|
|
830
|
+
* // true
|
|
831
|
+
* type Case1 = Color<'rgb(23, 242, 0)'>
|
|
832
|
+
* // false
|
|
833
|
+
* type Case2 = Color<'rgb(324, 123, 3)'>
|
|
834
|
+
* // true
|
|
835
|
+
* type Case3 = HEX<'#000000'>
|
|
836
|
+
* // true
|
|
837
|
+
* type Case4 = Color<'hsl(100,34%,56%)', { hslOptions: { separator: ',' } }>
|
|
838
|
+
* ```
|
|
839
|
+
*/
|
|
840
|
+
type IsColor<T extends string,Options extends ColorOptions=DefaultColorOptions>=Not<IsNever<Color<T,Options>>>;
|
|
841
|
+
/**
|
|
842
|
+
* Returns the third argument if the first argument is valid RGB or HEX or HSL color (defaults to `true`), otherwise returns the fourth argument (defaults to `false`)
|
|
843
|
+
* The second argument is an object type with `rgbOptions: RGBOptions` and `hslOptions: hslOptions` properties, which can accept the separator between color parameters (defaults to `', '`)
|
|
844
|
+
* @example
|
|
845
|
+
* ```ts
|
|
846
|
+
* // 'valid'
|
|
847
|
+
* type Case1 = Color<'rgb(23, 242, 0)', 'valid'>
|
|
848
|
+
* // 'invalid'
|
|
849
|
+
* type Case2 = Color<'rgb(324, 123, 3)', 'valid', 'invalid'>
|
|
850
|
+
* // true
|
|
851
|
+
* type Case3 = Color<'#000000'>
|
|
852
|
+
* ```
|
|
853
|
+
*/
|
|
854
|
+
type IfColor<T extends string,Options extends ColorOptions=DefaultColorOptions,IfTrue=true,IfFalse=false>=If<IsColor<T,Options>,IfTrue,IfFalse>;
|
|
855
|
+
/**
|
|
856
|
+
* Type version of `Array.prototype.concat()`. Concatenates two arrays into one.
|
|
857
|
+
* @example
|
|
858
|
+
* ```ts
|
|
859
|
+
* // [number, number, string, string]
|
|
860
|
+
* type Result = Concat<[number, number], [string, string]>
|
|
861
|
+
* ```
|
|
862
|
+
*/
|
|
863
|
+
type Concat<T extends readonly unknown[],U>=[...T,...(U extends readonly unknown[] ? U:[U])];
|
|
864
|
+
/**
|
|
865
|
+
* Accepts an integer argument and returns a tuple of its digits
|
|
866
|
+
* @example
|
|
867
|
+
* ```ts
|
|
868
|
+
* // [1]
|
|
869
|
+
* type Case1 = DigitsTuple<1>
|
|
870
|
+
* // [1, 2, 3]
|
|
871
|
+
* type Case2 = DigitsTuple<123>
|
|
872
|
+
* // [1, 2, 3]
|
|
873
|
+
* type Case3 = DigitsTuple<-123>
|
|
874
|
+
* ```
|
|
875
|
+
*/
|
|
876
|
+
type DigitsTuple<T extends number>=number extends T ? number[]:Split<Stringify<Abs<T>>,"">extends infer Result ?{[K in keyof Result]:Result[K] extends string ? ParseNumber<Result[K]>:Result[K];}:never;
|
|
877
|
+
/**
|
|
878
|
+
* Pushes the second argument to the first array argument
|
|
879
|
+
* @example
|
|
880
|
+
* ```ts
|
|
881
|
+
* // [1, 2, 3, 4, 5]
|
|
882
|
+
* type Case1 = Push<[1, 2, 3, 4], 5>
|
|
883
|
+
* ```
|
|
884
|
+
*/
|
|
885
|
+
type Push<T extends readonly unknown[],U extends unknown>=[...T,U];type _Repeat<T extends string,Count extends number,Result extends string="",Iteration extends unknown[]=[]>=Iteration["length"] extends Count ? Result:_Repeat<T,Count,`${T}${Result}`,Push<Iteration,unknown>>;
|
|
886
|
+
/**
|
|
887
|
+
* Repeats the first argument number of times specified in the second argument. Range `[0,999]`
|
|
888
|
+
* @example
|
|
889
|
+
* ```ts
|
|
890
|
+
* // 'x'
|
|
891
|
+
* type Case1 = Repeat<'x', 1>
|
|
892
|
+
* // 'xxxxx'
|
|
893
|
+
* type Case2 = Repeat<'x', 5>
|
|
894
|
+
* ```
|
|
895
|
+
*/
|
|
896
|
+
type Repeat<T extends string,Count extends number>=_Repeat<T,Count>;
|
|
897
|
+
/**
|
|
898
|
+
* Returns the first argument if it extends the second argument, returns the third argument otherwise
|
|
899
|
+
* @example
|
|
900
|
+
* ```ts
|
|
901
|
+
* // 1
|
|
902
|
+
* type Case1 = ReturnItselfIfExtends<1, number, 2>
|
|
903
|
+
* // 2
|
|
904
|
+
* type Case2 = ReturnItselfIfExtends<'1', number, 2>
|
|
905
|
+
* ```
|
|
906
|
+
*/
|
|
907
|
+
type ReturnItselfIfExtends<T,Base,Else>=T extends Base ? T:Else;
|
|
908
|
+
/**
|
|
909
|
+
* Returns the first argument if it doesn't extend the second argument, returns the third argument otherwise
|
|
910
|
+
* @example
|
|
911
|
+
* ```ts
|
|
912
|
+
* // '1'
|
|
913
|
+
* type Case1 = ReturnItselfIfNotExtends<'1', number, 2>
|
|
914
|
+
* // 2
|
|
915
|
+
* type Case2 = ReturnItselfIfNotExtends<1, number, 2>
|
|
916
|
+
* ```
|
|
917
|
+
*/
|
|
918
|
+
type ReturnItselfIfNotExtends<T,Base,Else>=T extends Base ? Else:T;type MultiplicationMap={0:[0,0,0,0,0,0,0,0,0,0];1:[0,1,2,3,4,5,6,7,8,9];2:[0,2,4,6,8,10,12,14,16,18];3:[0,3,6,9,12,15,18,21,24,27];4:[0,4,8,12,16,20,24,28,32,36];5:[0,5,10,15,20,25,30,35,40,45];6:[0,6,12,18,24,30,36,42,48,54];7:[0,7,14,21,28,35,42,49,56,63];8:[0,8,16,24,32,40,48,56,64,72];9:[0,9,18,27,36,45,54,63,72,81];};type _MultSingle<Num1 extends string,DigitOfNum2 extends keyof MultiplicationMap,Carry extends number=0,Result extends string="">=IsEmptyString<Num1>extends true ? ReturnItselfIfNotExtends<RemoveLeading<`${Carry}${Result}`,"0">,"","0">:IsEqual<Num1,0>extends true ? "0":IsEqual<DigitOfNum2,0>extends true ? "0":LastCharacter<Num1,{includeRest:true;}>extends [infer Num1LastCharacter extends string,infer Num1Rest extends string] ? Stringify<Sum<MultiplicationMap[DigitOfNum2][ParseNumber<Num1LastCharacter>& keyof MultiplicationMap[DigitOfNum2]],Carry>>extends infer Multiplied extends string ? LastCharacter<Multiplied,{includeRest:true;}>extends [infer MultipliedLastDigit extends string,infer MultipliedRest extends string] ? _MultSingle<Num1Rest,DigitOfNum2,If<IsNever<ParseNumber<MultipliedRest>>,0,ParseNumber<MultipliedRest>>,`${MultipliedLastDigit}${Result}`>:never:never:never;type _Mult<Num1 extends string,Num2 extends string,Result extends string="",Iteration extends unknown[]=[]>=IsEmptyString<Num2>extends true ? Result:LastCharacter<Num2,{includeRest:true;}>extends [infer Num2LastCharacter extends string,infer Num2Rest extends string] ? ParseNumber<Num2LastCharacter>extends infer Num2Digit extends keyof MultiplicationMap ? _Mult<Num1,Num2Rest,Stringify<_Sum<Result,ReturnItselfIfNotExtends<RemoveLeading<`${_MultSingle<Num1,Num2Digit>}${Repeat<"0",Iteration["length"]>}`,"0">,"","0">>>,Push<Iteration,unknown>>:never:Result;
|
|
919
|
+
/**
|
|
920
|
+
* Accepts tow integers and returns their multiplication. Range: `[Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER]`
|
|
921
|
+
* @example
|
|
922
|
+
* ```ts
|
|
923
|
+
* // 0
|
|
924
|
+
* type Case1 = Mult<10, 0>
|
|
925
|
+
* // 24
|
|
926
|
+
* type Case2 = Mult<4, 6>
|
|
927
|
+
* // -24
|
|
928
|
+
* type Case3 = Mult<-4, 6>
|
|
929
|
+
* // 24
|
|
930
|
+
* type Case4 = Mult<-4, -6>
|
|
931
|
+
* ```
|
|
932
|
+
*/
|
|
933
|
+
type Mult<Num1 extends number,Num2 extends number>=IsEqual<Num1,0>extends true ? 0:IsEqual<Num2,0>extends true ? 0:ParseNumber<_Mult<Stringify<Abs<Num1>>,Stringify<Abs<Num2>>>>extends infer Result extends number ? IfNegative<Num1,IfNegative<Num2,Result,Negate<Result>>,IfNegative<Num2,Negate<Result>,Result>>:never;
|
|
934
|
+
/**
|
|
935
|
+
* Returns result of logical addition of two params.
|
|
936
|
+
* @example
|
|
937
|
+
* ```ts
|
|
938
|
+
* // true
|
|
939
|
+
* type Case1 = Or<true, true>
|
|
940
|
+
* // true
|
|
941
|
+
* type Case2 = Or<false, true>
|
|
942
|
+
* ```
|
|
943
|
+
*/
|
|
944
|
+
type Or<Condition1,Condition2>=IfExtends<Condition1,true,true,IfExtends<Condition2,true>>;
|
|
945
|
+
/**
|
|
946
|
+
* Returns result of logical addition of all elements inside the passed array type
|
|
947
|
+
* @example
|
|
948
|
+
* ```ts
|
|
949
|
+
* // true
|
|
950
|
+
* type Case1 = Or<[true, true, true]>
|
|
951
|
+
* // true
|
|
952
|
+
* type Case2 = Or<[true, true, false]>
|
|
953
|
+
* ```
|
|
954
|
+
*/
|
|
955
|
+
type OrArr<Conditions extends readonly unknown[]>=true extends Conditions[number] ? true:false;type _FindQuotient<Dividend extends number,Divisor extends number,CurrentQuotient extends number>=Mult<Divisor,CurrentQuotient>extends infer Product extends number ? IsEqual<Dividend,Product>extends true ? CurrentQuotient:IsLowerThan<Dividend,Product>extends true ? _FindQuotient<Dividend,Divisor,Decrement<CurrentQuotient>>:CurrentQuotient:never;type _Div<Dividend extends string,Divisor extends number,Result extends string="",CurrentDividend extends string="",IterationsWithoutDivision extends number=0,HadFirstDivision extends boolean=false>=Or<IsEmptyString<CurrentDividend>,IsLowerThan<ParseNumber<CurrentDividend>,Divisor>>extends true ? IsEmptyString<Dividend>extends true ? ParseNumber<If<And<HadFirstDivision,IsNotEqual<IterationsWithoutDivision,0>>,`${Result}0`,Result>>:Dividend extends `${infer FirstDigit extends string}${infer Rest extends string}` ? _Div<Rest,Divisor,If<And<HadFirstDivision,IsNotEqual<IterationsWithoutDivision,0>>,`${Result}0`,Result>,IfEqual<CurrentDividend,"0",FirstDigit,`${CurrentDividend}${FirstDigit}`>,Increment<IterationsWithoutDivision>,HadFirstDivision>:never:_FindQuotient<ParseNumber<CurrentDividend>,Divisor,10>extends infer Quotient extends number ? IsNever<Quotient>extends true ? ParseNumber<Result>:Sub<ParseNumber<CurrentDividend>,Mult<Quotient,Divisor>>extends infer Remainder extends number ? _Div<Dividend,Divisor,`${Result}${Quotient}`,IfGreaterThan<Remainder,0,`${Remainder}`,"">,0,true>:never:never;
|
|
956
|
+
/**
|
|
957
|
+
* Returns integer division of two numbers. Range: `[Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER]`
|
|
958
|
+
* @example
|
|
959
|
+
* ```ts
|
|
960
|
+
* // 5
|
|
961
|
+
* type Case1 = Div<10, 2>
|
|
962
|
+
* // 2
|
|
963
|
+
* type Case2 = Div<7, 3>
|
|
964
|
+
* ```
|
|
965
|
+
*/
|
|
966
|
+
type Div<Dividend extends number,Divisor extends number>=IsEqual<Divisor,0>extends true ? never:IsEqual<Dividend,0>extends true ? 0:IsEqual<Dividend,Divisor>extends true ? 1:IsLowerThan<Abs<Dividend>,Abs<Divisor>>extends true ? 0:_Div<Stringify<Abs<Dividend>>,Abs<Divisor>>extends infer Quotient extends number ? If<Or<And<IsNegative<Dividend>,IsNegative<Divisor>>,And<IsPositive<Dividend>,IsPositive<Divisor>>>,Quotient,Negate<Quotient>>:never;
|
|
967
|
+
/**
|
|
968
|
+
* Returns result of concatenation of two string literals with '.' if the second literal is not empty. otherwise returns the first string literal.
|
|
969
|
+
* @example
|
|
970
|
+
* ```ts
|
|
971
|
+
* // 'foo.bar'
|
|
972
|
+
* type Result = Dot<'foo', 'bar'>
|
|
973
|
+
* ```
|
|
974
|
+
*/
|
|
975
|
+
type Dot<T extends string,U extends string>="" extends U ? T:`${T}.${U}`;
|
|
976
|
+
/**
|
|
977
|
+
* Returns a boolean whether the first string argument ends with the second one
|
|
978
|
+
* @example
|
|
979
|
+
* ```ts
|
|
980
|
+
* // true
|
|
981
|
+
* type Result = EndsWith<'Foobar', 'bar'>
|
|
982
|
+
* ```
|
|
983
|
+
*/
|
|
984
|
+
type EndsWith<T extends string,Characters extends string>=T extends `${string}${Characters}` ? true:false;type _Factorial<T extends number,CurrentNum extends number=1,CurrentProduct extends number=1>=IsEqual<T,CurrentNum>extends true ? Mult<CurrentProduct,CurrentNum>:_Factorial<T,Increment<CurrentNum>,Mult<CurrentProduct,CurrentNum>>;
|
|
985
|
+
/**
|
|
986
|
+
* Accepts an integer argument and returns it mathematical factorial. Range: [0, 21]
|
|
987
|
+
* @example
|
|
988
|
+
* // 0
|
|
989
|
+
* type Case1 = Factorial<0>
|
|
990
|
+
* // 720
|
|
991
|
+
* type Case1 = Factorial<6>
|
|
992
|
+
*/
|
|
993
|
+
type Factorial<T extends number>=number extends T ? never:IsNegative<T>extends true ? never:IsEqual<T,0>extends true ? 1:_Factorial<T>;
|
|
994
|
+
/**
|
|
995
|
+
* Returns the fibonacci sequence number under the passed integer index. Range: `[0, 78]`
|
|
996
|
+
* @example
|
|
997
|
+
* ```ts
|
|
998
|
+
* // 3
|
|
999
|
+
* type Case1 = Fibonacci<4>
|
|
1000
|
+
* // 102334155
|
|
1001
|
+
* type Case2 = Fibonacci<40>
|
|
1002
|
+
* ```
|
|
1003
|
+
*/
|
|
1004
|
+
type Fibonacci<T extends number>=IsNegative<T>extends true ? never:IsLowerThan<T,2>extends true ? T:Fibonacci<Decrement<T>>extends infer NMinusOne extends number ? Fibonacci<Sub<T,2>>extends infer NMinusTwo extends number ? Sum<NMinusOne,NMinusTwo>:never:never;type FirstCharacterOptions={includeRest:boolean;};
|
|
1005
|
+
/**
|
|
1006
|
+
* Accepts a string argument and returns its first character.
|
|
1007
|
+
* If the `includeRest` options is `true`, returns the first character and the rest of the string in the format of: [first, rest]
|
|
1008
|
+
* @example
|
|
1009
|
+
* ```ts
|
|
1010
|
+
* // 'a'
|
|
1011
|
+
* type Case1 = FirstCharacter<'abc'>
|
|
1012
|
+
* // ['a', 'bc']
|
|
1013
|
+
* type Case2 = FirstCharacter<'abc', {includeRest: true}>
|
|
1014
|
+
* ```
|
|
1015
|
+
*/
|
|
1016
|
+
type FirstCharacter<T extends string,Options extends FirstCharacterOptions={includeRest:false;}>=T extends `${infer First extends string}${infer Rest extends string}` ? If<Options["includeRest"],[First,Rest],First>:never;
|
|
1017
|
+
/**
|
|
1018
|
+
* Returns the first digit of the number argument
|
|
1019
|
+
* @example
|
|
1020
|
+
* ```ts
|
|
1021
|
+
* // 1
|
|
1022
|
+
* type Case1 = FirstDigit<123>
|
|
1023
|
+
* // -1
|
|
1024
|
+
* type Case2 = FirstDigit<-123>
|
|
1025
|
+
* ```
|
|
1026
|
+
*/
|
|
1027
|
+
type FirstDigit<T extends number>=DigitsTuple<T>extends readonly [infer First extends number,...unknown[]] ? First:never;
|
|
1028
|
+
/**
|
|
1029
|
+
* Type version of `Math.floor()`. Returns floored value of the passed number
|
|
1030
|
+
* @example
|
|
1031
|
+
* ```ts
|
|
1032
|
+
* // 1
|
|
1033
|
+
* type Case1 = Ceil<1.9>
|
|
1034
|
+
* // -2
|
|
1035
|
+
* type Case2 = Ceil<-1.2>
|
|
1036
|
+
* ```
|
|
1037
|
+
*/
|
|
1038
|
+
type Floor<T extends number>=IsFloat<T>extends true ? GetFloatNumberParts<T>extends [infer Whole extends number,unknown] ? IsNegative<T>extends true ? Negate<Increment<Whole>>:Whole:never:T;type ShiftOptions={includeRemoved:boolean;};
|
|
1039
|
+
/**
|
|
1040
|
+
* Removes the first element from the first array argument.
|
|
1041
|
+
* If the `includeRemoved` option is `true` return removed element with the new array in the format of [rest, removed]
|
|
1042
|
+
* @example
|
|
1043
|
+
* ```ts
|
|
1044
|
+
* // [2, 3]
|
|
1045
|
+
* type Case1 = Shift<[1, 2, 3]>
|
|
1046
|
+
* // [[2, 3], 1]
|
|
1047
|
+
* type Case2 = Shift<[1, 2, 3], {includeRemoved: true}>
|
|
1048
|
+
* ```
|
|
1049
|
+
*/
|
|
1050
|
+
type Shift<T extends readonly unknown[],Options extends ShiftOptions={includeRemoved:false;}>=T extends readonly [infer Removed,...infer Rest extends readonly unknown[]] ? If<Options["includeRemoved"],[Rest,Removed],Rest>:never;
|
|
1051
|
+
/**
|
|
1052
|
+
* Returns a boolean whether the second argument is in the first array argument
|
|
1053
|
+
* @example
|
|
1054
|
+
* ```ts
|
|
1055
|
+
* // true
|
|
1056
|
+
* type Case1 = Includes<[1, 2, 3], 1>
|
|
1057
|
+
* // false
|
|
1058
|
+
* type Case1 = Includes<[1, 2, 3], 4>
|
|
1059
|
+
* ```
|
|
1060
|
+
*/
|
|
1061
|
+
type Includes<T extends readonly unknown[],Pivot>=IsEmptyArray<T>extends true ? false:Shift<T,{includeRemoved:true;}>extends [infer Rest extends readonly unknown[],infer Removed] ? IfEqual<Pivot,Removed,true,Includes<Rest,Pivot>>:false;type _IndexOfArray<T extends readonly unknown[],Pivot,Index extends number=0>=T extends readonly [infer First,...infer Rest extends unknown[]] ? IsEqual<First,Pivot>extends true ? Index:_IndexOfArray<Rest,Pivot,Increment<Index>>:-1;type _IndexOfString<T extends string,Pivot,Index extends number=0>=T extends `${infer First}${infer Rest extends string}` ? IsEqual<First,Pivot>extends true ? Index:_IndexOfString<Rest,Pivot,Increment<Index>>:-1;
|
|
1062
|
+
/**
|
|
1063
|
+
* Type version of `Array.prototype.indexOf()` and `String.prototype.indexOf()`. Returns the index of the second argument in the first argument
|
|
1064
|
+
* @example
|
|
1065
|
+
* ```ts
|
|
1066
|
+
* // 1
|
|
1067
|
+
* type Case1 = IndexOf<[1, 2, 3], 2>
|
|
1068
|
+
* // -1
|
|
1069
|
+
* type Case1 = IndexOf<[1, 2, 3], 4>
|
|
1070
|
+
* // 1
|
|
1071
|
+
* type Case3 = IndexOf<'123', '2'>
|
|
1072
|
+
* // -1
|
|
1073
|
+
* type Case4 = IndexOf<'123', '4'>
|
|
1074
|
+
* ```
|
|
1075
|
+
*/
|
|
1076
|
+
type IndexOf<T extends readonly unknown[] | string,Pivot extends T extends string ? string:unknown>=T extends string ? IsStringLiteral<T>extends true ? _IndexOfString<T,Pivot>:never:T extends readonly unknown[] ? IsTuple<T>extends true ? _IndexOfArray<T,Pivot>:never:never;
|
|
1077
|
+
/**
|
|
1078
|
+
* Returns a boolean whether the passed argument is a valid array index
|
|
1079
|
+
* @example
|
|
1080
|
+
* ```ts
|
|
1081
|
+
* // true
|
|
1082
|
+
* type Case1 = IsArrayIndex<1>
|
|
1083
|
+
* // true
|
|
1084
|
+
* type Case2 = IsArrayIndex<'1'>
|
|
1085
|
+
* // false
|
|
1086
|
+
* type Case3 = IsArrayIndex<-1>
|
|
1087
|
+
* ```
|
|
1088
|
+
*/
|
|
1089
|
+
type IsArrayIndex<T>=T extends number ? And<IsInteger<T>,IsGreaterOrEqual<T,0>>:T extends string ? ParseNumber<T>extends infer NumT extends number ? Not<IsNever<NumT>>extends true ? And<IsInteger<NumT>,IsGreaterOrEqual<NumT,0>>:false:false:never;type PrettifyOptions={recursive:boolean;};
|
|
1090
|
+
/**
|
|
1091
|
+
* Accepts a type and returns its simplified version for better readability. Transforms interface to type, simplifies intersections. If `recursive` option is `true` transforms the children object properties as well
|
|
1092
|
+
* @example
|
|
1093
|
+
* ```ts
|
|
1094
|
+
* // { a: string; b: string }
|
|
1095
|
+
* type Case1 = Prettify<{ a: string } & { b: string }
|
|
1096
|
+
* ```
|
|
1097
|
+
*/
|
|
1098
|
+
type Prettify<T,Options extends PrettifyOptions={recursive:false;}>=T extends infer R ?{[K in keyof R]:If<Options["recursive"],Prettify<R[K],Options>,R[K]>;}:never;type MutableOptions={recursive:boolean;};
|
|
1099
|
+
/**
|
|
1100
|
+
* Make all properties in the passed argument mutable (removes readonly)
|
|
1101
|
+
* If `recursive` is set to `true`, it will also make all nested properties mutable
|
|
1102
|
+
* @example
|
|
1103
|
+
* ```ts
|
|
1104
|
+
* // { a: { readonly b: string } }
|
|
1105
|
+
* type Case1 = Mutable<{ readonly a: { readonly b: string } }>;
|
|
1106
|
+
* // { a: { b: string } }
|
|
1107
|
+
* type Case2 = Mutable<{ readonly a: { readonly b: string } }, { recursive: true }>;
|
|
1108
|
+
* ```
|
|
1109
|
+
*/
|
|
1110
|
+
type Mutable<T,Options extends MutableOptions={recursive:false;}>=Prettify<{-readonly [K in keyof T]:And<Options["recursive"],Extends<T[K],object>>extends true ? Mutable<T[K],Options>:T[K];}>;
|
|
1111
|
+
/**
|
|
1112
|
+
* Make passed properties in the passed argument mutable (removes readonly)
|
|
1113
|
+
* @example
|
|
1114
|
+
* ```ts
|
|
1115
|
+
* // { a: string; readonly b: string; }
|
|
1116
|
+
* type Case1 = MutableOnly<{ readonly a: string; readonly b: string; }, "a">;
|
|
1117
|
+
* // { a: string; b: string; }
|
|
1118
|
+
* type Case2 = MutableOnly<{ readonly a: string; readonly b: string; }, "a" | "b">;
|
|
1119
|
+
* ```
|
|
1120
|
+
*/
|
|
1121
|
+
type MutableOnly<T,K extends keyof T>=Prettify<Pick<T,Exclude<keyof T,K>>&{-readonly [P in K]:T[P];}>;
|
|
1122
|
+
/**
|
|
1123
|
+
* Make all properties in the passed argument mutable except for the passed properties
|
|
1124
|
+
* @example
|
|
1125
|
+
* ```ts
|
|
1126
|
+
* // { a: string; readonly b: string; }
|
|
1127
|
+
* type Case1 = MutableExcept<{ readonly a: string; readonly b: string; }, "b">;
|
|
1128
|
+
* // { a: string; b: string; }
|
|
1129
|
+
* type Case2 = MutableExcept<{ a: string; readonly b: string; }, "a">;
|
|
1130
|
+
* ```
|
|
1131
|
+
*/
|
|
1132
|
+
type MutableExcept<T,K extends keyof T>=Prettify<Pick<T,K>&{-readonly [P in Exclude<keyof T,K>]:T[P];}>;
|
|
1133
|
+
/**
|
|
1134
|
+
* Returns a boolean whether the passed argument is an array
|
|
1135
|
+
* @example
|
|
1136
|
+
* ```ts
|
|
1137
|
+
* // true
|
|
1138
|
+
* type Case1 = IsArray<[]>
|
|
1139
|
+
* // false
|
|
1140
|
+
* type Case2 = IsArray<string>
|
|
1141
|
+
* ```
|
|
1142
|
+
*/
|
|
1143
|
+
type IsArray<T>=AndArr<[Not<IsAny<T>>,Not<IsNever<T>>,Extends<T,readonly unknown[]>]>;
|
|
1144
|
+
/**
|
|
1145
|
+
* Returns a boolean whether the passed argument is a mutable array
|
|
1146
|
+
* @example
|
|
1147
|
+
* ```ts
|
|
1148
|
+
* // true
|
|
1149
|
+
* type Case1 = IsMutableArray<[]>
|
|
1150
|
+
* // false
|
|
1151
|
+
* type Case2 = IsMutableArray<readonly []>
|
|
1152
|
+
* ```
|
|
1153
|
+
*/
|
|
1154
|
+
type IsMutableArray<T>=And<IsArray<T>,NotExtends<Readonly<T>,T>>;
|
|
1155
|
+
/**
|
|
1156
|
+
* Returns a boolean whether the passed argument is a read-only array
|
|
1157
|
+
* @example
|
|
1158
|
+
* ```ts
|
|
1159
|
+
* // true
|
|
1160
|
+
* type Case1 = IsReadonlyArray<readonly []>
|
|
1161
|
+
* // false
|
|
1162
|
+
* type Case2 = IsReadonlyArray<[]>
|
|
1163
|
+
* ```
|
|
1164
|
+
*/
|
|
1165
|
+
type IsReadonlyArray<T>=And<IsArray<T>,NotExtends<T,Mutable<T>>>;
|
|
1166
|
+
/**
|
|
1167
|
+
* Returns the remainder of the division of two numbers.
|
|
1168
|
+
* @example
|
|
1169
|
+
* ```ts
|
|
1170
|
+
* // 1
|
|
1171
|
+
* type T0 = Mod<1, 2>;
|
|
1172
|
+
* // 1
|
|
1173
|
+
* type T1 = Mod<1, 3>;
|
|
1174
|
+
* ```
|
|
1175
|
+
*/
|
|
1176
|
+
type Mod<Dividend extends number,Divisor extends number>=Div<Dividend,Divisor>extends infer Quotient extends number ? Mult<Quotient,Divisor>extends infer Product extends number ? Sub<Dividend,Product>:never:never;
|
|
1177
|
+
/**
|
|
1178
|
+
* Accepts an integer argument and returns a boolean whether it is divisible by two. Range: `[Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER]`
|
|
1179
|
+
* @example
|
|
1180
|
+
* ```ts
|
|
1181
|
+
* // true
|
|
1182
|
+
* type Case1 = IsDivisibleByTwo<4>
|
|
1183
|
+
* // false
|
|
1184
|
+
* type Case2 = IsDivisibleByTwo<-1>
|
|
1185
|
+
* // true
|
|
1186
|
+
* type Case3 = IsDivisibleByTwo<-4>
|
|
1187
|
+
* ```
|
|
1188
|
+
*/
|
|
1189
|
+
type IsDivisibleByTwo<T extends number>=IsEven<T>;type DivisibleByThreeMap={3:true;6:true;9:true;};type _IsDivisibleByThree<T extends number>=DigitsTuple<T>extends infer Digits extends readonly number[] ? IsEqual<Digits["length"],1>extends true ? Digits[0] extends keyof DivisibleByThreeMap ? true:false:SumArr<Digits>extends infer DigitsSum extends number ? IfLowerThan<DigitsSum,3>extends true ? false:_IsDivisibleByThree<DigitsSum>:never:never;
|
|
1190
|
+
/**
|
|
1191
|
+
* Accepts an integer argument and returns a boolean whether it is divisible by three. Range: `[Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER]`
|
|
1192
|
+
* @example
|
|
1193
|
+
* ```ts
|
|
1194
|
+
* // true
|
|
1195
|
+
* type Case1 = IsDivisibleByThree<123>
|
|
1196
|
+
* // false
|
|
1197
|
+
* type Case2 = IsDivisibleByThree<124>
|
|
1198
|
+
* // true
|
|
1199
|
+
* type Case3 = IsDivisibleByThree<-123>
|
|
1200
|
+
* ```
|
|
1201
|
+
*/
|
|
1202
|
+
type IsDivisibleByThree<T extends number>=_IsDivisibleByThree<T>;
|
|
1203
|
+
/**
|
|
1204
|
+
* Accepts an integer argument and returns a boolean whether it is divisible by five. Range: `[Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER]`
|
|
1205
|
+
* @example
|
|
1206
|
+
* ```ts
|
|
1207
|
+
* // true
|
|
1208
|
+
* type Case1 = IsDivisibleByFive<125>
|
|
1209
|
+
* // false
|
|
1210
|
+
* type Case2 = IsDivisibleByFive<-13>
|
|
1211
|
+
* // true
|
|
1212
|
+
* type Case3 = IsDivisibleByFive<-125>
|
|
1213
|
+
* ```
|
|
1214
|
+
*/
|
|
1215
|
+
type IsDivisibleByFive<T extends number>=EndsWith<Stringify<T>,"0" | "5">;
|
|
1216
|
+
/**
|
|
1217
|
+
* Accepts an integer argument and returns a boolean whether it is divisible by six. Range: `[Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER]`
|
|
1218
|
+
* @example
|
|
1219
|
+
* ```ts
|
|
1220
|
+
* // true
|
|
1221
|
+
* type Case1 = IsDivisibleBySix<126>
|
|
1222
|
+
* // false
|
|
1223
|
+
* type Case2 = IsDivisibleBySix<124>
|
|
1224
|
+
* // true
|
|
1225
|
+
* type Case3 = IsDivisibleBySix<-126>
|
|
1226
|
+
* ```
|
|
1227
|
+
*/
|
|
1228
|
+
type IsDivisibleBySix<T extends number>=And<IsDivisibleByTwo<T>,IsDivisibleByThree<T>>;
|
|
1229
|
+
/**
|
|
1230
|
+
* Accepts an integer argument and returns a boolean whether it is divisible by ten. Range: `[Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER]`
|
|
1231
|
+
* @example
|
|
1232
|
+
* ```ts
|
|
1233
|
+
* // true
|
|
1234
|
+
* type Case1 = IsDivisibleByTen<100>
|
|
1235
|
+
* // false
|
|
1236
|
+
* type Case2 = IsDivisibleByTen<101>
|
|
1237
|
+
* // true
|
|
1238
|
+
* type Case3 = IsDivisibleByTen<-100>
|
|
1239
|
+
* ```
|
|
1240
|
+
*/
|
|
1241
|
+
type IsDivisibleByTen<T extends number>=EndsWith<Stringify<T>,"0">;
|
|
1242
|
+
/**
|
|
1243
|
+
* Accepts an integer argument and returns a boolean whether it is divisible by hundred. Range: `[Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER]`
|
|
1244
|
+
* @example
|
|
1245
|
+
* ```ts
|
|
1246
|
+
* // true
|
|
1247
|
+
* type Case1 = IsDivisibleByHundred<100>
|
|
1248
|
+
* // false
|
|
1249
|
+
* type Case2 = IsDivisibleByHundred<101>
|
|
1250
|
+
* // true
|
|
1251
|
+
* type Case3 = IsDivisibleByHundred<-100>
|
|
1252
|
+
* ```
|
|
1253
|
+
*/
|
|
1254
|
+
type IsDivisibleByHundred<T extends number>=EndsWith<Stringify<T>,"00">;
|
|
1255
|
+
/**
|
|
1256
|
+
* Returns a boolean whether the first integer argument is divisible by the second integer argument
|
|
1257
|
+
* @example
|
|
1258
|
+
* ```ts
|
|
1259
|
+
* // true
|
|
1260
|
+
* type Case1 = IsDivisible<1024, 2>
|
|
1261
|
+
* // false
|
|
1262
|
+
* type Case2 = IsDivisible<1023, 2>
|
|
1263
|
+
* ```
|
|
1264
|
+
*/
|
|
1265
|
+
type IsDivisible<Dividend extends number,Divisor extends number>=IsEqual<Mod<Dividend,Divisor>,0>;
|
|
1266
|
+
/**
|
|
1267
|
+
* Returns a boolean whether the passed argument is a letter (Only for letters that have both upper and lower case)
|
|
1268
|
+
* @example
|
|
1269
|
+
* ```ts
|
|
1270
|
+
* // true
|
|
1271
|
+
* type Case1 = IsLetter<'a'>
|
|
1272
|
+
* // false
|
|
1273
|
+
* type Case2 = IsLetter<'1'>
|
|
1274
|
+
* ```
|
|
1275
|
+
*/
|
|
1276
|
+
type IsLetter<T extends string>=Uppercase<T>extends Lowercase<T>? false:true;type _IsUnion<T,U=T>=IsNever<T>extends true ? false:T extends U ? Not<IsNever<Exclude<U,T>>>:false;
|
|
1277
|
+
/**
|
|
1278
|
+
* Returns a boolean whether the passed argument is a union
|
|
1279
|
+
* @example
|
|
1280
|
+
* ```ts
|
|
1281
|
+
* // true
|
|
1282
|
+
* type Case1 = IsUnion<'a' | 'b'>
|
|
1283
|
+
* // false
|
|
1284
|
+
* type Case2 = IsUnion<'a'>
|
|
1285
|
+
* ```
|
|
1286
|
+
*/
|
|
1287
|
+
type IsUnion<T>=_IsUnion<T,T>;
|
|
1288
|
+
/**
|
|
1289
|
+
* Accepts two integers and returns the maximum among them. Range: `[Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER]`
|
|
1290
|
+
* @example
|
|
1291
|
+
* ```ts
|
|
1292
|
+
* // 10
|
|
1293
|
+
* type Case1 = Max<1, 10>
|
|
1294
|
+
* // 1
|
|
1295
|
+
* type Case2 = Max<1, -10>
|
|
1296
|
+
* ```
|
|
1297
|
+
*/
|
|
1298
|
+
type Max<Num1 extends number,Num2 extends number>=IfLowerThan<Num1,Num2,Num2,Num1>;type _MaxArr<T extends readonly number[],CurrentMax extends number=ReturnItselfIfNotExtends<T[0],undefined,never>>=IsEmptyArray<T>extends true ? CurrentMax:Shift<T,{includeRemoved:true;}>extends [infer Rest extends number[],infer First extends number] ? _MaxArr<Rest,Max<First,CurrentMax>>:never;
|
|
1299
|
+
/**
|
|
1300
|
+
* Accepts an array of integers and returns the maximum among its elements. Range: `[Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER]`
|
|
1301
|
+
* @example
|
|
1302
|
+
* ```ts
|
|
1303
|
+
* // 10
|
|
1304
|
+
* type Case1 = MaxArr<[1, 2, 4, 10]>
|
|
1305
|
+
* // 4
|
|
1306
|
+
* type Case2 = MaxArr<[-1, 4, -10]>
|
|
1307
|
+
* ```
|
|
1308
|
+
*/
|
|
1309
|
+
type MaxArr<T extends readonly number[]>=IsTuple<T>extends true ? _MaxArr<T>:never;
|
|
1310
|
+
/**
|
|
1311
|
+
* Accepts two integers and returns the minimum among them. Range: `[Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER]`
|
|
1312
|
+
* @example
|
|
1313
|
+
* ```ts
|
|
1314
|
+
* // 1
|
|
1315
|
+
* type Case1 = Min<1, 10>
|
|
1316
|
+
* // -10
|
|
1317
|
+
* type Case2 = Min<1, -10>
|
|
1318
|
+
* ```
|
|
1319
|
+
*/
|
|
1320
|
+
type Min<Num1 extends number,Num2 extends number>=IfLowerThan<Num1,Num2,Num1,Num2>;type _MinArr<T extends readonly number[],CurrentMin extends number=ReturnItselfIfNotExtends<T[0],undefined,never>>=IsEmptyArray<T>extends true ? CurrentMin:Shift<T,{includeRemoved:true;}>extends [infer Rest extends number[],infer First extends number] ? _MinArr<Rest,Min<First,CurrentMin>>:never;
|
|
1321
|
+
/**
|
|
1322
|
+
* Accepts an array of integers and returns the minimum among its elements. Range: `[Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER]`
|
|
1323
|
+
* @example
|
|
1324
|
+
* ```ts
|
|
1325
|
+
* // 1
|
|
1326
|
+
* type Case1 = MinArr<[1, 2, 4, 10]>
|
|
1327
|
+
* // -10
|
|
1328
|
+
* type Case2 = MinArr<[-1, 4, -10]>
|
|
1329
|
+
* ```
|
|
1330
|
+
*/
|
|
1331
|
+
type MinArr<T extends readonly number[]>=IsTuple<T>extends true ? _MinArr<T>:never;
|
|
1332
|
+
/**
|
|
1333
|
+
* Make all properties in the passed argument non-nullable
|
|
1334
|
+
* @example
|
|
1335
|
+
* ```ts
|
|
1336
|
+
* // { a: string, b: number }
|
|
1337
|
+
* type T0 = NonNullableObject<{ a: string | null, b: number | undefined }>;
|
|
1338
|
+
* ```
|
|
1339
|
+
*/
|
|
1340
|
+
type NonNullableObject<T>={[K in keyof T]:NonNullable<T[K]>;};
|
|
1341
|
+
/**
|
|
1342
|
+
* Make passed properties in the passed argument non-nullable
|
|
1343
|
+
* @example
|
|
1344
|
+
* ```ts
|
|
1345
|
+
* // { a: string, b: number, c: boolean | null }
|
|
1346
|
+
* type T0 = NonNullableObjectOnly<{ a: string | null, b: number | undefined, c: boolean | null }, "a" | "b">;
|
|
1347
|
+
* ```
|
|
1348
|
+
*/
|
|
1349
|
+
type NonNullableObjectOnly<T,K extends keyof T>=Prettify<Pick<T,Exclude<keyof T,K>>&{[P in K]:NonNullable<T[P]>;}>;
|
|
1350
|
+
/**
|
|
1351
|
+
* Make all properties in the passed argument non-nullable except for the passed properties
|
|
1352
|
+
* @example
|
|
1353
|
+
* ```ts
|
|
1354
|
+
* // { a: string, b: number, c: boolean | null }
|
|
1355
|
+
* type T0 = NonNullableObjectExcept<{ a: string | null, b: number | undefined, c: boolean | null }, "c">;
|
|
1356
|
+
* ```
|
|
1357
|
+
*/
|
|
1358
|
+
type NonNullableObjectExcept<T,K extends keyof T>=Prettify<Pick<T,K>&{[P in Exclude<keyof T,K>]:NonNullable<T[P]>;}>;type _IsPalindrome<T extends string>=IsEmptyString<T>extends true ? true:Not<IsStringLiteral<T>>extends true ? false:T extends `${infer First extends string}${infer Rest extends string}` ? IsEmptyString<Rest>extends true ? true:Rest extends `${infer NewRest extends string}${First}` ? _IsPalindrome<NewRest>:false:false;
|
|
1359
|
+
/**
|
|
1360
|
+
* Check whether a string or number is a palindrome.
|
|
1361
|
+
* @example
|
|
1362
|
+
* ```ts
|
|
1363
|
+
* // true
|
|
1364
|
+
* type T0 = IsPalindrome<"racecar">;
|
|
1365
|
+
* // false
|
|
1366
|
+
* type T1 = IsPalindrome<"hello">;
|
|
1367
|
+
* ```
|
|
1368
|
+
*/
|
|
1369
|
+
type IsPalindrome<T extends string | number>=_IsPalindrome<Stringify<T>>;
|
|
1370
|
+
/**
|
|
1371
|
+
* Returns a boolean if the passed type is `unknown`
|
|
1372
|
+
* @example
|
|
1373
|
+
* ```ts
|
|
1374
|
+
* // true
|
|
1375
|
+
* type TrueResult = IsUnknown<unknown>
|
|
1376
|
+
* // false
|
|
1377
|
+
* type FalseResult = IsUnknown<any>
|
|
1378
|
+
* ```
|
|
1379
|
+
*/
|
|
1380
|
+
type IsUnknown<T>=IsAny<T>extends true ? false:[unknown] extends [T] ? true:false;
|
|
1381
|
+
/**
|
|
1382
|
+
* Returns the second argument if the first argument is `unknown` (defaults to `true`), otherwise returns the third argument (defaults to `false`)
|
|
1383
|
+
* @example
|
|
1384
|
+
* ```ts
|
|
1385
|
+
* // "foo"
|
|
1386
|
+
* type Result = IfUnknown<unknown, "foo", "bar">
|
|
1387
|
+
* ```
|
|
1388
|
+
*/
|
|
1389
|
+
type IfUnknown<T,IfTrue=true,IfFalse=false>=If<IsUnknown<T>,IfTrue,IfFalse>;type UnknownifyPropertiesOptions={makeOptional:boolean;};
|
|
1390
|
+
/**
|
|
1391
|
+
* Turns all properties of an object to type `unknown`.
|
|
1392
|
+
* If `makeOptional` option is `true`, makes all properties optional
|
|
1393
|
+
* @example
|
|
1394
|
+
* ```ts
|
|
1395
|
+
* // {a:unknown; b:unknown}
|
|
1396
|
+
* type Result = UnknownifyProperties<{a: string; b: string}>
|
|
1397
|
+
* ```
|
|
1398
|
+
*/
|
|
1399
|
+
type UnknownifyProperties<T extends object,Options extends UnknownifyPropertiesOptions={makeOptional:false;}>={[K in keyof T]:unknown;}extends infer Result ? If<Options["makeOptional"],Partial<Result>,Result>:never;type OverWritable={overwriteDefault?:boolean;};type ApplyDefaultOptions<BaseOptions,Options extends BaseOptions,DefaultOptions extends BaseOptions,OverwriteRules,OverwriteDefault extends boolean=false>=Prettify<{[K in keyof BaseOptions]-?:K extends keyof Options ? AndArr<[Extends<NonNullable<BaseOptions[K]>,object>,Not<IsNever<DefaultOptions[K]>>,Not<IsUnknown<BaseOptions[K]>>]>extends true ? ApplyDefaultOptions<NonNullable<BaseOptions[K]>,Options[K],DefaultOptions[K],OverwriteRules[K & keyof OverwriteRules],OverwriteDefault>&{tra:"test";}:Or<IsEqual<OverwriteDefault,true>,And<Extends<K,keyof OverwriteRules>,Extends<OverwriteRules[K & keyof OverwriteRules],true>>>extends true ? Options[K]:Options[K] | DefaultOptions[K]:DefaultOptions[K];}>;
|
|
1400
|
+
/**
|
|
1401
|
+
* Get the values of properties in an object
|
|
1402
|
+
* @example
|
|
1403
|
+
* ```ts
|
|
1404
|
+
* // string | number
|
|
1405
|
+
* type T0 = ValueOf<{ a: string, b: number }>;
|
|
1406
|
+
* ```
|
|
1407
|
+
*/
|
|
1408
|
+
type ValueOf<T>=T[keyof T];
|
|
1409
|
+
/**
|
|
1410
|
+
* Get the values of properties in an object only for the passed properties
|
|
1411
|
+
* @example
|
|
1412
|
+
* ```ts
|
|
1413
|
+
* // string
|
|
1414
|
+
* type T0 = ValueOfOnly<{ a: string, b: number }, "a">;
|
|
1415
|
+
* ```
|
|
1416
|
+
*/
|
|
1417
|
+
type ValueOfOnly<T,K extends keyof T>=T[K];
|
|
1418
|
+
/**
|
|
1419
|
+
* Get the values of properties in an object except for the passed properties
|
|
1420
|
+
* @example
|
|
1421
|
+
* ```ts
|
|
1422
|
+
* // number
|
|
1423
|
+
* type T0 = ValueOfExcept<{ a: string, b: number }, "a">;
|
|
1424
|
+
* ```
|
|
1425
|
+
*/
|
|
1426
|
+
type ValueOfExcept<T,K extends keyof T>=T[keyof Omit<T,K>];
|
|
1427
|
+
/**
|
|
1428
|
+
* Get the types of elements in an array
|
|
1429
|
+
* @example
|
|
1430
|
+
* ```ts
|
|
1431
|
+
* // string | number
|
|
1432
|
+
* type T0 = ValueOfArray<[string, number]>;
|
|
1433
|
+
* ```
|
|
1434
|
+
*/
|
|
1435
|
+
type ValueOfArray<T extends readonly unknown[]>=T[number];type PathToFieldsOptions=OverWritable &{ignoredTypes?:unknown;stopTypes?:unknown;limit?:number;format?:"dot" | "array";ignoredKeys?:PropertyKey;arrayIndexing?:{exactIndexes:boolean;};};type DefaultPathToFieldsOptions={ignoredTypes:never;stopTypes:string | number | boolean | symbol | Date | Function;format:"dot";limit:10;ignoredKeys:never;arrayIndexing:{exactIndexes:false;};};type OverwriteRules={limit:true;format:true;arrayIndexing:{exactIndexes:true;};};type _PathToFieldsArray<T extends readonly unknown[],Options extends PathToFieldsOptions,Iteration extends number=0>=And<IsTuple<T>,IsEqual<Options["arrayIndexing"]["exactIndexes"],true>>extends true ? ValueOfArray<{[K in keyof T]:IsArrayIndex<K>extends true ? [K,..._PathToFields<T[K],Options,Increment<Iteration>>]:never;}>:ArrayElementType<T>extends infer ElementType ? [`${number}`,...(ElementType extends ElementType ? _PathToFields<ElementType,Options,Increment<Iteration>>:never)]:never;type _PathToFields<T,Options extends PathToFieldsOptions,Iteration extends number=0>=T extends Options["ignoredTypes"] ? never:T extends Options["stopTypes"] ? []:IsEqual<Iteration,Options["limit"]>extends true ? never:T extends readonly unknown[] ? _PathToFieldsArray<T,Options,Iteration>:ValueOf<{[K in Exclude<keyof T,symbol | Options["ignoredKeys"]>]:NonNullable<T[K]>extends infer NonNullableFields ? NonNullableFields extends readonly unknown[] ? [K,..._PathToFieldsArray<NonNullableFields,Options,Iteration>]:[K,..._PathToFields<NonNullableFields,Options,Increment<Iteration>>]:never;}>;
|
|
1436
|
+
/**
|
|
1437
|
+
* Get all possible paths to fields in an object
|
|
1438
|
+
* @example
|
|
1439
|
+
* ```ts
|
|
1440
|
+
* // "a" | "b" | "d"
|
|
1441
|
+
* type T0 = PathToFields<{a: string, b: number, d: boolean}>;
|
|
1442
|
+
* // ["arr.0.a", "arr.0.b", "arr.1.c"]
|
|
1443
|
+
* type T1 = PathToFields<{arr: [{a: string; b: number}, {c: boolean}]}, {
|
|
1444
|
+
* arrayIndexing: {
|
|
1445
|
+
* exactIndexes: true;
|
|
1446
|
+
* }
|
|
1447
|
+
* }>;
|
|
1448
|
+
* ```
|
|
1449
|
+
*/
|
|
1450
|
+
type PathToFields<T,Options extends PathToFieldsOptions &{overwriteDefault?:boolean;}=never>=(IsNever<Options>extends true ? DefaultPathToFieldsOptions:ApplyDefaultOptions<Omit<PathToFieldsOptions,keyof OverWritable>,Options,DefaultPathToFieldsOptions,OverwriteRules,PathToFieldsOptions["overwriteDefault"]>)extends infer MergedOptions extends PathToFieldsOptions ? _PathToFields<T,MergedOptions>extends infer Paths extends readonly(string | number)[] ? IsEqual<MergedOptions["format"],"dot">extends true ? Paths extends Paths ? Join<Paths,".">:never:Paths:never:never;
|
|
1451
|
+
/**
|
|
1452
|
+
* Make passed properties in the passed argument optional
|
|
1453
|
+
* @example
|
|
1454
|
+
* ```ts
|
|
1455
|
+
* // { a?: string, b: number }
|
|
1456
|
+
* type T0 = PartialOnly<{ a: string, b: number }, 'a'>;
|
|
1457
|
+
* ```
|
|
1458
|
+
*/
|
|
1459
|
+
type PartialOnly<T extends object,K extends keyof T>=Prettify<Pick<T,Exclude<keyof T,K>>&{[P in K]?:T[P];}>;
|
|
1460
|
+
/**
|
|
1461
|
+
* Make all properties in the passed argument optional except for the passed properties
|
|
1462
|
+
* @example
|
|
1463
|
+
* ```ts
|
|
1464
|
+
* // { a: string, b?: number }
|
|
1465
|
+
* type T0 = PartialExcept<{ a: string, b: number }, 'a'>;
|
|
1466
|
+
* ```
|
|
1467
|
+
*/
|
|
1468
|
+
type PartialExcept<T extends object,K extends keyof T>=Prettify<Pick<T,K>&{[P in Exclude<keyof T,K>]?:T[P];}>;type _Pow<Num extends number,Factor extends number,CurrentProduct extends number=1,Iteration extends unknown[]=[]>=IsEqual<Iteration["length"],Factor>extends true ? CurrentProduct:_Pow<Num,Factor,Mult<CurrentProduct,Num>,Push<Iteration,unknown>>;
|
|
1469
|
+
/**
|
|
1470
|
+
* Returns the first integer parameter raised to factor of the second integer parameter
|
|
1471
|
+
*
|
|
1472
|
+
* @example
|
|
1473
|
+
* ```ts
|
|
1474
|
+
* // 100
|
|
1475
|
+
* type Result = Pow<10, 2>
|
|
1476
|
+
* ```
|
|
1477
|
+
*/
|
|
1478
|
+
type Pow<Num extends number,Factor extends number>=_Pow<Num,Factor>;
|
|
1479
|
+
/**
|
|
1480
|
+
* Make passed properties in the passed argument readonly
|
|
1481
|
+
* @example
|
|
1482
|
+
* ```ts
|
|
1483
|
+
* // { readonly a: string, b: number }
|
|
1484
|
+
* type T0 = ReadonlyOnly<{ a: string, b: number }, 'a'>;
|
|
1485
|
+
* ```
|
|
1486
|
+
*/
|
|
1487
|
+
type ReadonlyOnly<T extends object,K extends keyof T>=Prettify<Pick<T,Exclude<keyof T,K>>&{readonly [P in K]:T[P];}>;
|
|
1488
|
+
/**
|
|
1489
|
+
* Make all properties in the passed argument readonly except for the passed properties
|
|
1490
|
+
* @example
|
|
1491
|
+
* ```ts
|
|
1492
|
+
* // { a: string, readonly b: number }
|
|
1493
|
+
* type T0 = ReadonlyExcept<{ a: string, b: number }, 'a'>;
|
|
1494
|
+
* ```
|
|
1495
|
+
*/
|
|
1496
|
+
type ReadonlyExcept<T extends object,K extends keyof T>=Prettify<Pick<T,K>&{readonly [P in Exclude<keyof T,K>]:T[P];}>;
|
|
1497
|
+
/**
|
|
1498
|
+
* Removes the index signature from the passed type
|
|
1499
|
+
* @example
|
|
1500
|
+
* ```ts
|
|
1501
|
+
* // {}
|
|
1502
|
+
* type Case1 = RemoveIndexSignature<{[x: string]: number}>
|
|
1503
|
+
* // {x: number}
|
|
1504
|
+
* type Case2 = RemoveIndexSignature<{x: number}>
|
|
1505
|
+
* ```
|
|
1506
|
+
*/
|
|
1507
|
+
type RemoveIndexSignature<T>={[Key in keyof T as Key extends `${infer _}` ? Key:never]:T[Key];};
|
|
1508
|
+
/**
|
|
1509
|
+
* Replaces all occurrences of the second string argument with the third string argument in the first string argument
|
|
1510
|
+
* @example
|
|
1511
|
+
* ```ts
|
|
1512
|
+
* // 'remove him him'
|
|
1513
|
+
* type Case1 = ReplaceAll<'remove me me', 'me', 'him'>
|
|
1514
|
+
* // 'remove me me'
|
|
1515
|
+
* type Case2 = ReplaceAll<'remove me me', 'us', 'him'>
|
|
1516
|
+
* ```
|
|
1517
|
+
*/
|
|
1518
|
+
type ReplaceAll<T extends string,Pivot extends string,ReplaceBy extends string>=T extends `${infer A}${Pivot}${infer B}` ? ReplaceAll<`${A}${ReplaceBy}${B}`,Pivot,ReplaceBy>:T;
|
|
1519
|
+
/**
|
|
1520
|
+
* Replaces the first occurrence of the second string argument with the third string argument in the first string argument
|
|
1521
|
+
* @example
|
|
1522
|
+
* ```ts
|
|
1523
|
+
* // 'remove him me'
|
|
1524
|
+
* type Case1 = Replace<'remove me me', 'me', 'him'>
|
|
1525
|
+
* // 'remove me me'
|
|
1526
|
+
* type Case2 = Replace<'remove me me', 'us', 'him'>
|
|
1527
|
+
* ```
|
|
1528
|
+
*/
|
|
1529
|
+
type Replace<T extends string,Pivot extends string,ReplaceBy extends string>=T extends `${infer A}${Pivot}${infer B}` ? `${A}${ReplaceBy}${B}`:T;
|
|
1530
|
+
/**
|
|
1531
|
+
* Make passed properties in the passed argument required
|
|
1532
|
+
* @example
|
|
1533
|
+
* ```ts
|
|
1534
|
+
* // { a: number; b?: string; c?: boolean }
|
|
1535
|
+
* type T0 = RequiredOnly<{ a?: number; b?: string; c?: boolean }, "a">;
|
|
1536
|
+
* ```
|
|
1537
|
+
*/
|
|
1538
|
+
type RequiredOnly<T extends object,K extends keyof T>=Prettify<Pick<T,Exclude<keyof T,K>>&{[P in K]-?:T[P];}>;
|
|
1539
|
+
/**
|
|
1540
|
+
* Make all properties in the passed argument required except for the passed properties
|
|
1541
|
+
* @example
|
|
1542
|
+
* ```ts
|
|
1543
|
+
* // { a?: number; b: string; c: boolean }
|
|
1544
|
+
* type T0 = RequiredExcept<{ a?: number; b?: string; c?: boolean }, "a">;
|
|
1545
|
+
* ```
|
|
1546
|
+
*/
|
|
1547
|
+
type RequiredExcept<T extends object,K extends keyof T>=Prettify<Pick<T,K>&{[P in Exclude<keyof T,K>]-?:T[P];}>;type _Reverse<T extends readonly unknown[],Result extends readonly unknown[]=[]>=IsEmptyArray<T>extends true ? Result:T extends readonly [...infer Rest extends readonly unknown[],infer First] ? _Reverse<Rest,[...Result,First]>:Result;
|
|
1548
|
+
/**
|
|
1549
|
+
* Returns a new array with the elements in reverse order.
|
|
1550
|
+
* @example
|
|
1551
|
+
* ```ts
|
|
1552
|
+
* // [3, 2, 1]
|
|
1553
|
+
* type T0 = Reverse<[1, 2, 3]>;
|
|
1554
|
+
* // [3, 2, 1]
|
|
1555
|
+
* type T1 = Reverse<readonly [1, 2, 3]>;
|
|
1556
|
+
* ```
|
|
1557
|
+
*/
|
|
1558
|
+
type Reverse<T extends readonly unknown[]>=IsTuple<T>extends true ? _Reverse<T>extends infer R extends readonly unknown[] ? IsReadonlyArray<T>extends true ? Readonly<R>:R:never:T;
|
|
1559
|
+
/**
|
|
1560
|
+
* Type version of `Math.round()`. Returns the value of a number rounded to the nearest integer
|
|
1561
|
+
* @example
|
|
1562
|
+
* ```ts
|
|
1563
|
+
* // 3
|
|
1564
|
+
* type T0 = Round<3.14>;
|
|
1565
|
+
* // -3
|
|
1566
|
+
* type T1 = Round<-3.14>;
|
|
1567
|
+
* ```
|
|
1568
|
+
*/
|
|
1569
|
+
type Round<T extends number>=IsFloat<T>extends true ? GetFloatNumberParts<T>extends [infer Whole extends number,infer Fraction extends number] ? IsGreaterThan<FirstDigit<Fraction>,4>extends true ? Increment<Whole>:Whole:never:T;type SliceRemovedItemValue=Record<"__type-samurai_internal__",symbol>;type FilterRemoved<T extends readonly unknown[],Result extends unknown[]=[]>=T extends readonly [infer First,...infer Rest extends unknown[]] ? FilterRemoved<Rest,First extends SliceRemovedItemValue ? Result:Push<Result,First>>:Result;
|
|
1570
|
+
/**
|
|
1571
|
+
* Type version of `Array.prototype.slice()` method. Returns a shallow copy of a portion of an array into a new array object selected from `start` to `end` (`end` not included)
|
|
1572
|
+
* @example
|
|
1573
|
+
* ```ts
|
|
1574
|
+
* // [2, 3]
|
|
1575
|
+
* type T0 = Slice<[1, 2, 3, 4], 1>;
|
|
1576
|
+
* // [2, 3]
|
|
1577
|
+
* type T1 = Slice<[1, 2, 3, 4], 1, 3>;
|
|
1578
|
+
* ```
|
|
1579
|
+
*/
|
|
1580
|
+
type Slice<T extends readonly unknown[],Start extends number=0,End extends number=T["length"]>=(IsEmptyArray<T>extends true ? "self":IsGreaterOrEqual<Start,T["length"]>extends true ? "empty":IsNegative<End>extends true ? IsGreaterOrEqual<Abs<End>,T["length"]>extends true ? "empty":[IfPositive<Start,Start,Sum<T["length"],Start>>,Sum<T["length"],End>]:And<Or<IsEqual<Start,0>,IsGreaterOrEqual<Abs<Start>,T["length"]>>,IsGreaterOrEqual<End,T["length"]>>extends true ? "self":[IfPositive<Start,Start,Sum<T["length"],Start>>,End])extends infer Indexes ? Indexes extends "self" ? T:Indexes extends "empty" ? []:Indexes extends [infer NewStart extends number,infer NewEnd extends number] ? IfGreaterOrEqual<NewStart,NewEnd>extends true ? []:FilterRemoved<{[K in keyof T]:IsArrayIndex<K>extends true ? If<And<IsGreaterOrEqual<ParseNumber<K>,NewStart>,IsLowerThan<ParseNumber<K>,NewEnd>>,T[K],SliceRemovedItemValue>:T[K];}>:T:T;
|
|
1581
|
+
/**
|
|
1582
|
+
* Swaps the position of two elements in a tuple.
|
|
1583
|
+
* @example
|
|
1584
|
+
* ```ts
|
|
1585
|
+
* // [3, 2, 1]
|
|
1586
|
+
* type Case1 = Swap<[1, 2, 3], 0, 2>;
|
|
1587
|
+
* // [1, 2, 3]
|
|
1588
|
+
* type Case2 = Swap<[1, 2, 3], 0, 0>;
|
|
1589
|
+
* ```
|
|
1590
|
+
*/
|
|
1591
|
+
type Swap<T extends readonly unknown[],FromIndex extends number,ToIndex extends number>=IsTuple<T>extends true ? And<IsBetween<FromIndex,0,T["length"]>,IsBetween<ToIndex,0,T["length"]>>extends true ? T[FromIndex] extends infer From ? T[ToIndex] extends infer To ?{[K in keyof T]:ParseNumber<K>extends infer NumK ? IsEqual<FromIndex,NumK>extends true ? To:IsEqual<ToIndex,NumK>extends true ? From:T[K]:never;}:never:never:never:T;type _SortSingle<Result extends readonly number[],PivotIndex extends number,CurrentIndex extends number>=IsEqual<PivotIndex,CurrentIndex>extends true ? Result:Increment<CurrentIndex>extends infer NextCurrentIndex extends number ? _SortSingle<IsGreaterThan<Result[CurrentIndex],Result[NextCurrentIndex]>extends true ? Swap<Result,CurrentIndex,NextCurrentIndex>extends infer NewResult extends readonly number[] ? NewResult:Result:Result,PivotIndex,NextCurrentIndex>:never;type _Sort<T extends readonly number[],CurrentIndex extends number>=IsLowerOrEqual<CurrentIndex,0>extends true ? T:_SortSingle<T,CurrentIndex,0>extends infer NewT extends readonly number[] ? _Sort<NewT,Decrement<CurrentIndex>>:T;
|
|
1592
|
+
/**
|
|
1593
|
+
* Sorts a tuple of numbers in ascending order.
|
|
1594
|
+
* @example
|
|
1595
|
+
* ```ts
|
|
1596
|
+
* // [1, 2, 3]
|
|
1597
|
+
* type T0 = Sort<[3, 2, 1]>;
|
|
1598
|
+
*
|
|
1599
|
+
* // [-1, 0, 1]
|
|
1600
|
+
* type T1 = Sort<[1, -1, 0]>;
|
|
1601
|
+
* ```
|
|
1602
|
+
*/
|
|
1603
|
+
type Sort<T extends readonly number[]>=IsLowerThan<T["length"],2>extends true ? T:_Sort<T,Decrement<T["length"]>>;
|
|
1604
|
+
/**
|
|
1605
|
+
* Returns a boolean whether the first string arguments starts with the second string argument
|
|
1606
|
+
* @example
|
|
1607
|
+
* ```ts
|
|
1608
|
+
* // true
|
|
1609
|
+
* type Case1 = StartsWith<'abc', 'a'>
|
|
1610
|
+
* // false
|
|
1611
|
+
* type Case2 = StartsWith<'abc', 'b'>
|
|
1612
|
+
* ```
|
|
1613
|
+
*/
|
|
1614
|
+
type StartsWith<Str extends string,Pivot extends string | number>=Str extends `${Pivot}${string}` ? true:false;
|
|
1615
|
+
/**
|
|
1616
|
+
* Type version of switch statement.
|
|
1617
|
+
* @param Cases - An object containing cases with their corresponding values.
|
|
1618
|
+
* @param Default - The default value if the condition does not match any case.
|
|
1619
|
+
* @example
|
|
1620
|
+
* ```ts
|
|
1621
|
+
* const a = 'const';
|
|
1622
|
+
*
|
|
1623
|
+
* // 'bar'
|
|
1624
|
+
* type Result = Switch<typeof a, { number: 'foo', const: 'bar' }, 'foobar'>
|
|
1625
|
+
*
|
|
1626
|
+
* ```
|
|
1627
|
+
*/
|
|
1628
|
+
type Switch<Condition extends PropertyKey,Cases extends Record<PropertyKey,unknown>,Default=never>=Condition extends keyof Cases ? Cases[Condition]:Default;
|
|
1629
|
+
/**
|
|
1630
|
+
* Turns accepted literal type argument to its primitive
|
|
1631
|
+
* @example
|
|
1632
|
+
* ```ts
|
|
1633
|
+
* // number
|
|
1634
|
+
* type Case1 = ToPrimitive<1>
|
|
1635
|
+
* // string
|
|
1636
|
+
* type Case2 = ToPrimitive<'1'>
|
|
1637
|
+
* // {a: number; b: string}
|
|
1638
|
+
* type Case3 = ToPrimitive<{a: 1; b: 's'}>
|
|
1639
|
+
* ```
|
|
1640
|
+
*/
|
|
1641
|
+
type ToPrimitive<T>=T extends string ? string:T extends number ? number:T extends null ? null:T extends undefined ? undefined:T extends boolean ? boolean:T extends bigint ? bigint:T extends symbol ? symbol:{[K in keyof T]:ToPrimitive<T[K]>;};
|
|
1642
|
+
/**
|
|
1643
|
+
* Type version of `Math.trunc()`. Returns the integer part of a number by removing any fractional digits.
|
|
1644
|
+
* @example
|
|
1645
|
+
* ```ts
|
|
1646
|
+
* // 3
|
|
1647
|
+
* type T0 = Trunc<3.14>;
|
|
1648
|
+
* // -3
|
|
1649
|
+
* type T1 = Trunc<-3.14>;
|
|
1650
|
+
* ```
|
|
1651
|
+
*/
|
|
1652
|
+
type Trunc<T extends number>=number extends T ? T:IsFloat<T>extends true ? GetFloatNumberParts<T>[0] extends infer IntegerPart extends number ? IsNegative<T>extends true ? Negate<IntegerPart>:IntegerPart:never:T;
|
|
1653
|
+
/**
|
|
1654
|
+
* Accepts a tuple of string, number or symbol and return the object type, where the key values are the elements of the tuple
|
|
1655
|
+
* @example
|
|
1656
|
+
* ```ts
|
|
1657
|
+
* // {
|
|
1658
|
+
* // foo: 'foo',
|
|
1659
|
+
* // bar: 'bar',
|
|
1660
|
+
* // }
|
|
1661
|
+
* type Result = TupleToObject<['foo', 'bar']>
|
|
1662
|
+
* ```
|
|
1663
|
+
*/
|
|
1664
|
+
type TupleToObject<T extends readonly PropertyKey[]>={[K in T[number]]:K;};
|
|
1665
|
+
/**
|
|
1666
|
+
* Turns the passed union type to an intersection
|
|
1667
|
+
* Reference: https://stackoverflow.com/a/50375286/21637817
|
|
1668
|
+
* @example
|
|
1669
|
+
* ```ts
|
|
1670
|
+
* // {a: string} & {b: string}
|
|
1671
|
+
* type Case1 = UnionToIntersection<{a: string} | {b: string}>
|
|
1672
|
+
* ```
|
|
1673
|
+
*/
|
|
1674
|
+
type UnionToIntersection<U>=(U extends any ?(k:U)=>void:never)extends(k:infer I)=>void ? I:never;
|
|
1675
|
+
/**
|
|
1676
|
+
* Adds the second argument to the beginning of the first array argument.
|
|
1677
|
+
* @example
|
|
1678
|
+
* ```ts
|
|
1679
|
+
* // ['foo', 'bar']
|
|
1680
|
+
* type Result = Unshift<['bar'], 'foo'>
|
|
1681
|
+
* ```
|
|
1682
|
+
*/
|
|
1683
|
+
type Unshift<T extends readonly unknown[],U>=[U,...T];
|
|
1684
|
+
/** --------------------------------------------------
|
|
1685
|
+
* * ***Extracts the argument types of a given function type `F`.***
|
|
1686
|
+
* --------------------------------------------------
|
|
1687
|
+
*
|
|
1688
|
+
* Useful when you need to infer or reuse the parameter types from an existing function signature.
|
|
1689
|
+
*
|
|
1690
|
+
* @template F A function type from which to extract argument types.
|
|
1691
|
+
*
|
|
1692
|
+
* @example
|
|
1693
|
+
* type Args = ArgumentTypes<(a: number, b: string) => void>; // [number, string]
|
|
1694
|
+
*/
|
|
1695
|
+
type ArgumentTypes<F extends AnyFunction>=F extends(...args:infer A)=>any ? A:never;
|
|
1696
|
+
/** --------------------------------------------------
|
|
1697
|
+
* * ***Gets the element type from a readonly array or tuple.***
|
|
1698
|
+
* --------------------------------------------------
|
|
1699
|
+
*
|
|
1700
|
+
* Useful when working with `as const` arrays to extract the union of literal types.
|
|
1701
|
+
*
|
|
1702
|
+
* @template T A readonly array or tuple type.
|
|
1703
|
+
*
|
|
1704
|
+
* @example
|
|
1705
|
+
* const roles = ['admin', 'user'] as const;
|
|
1706
|
+
* type Role = GetArrayElementType<typeof roles>; // "admin" | "user"
|
|
1707
|
+
*/
|
|
1708
|
+
type GetArrayElementType<T extends readonly any[]>=T extends readonly(infer U)[] ? U:never;
|
|
1709
|
+
/** --------------------------------------------------
|
|
1710
|
+
* * ***Converts specific keys `K` in type `T` to required (non-optional), while keeping the rest unchanged.***
|
|
1711
|
+
* --------------------------------------------------
|
|
1712
|
+
*
|
|
1713
|
+
* This is useful when you need to enforce required fields conditionally.
|
|
1714
|
+
*
|
|
1715
|
+
* @template T The base object type.
|
|
1716
|
+
* @template K The keys within `T` to make required. Defaults to all keys in `T`.
|
|
1717
|
+
*
|
|
1718
|
+
* @example
|
|
1719
|
+
* type A = { a?: string; b?: number };
|
|
1720
|
+
* type B = RequiredKeys<A, 'a'>; // { a: string; b?: number }
|
|
1721
|
+
*/
|
|
1722
|
+
type RequiredKeys<T,K extends keyof T=T>=Required<Pick<T,Extract<keyof T,K>>>& OmitStrict<T,K>extends infer O ?{[P in keyof O]:O[P];}:never;
|
|
1723
|
+
/** --------------------------------------------------
|
|
1724
|
+
* * ***Converts specific keys `K` in type `T` to optional (partial), while keeping the rest unchanged.***
|
|
1725
|
+
* --------------------------------------------------
|
|
1726
|
+
*
|
|
1727
|
+
* Useful when certain keys should be optional in certain contexts (e.g., form inputs).
|
|
1728
|
+
*
|
|
1729
|
+
* @template T The base object type.
|
|
1730
|
+
* @template K The keys within `T` to make optional. Defaults to all keys in `T`.
|
|
1731
|
+
*
|
|
1732
|
+
* @example
|
|
1733
|
+
* type A = { a: string; b: number };
|
|
1734
|
+
* type B = PartialKeys<A, 'a'>; // { a?: string; b: number }
|
|
1735
|
+
*/
|
|
1736
|
+
type PartialKeys<T,K extends keyof T=T>=Partial<Pick<T,Extract<keyof T,K>>>& OmitStrict<T,K>extends infer O ?{[P in keyof O]:O[P];}:never;
|
|
1737
|
+
/** --------------------------------------------------
|
|
1738
|
+
* * ***Overrides properties in type `T` with properties from type `U`, based on matching keys.***
|
|
1739
|
+
* --------------------------------------------------
|
|
1740
|
+
*
|
|
1741
|
+
* Ensures the result retains all properties from `T`, but values from `U` override corresponding keys.
|
|
1742
|
+
*
|
|
1743
|
+
* @template T The base object type to override.
|
|
1744
|
+
* @template U The object type containing overriding properties.
|
|
1745
|
+
*
|
|
1746
|
+
* @example
|
|
1747
|
+
* type A = { a: number; b: string };
|
|
1748
|
+
* type B = { b: boolean };
|
|
1749
|
+
* type C = OverrideTypes<A, B>; // { a: number; b: boolean }
|
|
1750
|
+
*/
|
|
1751
|
+
type OverrideTypes<T,U extends Partial<Record<keyof T,unknown>>>=OmitStrict<T,keyof U>& U extends infer U ?{[K in keyof U]:U[K];}:never;
|
|
1752
|
+
/** ---------------------------------
|
|
1753
|
+
* * ***Strictly omits keys `K` from type `T`, with optional flattening for readability using `Prettify`.***
|
|
1754
|
+
* ---------------------------------
|
|
1755
|
+
*
|
|
1756
|
+
* Greatly enhances autocomplete and type inspection clarity in editors by optionally flattening
|
|
1757
|
+
* nested intersections or mapped types into a cleaner shape.
|
|
1758
|
+
*
|
|
1759
|
+
* @template T The original object type.
|
|
1760
|
+
* @template K The keys to omit from `T`.
|
|
1761
|
+
* @template WithPrettify Whether to prettify the result (default is `true`).
|
|
1762
|
+
* @template WithPrettifyRecursive Whether to prettify nested object properties recursively (defaults to `true`).
|
|
1763
|
+
*
|
|
1764
|
+
* @example
|
|
1765
|
+
* type A = { a: number; b: string; c: boolean };
|
|
1766
|
+
* type B = OmitStrict<A, 'b'>;
|
|
1767
|
+
* // -> { a: number; c: boolean }
|
|
1768
|
+
*
|
|
1769
|
+
* type C = OmitStrict<A, 'b', false>;
|
|
1770
|
+
* // -> Omit without prettifying, keeps intersection structure
|
|
1771
|
+
*
|
|
1772
|
+
* type D = OmitStrict<A, 'b', true, false>;
|
|
1773
|
+
* // -> Prettifies only top level, does not recurse into nested objects
|
|
1774
|
+
*
|
|
1775
|
+
*/
|
|
1776
|
+
type OmitStrict<T,K extends keyof T,WithPrettify extends boolean=true,WithPrettifyRecursive extends boolean=true>=WithPrettify extends true ? Prettify<Omit<T,K>,{recursive:WithPrettifyRecursive;}>:WithPrettify extends false ? Omit<T,K>:never;
|
|
1777
|
+
/** ---------------------------------
|
|
1778
|
+
* * ***Pick Key Type Property with Enhanced Type Autocomplete.***
|
|
1779
|
+
* ---------------------------------
|
|
1780
|
+
*
|
|
1781
|
+
* Utility type that behaves exactly like the native `Pick<T, K>`, but can help with
|
|
1782
|
+
* type inference and IDE autocomplete in more constrained generic scenarios.
|
|
1783
|
+
*
|
|
1784
|
+
* @template T The base object type.
|
|
1785
|
+
* @template K The keys from `T` to be picked.
|
|
1786
|
+
*
|
|
1787
|
+
* @example
|
|
1788
|
+
* type A = { a: number; b: string; c: boolean };
|
|
1789
|
+
* type B = PickStrict<A, 'a' | 'c'>; // { a: number; c: boolean }
|
|
1790
|
+
*/
|
|
1791
|
+
type PickStrict<T,K extends keyof T>=Pick<T,K>;
|
|
1792
|
+
/** ---------------------------------
|
|
1793
|
+
* * ***Exclude Key Type Property with Enhanced Type Autocomplete.***
|
|
1794
|
+
* ---------------------------------
|
|
1795
|
+
*
|
|
1796
|
+
* Utility type that performs a stricter version of `Exclude<T, U>` by ensuring better type
|
|
1797
|
+
* narrowing and improved behavior in complex generic conditions.
|
|
1798
|
+
*
|
|
1799
|
+
* Especially useful in generic libraries or utility types where standard `Exclude` may
|
|
1800
|
+
* collapse or widen types unintentionally.
|
|
1801
|
+
*
|
|
1802
|
+
* @template T The full union or set of types.
|
|
1803
|
+
* @template U The type(s) to be excluded from `T`.
|
|
1804
|
+
*
|
|
1805
|
+
* @example
|
|
1806
|
+
* type A = 'a' | 'b' | 'c';
|
|
1807
|
+
* type B = ExcludeStrict<A, 'b'>; // 'a' | 'c'
|
|
1808
|
+
*/
|
|
1809
|
+
type ExcludeStrict<T,U extends T>=T extends unknown ? 0 extends(U extends T ?([T] extends [U] ? 0:never):never)? never:T:never;
|
|
1810
|
+
/** --------------------------------------------------
|
|
1811
|
+
* * ***Identity utility type that preserves the structure and inference of type `T`.***
|
|
1812
|
+
* --------------------------------------------------
|
|
1813
|
+
*
|
|
1814
|
+
* This is commonly used to force TypeScript to expand a mapped or intersection type
|
|
1815
|
+
* into a more readable and usable shape.
|
|
1816
|
+
*
|
|
1817
|
+
* @template T The type to preserve and normalize.
|
|
1818
|
+
*
|
|
1819
|
+
* @example
|
|
1820
|
+
* type A = { a: string; b: number };
|
|
1821
|
+
* type B = Identity<A>; // Same as A, but fully expanded in IDEs
|
|
1822
|
+
*/
|
|
1823
|
+
type Identity<T>={[P in keyof T]:T[P];};
|
|
1824
|
+
/** --------------------------------------------------
|
|
1825
|
+
* * ***Replaces specified keys in a type with a new value type, making them optional.***
|
|
1826
|
+
* --------------------------------------------------
|
|
1827
|
+
*
|
|
1828
|
+
* This is useful when certain properties in a type should allow partial overrides
|
|
1829
|
+
* while keeping the rest of the structure intact.
|
|
1830
|
+
*
|
|
1831
|
+
* @template TypeToBeChecked The original object type.
|
|
1832
|
+
* @template KeyToBeReplaced The keys in the original type to be replaced.
|
|
1833
|
+
* @template NewValueToUse The new type to assign to the replaced keys.
|
|
1834
|
+
*
|
|
1835
|
+
* @example
|
|
1836
|
+
* type A = { name: string; age: number };
|
|
1837
|
+
* type B = ReplacingToPartial<A, 'age', string>; // { name: string; age?: string }
|
|
1838
|
+
*/
|
|
1839
|
+
type ReplacingToPartial<TypeToBeChecked,KeyToBeReplaced extends keyof TypeToBeChecked,NewValueToUse>=Identity<Pick<TypeToBeChecked,Exclude<keyof TypeToBeChecked,KeyToBeReplaced>>&{[P in KeyToBeReplaced]?:NewValueToUse;}>;
|
|
1840
|
+
/** --------------------------------------------------
|
|
1841
|
+
* * ***Replaces specified keys in a type with a new value type, making them required.***
|
|
1842
|
+
* --------------------------------------------------
|
|
1843
|
+
*
|
|
1844
|
+
* This is useful when redefining a property’s type while ensuring it's required in the resulting structure.
|
|
1845
|
+
*
|
|
1846
|
+
* @template TypeToBeChecked The original object type.
|
|
1847
|
+
* @template KeyToBeReplaced The keys in the original type to be replaced.
|
|
1848
|
+
* @template NewValueToUse The new type to assign to the replaced keys.
|
|
1849
|
+
*
|
|
1850
|
+
* @example
|
|
1851
|
+
* type A = { name?: string; age: number };
|
|
1852
|
+
* type B = ReplacingToRequired<A, 'name', string>; // { name: string; age: number }
|
|
1853
|
+
*/
|
|
1854
|
+
type ReplacingToRequired<TypeToBeChecked,KeyToBeReplaced extends keyof TypeToBeChecked,NewValueToUse>=Identity<Pick<TypeToBeChecked,Exclude<keyof TypeToBeChecked,KeyToBeReplaced>>&{[P in KeyToBeReplaced]:NewValueToUse;}>;
|
|
1855
|
+
/** --------------------------------------------------
|
|
1856
|
+
* * ***Represents an object with arbitrary string keys and values of any type.***
|
|
1857
|
+
* --------------------------------------------------
|
|
1858
|
+
*
|
|
1859
|
+
* This type is commonly used as a fallback or catch-all for flexible key-value structures
|
|
1860
|
+
* such as query parameters, configuration maps, or JSON-like data.
|
|
1861
|
+
*
|
|
1862
|
+
* ⚠️ Use with caution — `any` disables type safety. Prefer stricter typing when possible.
|
|
1863
|
+
*
|
|
1864
|
+
* @example
|
|
1865
|
+
* const config: ObjArrayKeyStringAny = {
|
|
1866
|
+
* mode: "dark",
|
|
1867
|
+
* retries: 3,
|
|
1868
|
+
* debug: true,
|
|
1869
|
+
* };
|
|
1870
|
+
*/
|
|
1871
|
+
type ObjArrayKeyStringAny={[key:string]:any;};
|
|
1872
|
+
/** --------------------------------------------------
|
|
1873
|
+
* * ***Represents a broad union of commonly used JavaScript data types.***
|
|
1874
|
+
* --------------------------------------------------
|
|
1875
|
+
*
|
|
1876
|
+
* Includes primitive types, `object`, `null`, `undefined`, `symbol`, and a function signature.
|
|
1877
|
+
* This type is useful for scenarios where you need to support a wide range of inputs,
|
|
1878
|
+
* such as dynamic data processors, serializers, or value validators.
|
|
1879
|
+
*
|
|
1880
|
+
* @example
|
|
1881
|
+
* function isValidType(value: DataTypes): boolean {
|
|
1882
|
+
* return value !== undefined && value !== null;
|
|
1883
|
+
* }
|
|
1884
|
+
*/
|
|
1885
|
+
type DataTypes=bigint | boolean |((string?:any)=>void)| null | number | object | string | symbol | undefined;
|
|
1886
|
+
/** --------------------------------------------------
|
|
1887
|
+
* * ***A custom extension of the native `Promise` type that allows explicit typing for both the resolved (`onSuccess`) and rejected (`onError`) values.***
|
|
1888
|
+
* --------------------------------------------------
|
|
1889
|
+
*
|
|
1890
|
+
* This type is useful when you want to strongly type both the success and error cases of an asynchronous operation,
|
|
1891
|
+
* particularly in scenarios like server actions, remote procedure calls (RPC), or custom async wrappers.
|
|
1892
|
+
*
|
|
1893
|
+
* @template onSuccess The type of the resolved value when the promise is fulfilled.
|
|
1894
|
+
* @template onError The type of the rejection reason when the promise is rejected. Defaults to `any`.
|
|
1895
|
+
*
|
|
1896
|
+
* @example
|
|
1897
|
+
* const fetchUser = (): CustomPromise<User, ApiError> => {
|
|
1898
|
+
* return customRequest().catch(err => {
|
|
1899
|
+
* handleError(err); // `err` is typed as `ApiError`
|
|
1900
|
+
* return fallbackUser;
|
|
1901
|
+
* });
|
|
1902
|
+
* };
|
|
1903
|
+
*
|
|
1904
|
+
* fetchUser().then(user => {
|
|
1905
|
+
* // user is typed as `User`
|
|
1906
|
+
* });
|
|
1907
|
+
*/
|
|
1908
|
+
type CustomPromise<onSuccess,onError=any>={catch<TResult=never>(onrejected?:((reason:onError)=>TResult | PromiseLike<TResult>)| undefined | null):Promise<onSuccess | TResult>;}& Promise<onSuccess>;
|
|
1909
|
+
/** ---------------------------------
|
|
1910
|
+
* * ***Helper: Prettify a Type or Interface for Easier Readability***
|
|
1911
|
+
* ---------------------------------
|
|
1912
|
+
*
|
|
1913
|
+
* This utility type recursively resolves and flattens the structure of a given type,
|
|
1914
|
+
* making the resulting type easier to read in IDE tooltips or inline type inspection.
|
|
1915
|
+
*
|
|
1916
|
+
* It is especially useful when dealing with deeply nested generics or intersection types
|
|
1917
|
+
* that are difficult to interpret directly.
|
|
1918
|
+
*
|
|
1919
|
+
* @template T The type or interface to prettify.
|
|
1920
|
+
*
|
|
1921
|
+
* @example
|
|
1922
|
+
* // Without Prettify:
|
|
1923
|
+
* type Result = A & B & { extra: string };
|
|
1924
|
+
*
|
|
1925
|
+
* // With Prettify:
|
|
1926
|
+
* type Result = PrettifyOld<A & B & { extra: string }>;
|
|
1927
|
+
*
|
|
1928
|
+
* @deprecated use type `Prettify` instead.
|
|
1929
|
+
*/
|
|
1930
|
+
type PrettifyOld<T>={[K in keyof T]:T[K] extends object ? PrettifyOld<T[K]>:T[K];}&{};
|
|
1931
|
+
/** --------------------------------------------------
|
|
1932
|
+
* * ***Represents common whitespace characters.***
|
|
1933
|
+
* --------------------------------------------------
|
|
1934
|
+
*
|
|
1935
|
+
* Used as the default trimming characters.
|
|
1936
|
+
*/
|
|
1937
|
+
type Whitespace=" " | "\t" | "\r" | "\n";
|
|
1938
|
+
/** --------------------------------------------------
|
|
1939
|
+
* * ***Recursively trims specified characters (default: whitespace) from the start (left) of a string.***
|
|
1940
|
+
* --------------------------------------------------
|
|
1941
|
+
*
|
|
1942
|
+
* @template Text The string to trim.
|
|
1943
|
+
* @template Chars The characters to remove from the beginning of the string. Defaults to `Whitespace`.
|
|
1944
|
+
*
|
|
1945
|
+
* @example
|
|
1946
|
+
* type T = TrimLeft<"\n hello", " " | "\n">; // "hello"
|
|
1947
|
+
*/
|
|
1948
|
+
type TrimLeft<Text extends string,Chars extends string | number=Whitespace>=Text extends `${Chars}${infer Rest}` ? TrimLeft<Rest,Chars>:Text;
|
|
1949
|
+
/** --------------------------------------------------
|
|
1950
|
+
* * ***Recursively trims specified characters (default: whitespace) from the end (right) of a string.***
|
|
1951
|
+
* --------------------------------------------------
|
|
1952
|
+
*
|
|
1953
|
+
* @template Text The string to trim.
|
|
1954
|
+
* @template Chars The characters to remove from the end of the string. Defaults to `Whitespace`.
|
|
1955
|
+
*
|
|
1956
|
+
* @example
|
|
1957
|
+
* type T = TrimRight<"hello \t", " " | "\t">; // "hello"
|
|
1958
|
+
*/
|
|
1959
|
+
type TrimRight<Text extends string,Chars extends string | number=Whitespace>=Text extends `${infer Rest}${Chars}` ? TrimRight<Rest,Chars>:Text;
|
|
1960
|
+
/** --------------------------------------------------
|
|
1961
|
+
* * ***Trims specified characters (default: whitespace) from both the start and end of a string.***
|
|
1962
|
+
* --------------------------------------------------
|
|
1963
|
+
*
|
|
1964
|
+
* @template Text The string to trim.
|
|
1965
|
+
* @template Chars The characters to remove. Defaults to `Whitespace`.
|
|
1966
|
+
*
|
|
1967
|
+
* @example
|
|
1968
|
+
* type T = Trim<" hello ", " ">; // "hello"
|
|
1969
|
+
*/
|
|
1970
|
+
type Trim<Text extends string,Chars extends string | number=Whitespace>=TrimRight<TrimLeft<Text,Chars>,Chars>;
|
|
1971
|
+
/** --------------------------------------------------
|
|
1972
|
+
* * ***Replaces all occurrences of a pattern in a string with a replacement string.***
|
|
1973
|
+
* --------------------------------------------------
|
|
1974
|
+
*
|
|
1975
|
+
* @template Text The input string.
|
|
1976
|
+
* @template Pattern The substring to replace.
|
|
1977
|
+
* @template Replacement The replacement string. Defaults to an empty string.
|
|
1978
|
+
*
|
|
1979
|
+
* @example
|
|
1980
|
+
* type T = ReplaceAllOld<"foo-bar-bar", "bar", "baz">; // "foo-baz-baz"
|
|
1981
|
+
*
|
|
1982
|
+
* @deprecated use `ReplaceAll` instead.
|
|
1983
|
+
*/
|
|
1984
|
+
type ReplaceAllOld<Text extends string,Pattern extends string | number,Replacement extends string="">=Text extends `${infer Start extends string}${Pattern}${infer Rest extends string}` ? `${Start}${Replacement}${ReplaceAllOld<Rest,Pattern,Replacement>}`:Text;
|
|
1985
|
+
/** --------------------------------------------------
|
|
1986
|
+
* * ***Converts a string to lowercase and trims leading and trailing whitespace.***
|
|
1987
|
+
* --------------------------------------------------
|
|
1988
|
+
*
|
|
1989
|
+
* @template S The input string.
|
|
1990
|
+
*
|
|
1991
|
+
* @example
|
|
1992
|
+
* type T = TrimsLower<" HeLLo \n">; // "hello"
|
|
1993
|
+
*/
|
|
1994
|
+
type TrimsLower<S extends string>=Trim<Lowercase<S>>;
|
|
1995
|
+
/** --------------------------------------------------
|
|
1996
|
+
* * ***Recursively traverses an array (or nested object structure) and replaces all values of a given type (`Target`) with `NewType`.***
|
|
1997
|
+
* --------------------------------------------------
|
|
1998
|
+
*
|
|
1999
|
+
* Useful for remapping deeply nested arrays or records.
|
|
2000
|
+
*
|
|
2001
|
+
* @template Arr The input array or object.
|
|
2002
|
+
* @template Target The type to match and replace.
|
|
2003
|
+
* @template NewType The new type to assign in place of `Target`.
|
|
2004
|
+
*
|
|
2005
|
+
* @example
|
|
2006
|
+
* type A = [number, string, [number]];
|
|
2007
|
+
* type B = ChangeTypeOfValuesArray<A, number, boolean>; // [boolean, string, [boolean]]
|
|
2008
|
+
*/
|
|
2009
|
+
type ChangeTypeOfValuesArray<Arr,Target,NewType>=Arr extends object ?{[K in keyof Arr]:ChangeTypeOfValuesArray<Arr[K],Target,NewType>;}:NewType;
|
|
2010
|
+
/** --------------------------------------------------
|
|
2011
|
+
* * ***A generic type representing any function with any arguments and any return type.***
|
|
2012
|
+
* --------------------------------------------------
|
|
2013
|
+
*
|
|
2014
|
+
* @function {(...args: any[]) => any} AnyFunction
|
|
2015
|
+
*
|
|
2016
|
+
* @example
|
|
2017
|
+
* const fn: AnyFunction = (a, b) => a + b;
|
|
2018
|
+
* console.log(fn(1, 2)); // 3
|
|
2019
|
+
*/
|
|
2020
|
+
type AnyFunction=(...args:any[])=>any;type Enumerate<N extends number,Acc extends number[]=[]>=Acc["length"] extends N ? Acc[number]:Enumerate<N,[...Acc,Acc["length"]]>;
|
|
2021
|
+
/** --------------------------------------------------
|
|
2022
|
+
* * ***Generate a union type of numbers within a specific range from `1` to `999`.***
|
|
2023
|
+
* --------------------------------------------------
|
|
2024
|
+
*
|
|
2025
|
+
* @template From Starting number of the range (inclusive).
|
|
2026
|
+
* @template To Ending number of the range (inclusive).
|
|
2027
|
+
*
|
|
2028
|
+
* @description
|
|
2029
|
+
* Produces a union of numbers from `From` to `To` (inclusive).
|
|
2030
|
+
* Maximum `From` or `To` supported is `999` to prevent
|
|
2031
|
+
* `"Type instantiation is excessively deep and possibly infinite.ts(2589)"`.
|
|
2032
|
+
*
|
|
2033
|
+
* @example
|
|
2034
|
+
* type Range = RangeNumberTo999<3, 6>;
|
|
2035
|
+
* // => 3 | 4 | 5 | 6
|
|
2036
|
+
*/
|
|
2037
|
+
type RangeNumberTo999<From extends number,To extends number>=From extends To ? From:Exclude<Enumerate<To>,Enumerate<From>>extends never ? never:Exclude<Enumerate<To>,Enumerate<From>>| To;
|
|
2038
|
+
/** --------------------------------------------------
|
|
2039
|
+
* * ***Generate a union type of numbers within a specified range.***
|
|
2040
|
+
* --------------------------------------------------
|
|
2041
|
+
*
|
|
2042
|
+
* @template From Starting number of the range (inclusive).
|
|
2043
|
+
* @template To Ending number of the range (inclusive).
|
|
2044
|
+
* @template Result Accumulator for recursion (internal use).
|
|
2045
|
+
*
|
|
2046
|
+
* @description
|
|
2047
|
+
* Generates a numeric union type from `From` to `To` (inclusive).
|
|
2048
|
+
* Maximum `To` supported is `999` to avoid
|
|
2049
|
+
* `"Type instantiation is excessively deep and possibly infinite.ts(2589)"`.
|
|
2050
|
+
*
|
|
2051
|
+
* Example:
|
|
2052
|
+
* ```ts
|
|
2053
|
+
* type MyRange = RangeNumberLimit<5, 8>;
|
|
2054
|
+
* // => 5 | 6 | 7 | 8
|
|
2055
|
+
* ```
|
|
2056
|
+
*/
|
|
2057
|
+
type RangeNumberLimit<From extends number,To extends number,Result extends number[]=[From]>=IsGreaterThan<From,To>extends true ? [...Result,To][number] extends infer R extends number ? R extends R ? IsGreaterThan<R,To>extends true ? never:R:never:never:RangeNumberLimit<Sum<From,7>,To,[...Result,From,Sum<From,1>,Sum<From,2>,Sum<From,3>,Sum<From,4>,Sum<From,5>,Sum<From,6>]>;export type{Abs,And,AndArr,AnifyProperties,AnifyPropertiesOptions,AnyFunction,AreAnagrams,ArgumentTypes,ArrayElementType,Ceil,ChangeTypeOfValuesArray,Color,ColorCssValidBase,ColorOptions,CompareNumberLength,CompareStringLength,Concat,CustomPromise,DataTypes,Decrement,DefaultColorOptions,DefaultHSLOptions,DefaultRGBOptions,DigitsTuple,Div,Dot,EmptyArray,EmptyString,EndsWith,Even,ExcludeStrict,Extends,ExtendsArr,Factorial,Fibonacci,FirstCharacter,FirstCharacterOptions,FirstDigit,Float,Floor,GetArrayElementType,GetFloatNumberParts,HEX,HSL,HSLOptions,Identity,If,IfAny,IfColor,IfEmptyArray,IfEmptyString,IfEqual,IfEven,IfExtends,IfFloat,IfGreaterOrEqual,IfGreaterThan,IfHEX,IfHSL,IfInteger,IfLowerThan,IfNegative,IfNegativeFloat,IfNegativeInteger,IfNever,IfNonEmptyArray,IfNonEmptyString,IfNot,IfNotEqual,IfNotExtends,IfOdd,IfPositive,IfPositiveFloat,IfPositiveInteger,IfRGB,IfUnknown,Includes,Increment,IndexOf,Integer,IsAny,IsArray,IsArrayIndex,IsBetween,IsColor,IsDivisible,IsDivisibleByFive,IsDivisibleByHundred,IsDivisibleBySix,IsDivisibleByTen,IsDivisibleByThree,IsDivisibleByTwo,IsEmptyArray,IsEmptyString,IsEqual,IsEven,IsFloat,IsGreaterOrEqual,IsGreaterThan,IsHEX,IsHSL,IsInteger,IsLetter,IsLongerNumber,IsLongerString,IsLowerThan,IsMutableArray,IsNegative,IsNegativeFloat,IsNegativeInteger,IsNever,IsNonEmptyArray,IsNonEmptyString,IsNotEqual,IsOdd,IsPalindrome,IsPositive,IsPositiveFloat,IsPositiveInteger,IsRGB,IsReadonlyArray,IsSameLengthNumber,IsSameLengthString,IsShorterNumber,IsShorterString,IsStringLiteral,IsTuple,IsUnion,IsUnknown,Join,LastCharacter,LastCharacterOptions,Max,MaxArr,Min,MinArr,Mod,Mult,Mutable,MutableExcept,MutableOnly,Negate,Negative,NegativeFloat,NegativeInteger,NeverifyProperties,NeverifyPropertiesOptions,NonEmptyArray,NonEmptyString,NonNullableObject,NonNullableObjectExcept,NonNullableObjectOnly,Not,NotExtends,NumberLength,ObjArrayKeyStringAny,Odd,OmitStrict,Or,OrArr,OverrideTypes,ParseNumber,PartialExcept,PartialKeys,PartialOnly,PathToFields,PathToFieldsOptions,PickStrict,Pop,PopOptions,Positive,PositiveFloat,PositiveInteger,Pow,Prettify,PrettifyOld,PrettifyOptions,Push,RGB,RGBOptions,RangeNumberLimit,RangeNumberTo999,ReadonlyExcept,ReadonlyOnly,RemoveIndexSignature,RemoveLeading,Repeat,Replace,ReplaceAll,ReplaceAllOld,ReplacingToPartial,ReplacingToRequired,RequiredExcept,RequiredKeys,RequiredOnly,ReturnItselfIfExtends,ReturnItselfIfNotExtends,Reverse,Round,Shift,ShiftOptions,Slice,Sort,Split,StartsWith,StringLength,Stringify,Sub,Sum,SumArr,Swap,Switch,ToPrimitive,Trim,TrimLeft,TrimRight,TrimsLower,Trunc,TupleToObject,UnionToIntersection,UnknownifyProperties,UnknownifyPropertiesOptions,Unshift,ValueOf,ValueOfArray,ValueOfExcept,ValueOfOnly,Whitespace};
|