@rzl-zone/utils-js 3.3.0 → 3.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,952 +0,0 @@
1
- import{O as OrArr,A as And,a as AndArr}from'./or-C6qzKt2I.js';import{E as Extends,N as Not,I as IfExtends,a as NotExtends}from'./extends-DtdRjDyU.js';import{I as If}from'./if-ChM35c_q.js';import{T as Trim,I as IfNot}from'./string-B1jlOnws.js';import{I as IsNever}from'./never-D89PbPh5.js';import{I as IsAny}from'./any-v4TsK9ES.js';import{P as Prettify}from'./prettify-3o8_Kw6b.js';
2
- /** -------------------------------------------------------
3
- * * ***Utility Type: `IsStringLiteral`.***
4
- * -------------------------------------------------------
5
- * **Returns a boolean whether the passed argument is literal string.**
6
- * @template T - The type value to check.
7
- * @example
8
- * type Case1 = IsStringLiteral<'a'>; // ➔ true
9
- * type Case2 = IsStringLiteral<1>; // ➔ false
10
- * type Case3 = IsStringLiteral<string>; // ➔ false
11
- */
12
- type IsStringLiteral<T>=If<Extends<T,string>,Extends<string,T>extends true?false:true>;
13
- /** -------------------------------------------------------
14
- * * ***Utility Type: `Push`.***
15
- * -------------------------------------------------------
16
- * **Appends a type `U` to the end of a tuple or readonly array type `T`.**
17
- * @template T - The tuple or readonly array type to append U.
18
- * @template U - The type of the element to push.
19
- * @example
20
- * ```ts
21
- * type Case1 = Push<[1, 2, 3, 4], 5>;
22
- * // ➔ [1, 2, 3, 4, 5]
23
- *
24
- * type Case2 = Push<["a", "b"], "c">;
25
- * // ➔ ["a", "b", "c"]
26
- * ```
27
- */
28
- type Push<T extends readonly unknown[],U>=[...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>>;
29
- /** -------------------------------------------------------
30
- * * ***Utility Type: `Repeat`.***
31
- * -------------------------------------------------------
32
- * **Repeats a string literal type `T` a specified number of times `Count`.**
33
- * - **Behavior:**
34
- * - Supports a range of `[0, 999]` due to TypeScript recursion limits.
35
- * - If `Count > 999`, it is automatically to `any` because error `Type instantiation is excessively deep and possibly infinite.ts(2589)`.
36
- * @template T - The string literal to repeat.
37
- * @template Count - Number of times to repeat.
38
- * @example
39
- * ```ts
40
- * type Case0 = Repeat<'x', 0>; // ➔ ''
41
- * type Case1 = Repeat<'x', 1>; // ➔ 'x'
42
- * type Case2 = Repeat<'x', 5>; // ➔ 'xxxxx'
43
- * type Case3 = Repeat<'ab', 3>; // ➔ 'ababab'
44
- *
45
- * // ❌ Invalid:
46
- * type Case1000 = Repeat<'x', 1000>;
47
- * // ➔ same as any (because: TypeScript recursion limits)
48
- * ```
49
- */
50
- type Repeat<T extends string,Count extends number>=_Repeat<T,Count>;
51
- /** -------------------------------------------------------
52
- * * ***Utility Type: `OddDigit`.***
53
- * -------------------------------------------------------
54
- * **A union of string literal digits considered ***odd***.**
55
- * - Includes: `"1" | "3" | "5" | "7" | "9"`.
56
- * @example
57
- * ```ts
58
- * type A = OddDigit; // ➔ "1" | "3" | "5" | "7" | "9"
59
- * ```
60
- */
61
- type OddDigit="1"|"3"|"5"|"7"|"9";
62
- /** -------------------------------------------------------
63
- * * ***Utility Type: `EvenDigit`.***
64
- * -------------------------------------------------------
65
- * **A union of string literal digits considered ***even***.**
66
- * - Includes: `"0" | "2" | "4" | "6" | "8"`.
67
- * @example
68
- * ```ts
69
- * type A = EvenDigit; // ➔ "0" | "2" | "4" | "6" | "8"
70
- * ```
71
- */
72
- type EvenDigit="0"|"2"|"4"|"6"|"8";
73
- /** -------------------------------------------------------
74
- * * ***Utility Type: `Integer`.***
75
- * -------------------------------------------------------
76
- * **A type-level utility that validates if `T` is an ***integer***.**
77
- * - **Behavior:**
78
- * - Returns `T` if it is an integer.
79
- * - Returns `never` if `T` is a ***float*** (decimal).
80
- * @template T - A number type to validate.
81
- * @example
82
- * ```ts
83
- * type A = Integer<42>; // ➔ 42
84
- * type B = Integer<-10>; // ➔ -10
85
- * type C = Integer<3.14>; // ➔ never
86
- * ```
87
- */
88
- type Integer<T extends number>=`${T}`extends`${string}.${string}`?never:T;
89
- /** -------------------------------------------------------
90
- * * ***Utility Type: `Float`.***
91
- * -------------------------------------------------------
92
- * **A type-level utility that validates if `T` is a ***float***.**
93
- * - **Behavior:**
94
- * - Returns `T` if it is a float.
95
- * - Returns `never` if `T` is an ***integer***.
96
- * @template T - A number type to validate.
97
- * @example
98
- * ```ts
99
- * type A = Float<3.14>; // ➔ 3.14
100
- * type B = Float<42>; // ➔ never
101
- * ```
102
- */
103
- type Float<T extends number>=If<IsNever<Integer<T>>,T,never>;
104
- /** -------------------------------------------------------
105
- * * ***Utility Type: `Negative`.***
106
- * -------------------------------------------------------
107
- * **Extracts `T` if it is ***negative***, otherwise `never`.**
108
- * @template T - A number type to check.
109
- * @example
110
- * ```ts
111
- * type A = Negative<-10>; // ➔ -10
112
- * type B = Negative<5>; // ➔ never
113
- * type C = Negative<0>; // ➔ never
114
- * ```
115
- */
116
- type Negative<T extends number>=`${T}`extends`-${string}`?T:never;
117
- /** -------------------------------------------------------
118
- * * ***Utility Type: `Positive`.***
119
- * -------------------------------------------------------
120
- * **Extracts `T` if it is ***positive*** (or zero), otherwise `never`.**
121
- * @template T - A number type to check.
122
- * @example
123
- * ```ts
124
- * type A = Positive<10>; // ➔ 10
125
- * type B = Positive<0>; // ➔ 0
126
- * type C = Positive<-5>; // ➔ never
127
- * ```
128
- */
129
- type Positive<T extends number>=If<IsNever<Negative<T>>,T,never>;
130
- /** -------------------------------------------------------
131
- * * ***Utility Type: `PositiveInteger`.***
132
- * -------------------------------------------------------
133
- * **Restricts `T` to ***positive integers*** only.**
134
- * @template T - A number type.
135
- * @example
136
- * ```ts
137
- * type A = PositiveInteger<42>; // ➔ 42
138
- * type B = PositiveInteger<0>; // ➔ 0
139
- * type C = PositiveInteger<-5>; // ➔ never
140
- * type D = PositiveInteger<3.14>; // ➔ never
141
- * ```
142
- */
143
- type PositiveInteger<T extends number>=Positive<Integer<T>>;
144
- /** -------------------------------------------------------
145
- * * ***Utility Type: `NegativeInteger`.***
146
- * -------------------------------------------------------
147
- * **Restricts `T` to ***negative integers*** only.**
148
- * @template T - A number type.
149
- * @example
150
- * ```ts
151
- * type A = NegativeInteger<-42>; // ➔ -42
152
- * type B = NegativeInteger<5>; // ➔ never
153
- * type C = NegativeInteger<-3.14>; // ➔ never
154
- * ```
155
- */
156
- type NegativeInteger<T extends number>=Negative<Integer<T>>;
157
- /** -------------------------------------------------------
158
- * * ***Utility Type: `PositiveFloat`.***
159
- * -------------------------------------------------------
160
- * **Restricts `T` to ***positive floats*** only.**
161
- * @template T - A number type.
162
- * @example
163
- * ```ts
164
- * type A = PositiveFloat<3.14>; // ➔ 3.14
165
- * type B = PositiveFloat<-2.5>; // ➔ never
166
- * type C = PositiveFloat<5>; // ➔ never
167
- * ```
168
- */
169
- type PositiveFloat<T extends number>=Positive<Float<T>>;
170
- /** -------------------------------------------------------
171
- * * ***Utility Type: `NegativeFloat`.***
172
- * -------------------------------------------------------
173
- * **Restricts `T` to ***negative floats*** only.**
174
- * @template T - A number type.
175
- * @example
176
- * ```ts
177
- * type A = NegativeFloat<-3.14>; // ➔ -3.14
178
- * type B = NegativeFloat<2.5>; // ➔ never
179
- * type C = NegativeFloat<-5>; // ➔ never
180
- * ```
181
- */
182
- type NegativeFloat<T extends number>=Negative<Float<T>>;
183
- /** -------------------------------------------------------
184
- * * ***Utility Type: `Even`.***
185
- * -------------------------------------------------------
186
- * **A type-level utility that extracts `T` if it is an ***even integer***.**
187
- * @template T - A number type to check.
188
- * @example
189
- * ```ts
190
- * type A = Even<0>; // ➔ 0
191
- * type B = Even<4>; // ➔ 4
192
- * type C = Even<5>; // ➔ never
193
- * type D = Even<24>; // ➔ 24
194
- * type E = Even<27>; // ➔ never
195
- * type F = Even<3.14>; // ➔ never
196
- * ```
197
- */
198
- type Even<T extends number>=IfNot<IsNever<Integer<T>>,`${T}`extends`${string}${EvenDigit}`?T:never,never>;
199
- /** -------------------------------------------------------
200
- * * ***Utility Type: `Odd`.***
201
- * -------------------------------------------------------
202
- * **A type-level utility that extracts `T` if it is an ***odd integer***.**
203
- * @template T - A number type to check.
204
- * @example
205
- * ```ts
206
- * type A = Odd<0>; // ➔ never
207
- * type B = Odd<5>; // ➔ 5
208
- * type C = Odd<4>; // ➔ never
209
- * type D = Odd<23>; // ➔ 23
210
- * type E = Odd<26>; // ➔ never
211
- * type F = Odd<4.2>; // ➔ never
212
- * ```
213
- */
214
- type Odd<T extends number>=IfNot<IsNever<Integer<T>>,If<IsNever<Even<T>>,T,never>,never>;
215
- /** -------------------------------------------------------
216
- * * ***Utility Type: `IsInteger`.***
217
- * -------------------------------------------------------
218
- * **Whether `T` is an ***integer***.**
219
- * @example
220
- * ```ts
221
- * type A = IsInteger<-2>; // ➔ true
222
- * type B = IsInteger<0>; // ➔ true
223
- * type C = IsInteger<42>; // ➔ true
224
- * type D = IsInteger<3.14>; // ➔ false
225
- * ```
226
- */
227
- type IsInteger<T extends number>=Not<IsNever<Integer<T>>>;
228
- /** -------------------------------------------------------
229
- * * ***Utility Type: `IsFloat`.***
230
- * -------------------------------------------------------
231
- * **Whether `T` is a ***float***.**
232
- * @example
233
- * ```ts
234
- * type A = IsFloat<3.14>; // ➔ true
235
- * type B = IsFloat<-3.14>; // ➔ true
236
- * type C = IsFloat<0>; // ➔ false
237
- * type D = IsFloat<42>; // ➔ false
238
- * type E = IsFloat<-42>; // ➔ false
239
- * ```
240
- */
241
- type IsFloat<T extends number>=Not<IsNever<Float<T>>>;
242
- /** -------------------------------------------------------
243
- * * ***Utility Type: `IsEven`.***
244
- * -------------------------------------------------------
245
- * **Whether `T` is ***even***.**
246
- * @example
247
- * ```ts
248
- * type A = IsEven<0>; // ➔ true
249
- * type B = IsEven<4>; // ➔ true
250
- * type C = IsEven<5>; // ➔ false
251
- * type D = IsEven<24>; // ➔ true
252
- * type E = IsEven<27>; // ➔ false
253
- * type F = IsEven<3.14>; // ➔ false
254
- * ```
255
- */
256
- type IsEven<T extends number>=If<IsInteger<T>,`${T}`extends`${string}${EvenDigit}`?true:false>;
257
- /** -------------------------------------------------------
258
- * * ***Utility Type: `IsOdd`.***
259
- * -------------------------------------------------------
260
- * **Whether `T` is ***odd***.**
261
- * @example
262
- * ```ts
263
- * type A = IsEven<0>; // ➔ false
264
- * type B = IsEven<4>; // ➔ false
265
- * type C = IsEven<5>; // ➔ true
266
- * type D = IsEven<24>; // ➔ false
267
- * type E = IsEven<27>; // ➔ true
268
- * type F = IsEven<3.14>; // ➔ true
269
- * ```
270
- */
271
- type IsOdd<T extends number>=If<IsInteger<T>,Not<IsEven<T>>>;
272
- /** -------------------------------------------------------
273
- * * ***Utility Type: `IsPositive`.***
274
- * -------------------------------------------------------
275
- * **Whether `T` is ***positive***.**
276
- * @example
277
- * ```ts
278
- * type A = IsPositive<10>; // ➔ true
279
- * type B = IsPositive<0>; // ➔ true
280
- * type C = IsPositive<-5>; // ➔ false
281
- * type D = IsPositive<3.5>; // ➔ true
282
- * type E = IsPositive<-3.5>; // ➔ false
283
- * ```
284
- */
285
- type IsPositive<T extends number>=Not<IsNever<Positive<T>>>;
286
- /** -------------------------------------------------------
287
- * * ***Utility Type: `IsNegative`.***
288
- * -------------------------------------------------------
289
- * **Whether `T` is ***negative***.**
290
- * @example
291
- * ```ts
292
- * type A = IsNegative<-10>; // ➔ true
293
- * type B = IsNegative<5>; // ➔ false
294
- * type C = IsNegative<0>; // ➔ false
295
- * type D = IsPositive<3.5>; // ➔ false
296
- * type E = IsPositive<-3.5>; // ➔ true
297
- * ```
298
- */
299
- type IsNegative<T extends number>=Not<IsNever<Negative<T>>>;
300
- /** -------------------------------------------------------
301
- * * ***Utility Type: `IsPositiveInteger`.***
302
- * -------------------------------------------------------
303
- * **Whether `T` is a ***positive integer***.**
304
- * @example
305
- * ```ts
306
- * type A = IsPositiveInteger<42>; // ➔ true
307
- * type B = IsPositiveInteger<0>; // ➔ true
308
- * type C = IsPositiveInteger<-5>; // ➔ false
309
- * type D = IsPositiveInteger<3.14>; // ➔ false
310
- * ```
311
- */
312
- type IsPositiveInteger<T extends number>=Not<IsNever<PositiveInteger<T>>>;
313
- /** -------------------------------------------------------
314
- * * ***Utility Type: `IsNegativeInteger`.***
315
- * -------------------------------------------------------
316
- * **Whether `T` is a ***negative integer***.**
317
- * @example
318
- * ```ts
319
- * type A = IsNegativeInteger<-42>; // ➔ true
320
- * type B = IsNegativeInteger<5>; // ➔ false
321
- * type C = IsNegativeInteger<-3.14>; // ➔ false
322
- * ```
323
- */
324
- type IsNegativeInteger<T extends number>=Not<IsNever<NegativeInteger<T>>>;
325
- /** -------------------------------------------------------
326
- * * ***Utility Type: `IsPositiveFloat`.***
327
- * -------------------------------------------------------
328
- * **Whether `T` is a ***positive float***.**
329
- * @example
330
- * ```ts
331
- * type A = IsPositiveFloat<3.14>; // ➔ true
332
- * type B = IsPositiveFloat<-2.5>; // ➔ false
333
- * type C = IsPositiveFloat<5>; // ➔ false
334
- * ```
335
- */
336
- type IsPositiveFloat<T extends number>=Not<IsNever<PositiveFloat<T>>>;
337
- /** -------------------------------------------------------
338
- * * ***Utility Type: `IsNegativeFloat`.***
339
- * -------------------------------------------------------
340
- * **Whether `T` is a ***negative float***.**
341
- * @example
342
- * ```ts
343
- * type A = IsNegativeFloat<-3.14>; // ➔ true
344
- * type B = IsNegativeFloat<2.5>; // ➔ false
345
- * type C = IsNegativeFloat<-5>; // ➔ false
346
- * ```
347
- */
348
- type IsNegativeFloat<T extends number>=Not<IsNever<NegativeFloat<T>>>;
349
- /** -------------------------------------------------------
350
- * * ***Utility Type: `IfInteger`.***
351
- * -------------------------------------------------------
352
- * **Conditional: `If` branch if `T` is an ***integer***.**
353
- * @example
354
- * ```ts
355
- * type A = IfInteger<42>; // ➔ true
356
- * type B = IfInteger<3.14>; // ➔ false
357
- * type C = IfInteger<42, "yes", "no">; // ➔ "yes"
358
- * type D = IfInteger<3.14, "yes", "no">; // ➔ "no"
359
- * ```
360
- */
361
- type IfInteger<T extends number,IfTrue=true,IfFalse=false>=If<IsInteger<T>,IfTrue,IfFalse>;
362
- /** -------------------------------------------------------
363
- * * ***Utility Type: `IfFloat`.***
364
- * -------------------------------------------------------
365
- * **Conditional: selects one of two branches depending on whether `T` is a ***float***.**
366
- * - Defaults: `IfTrue = true`, `IfFalse = false`.
367
- * @template T - A number type.
368
- * @template IfTrue - The branch type if condition is met, (default: `true`).
369
- * @template IfFalse - The branch type if condition is not met, (default: `false`).
370
- * @example
371
- * ```ts
372
- * type A = IfFloat<3.14>; // ➔ true
373
- * type B = IfFloat<42>; // ➔ false
374
- * type C = IfFloat<3.14, "yes", "no">; // ➔ "yes"
375
- * type D = IfFloat<42, "yes", "no">; // ➔ "no"
376
- * ```
377
- */
378
- type IfFloat<T extends number,IfTrue=true,IfFalse=false>=If<IsFloat<T>,IfTrue,IfFalse>;
379
- /** -------------------------------------------------------
380
- * * ***Utility Type: `IfEven`.***
381
- * -------------------------------------------------------
382
- * **Conditional: selects one of two branches depending on whether `T` is ***even***.**
383
- * - Defaults: `IfTrue = true`, `IfFalse = false`.
384
- * @template T - A number type.
385
- * @template IfTrue - The branch type if condition is met, (default: `true`).
386
- * @template IfFalse - The branch type if condition is not met, (default: `false`).
387
- * @example
388
- * ```ts
389
- * type A = IfEven<4>; // ➔ true
390
- * type B = IfEven<5>; // ➔ false
391
- * type C = IfEven<4, "even", "odd">; // ➔ "even"
392
- * type D = IfEven<5, "even", "odd">; // ➔ "odd"
393
- * ```
394
- */
395
- type IfEven<T extends number,IfTrue=true,IfFalse=false>=If<IsEven<T>,IfTrue,IfFalse>;
396
- /** -------------------------------------------------------
397
- * * ***Utility Type: `IfOdd`.***
398
- * -------------------------------------------------------
399
- * **Conditional: selects one of two branches depending on whether `T` is ***odd***.**
400
- * - Defaults: `IfTrue = true`, `IfFalse = false`.
401
- * @template T - A number type.
402
- * @template IfTrue - The branch type if condition is met, (default: `true`).
403
- * @template IfFalse - The branch type if condition is not met, (default: `false`).
404
- * @example
405
- * ```ts
406
- * type A = IfOdd<5>; // ➔ true
407
- * type B = IfOdd<4>; // ➔ false
408
- * type C = IfOdd<5, "odd", "even">; // ➔ "odd"
409
- * type D = IfOdd<4, "odd", "even">; // ➔ "even"
410
- * ```
411
- */
412
- type IfOdd<T extends number,IfTrue=true,IfFalse=false>=If<IsOdd<T>,IfTrue,IfFalse>;
413
- /** -------------------------------------------------------
414
- * * ***Utility Type: `IfPositive`.***
415
- * -------------------------------------------------------
416
- * **Conditional: selects one of two branches depending on whether `T` is ***positive***.**
417
- * - Defaults: `IfTrue = true`, `IfFalse = false`.
418
- * @template T - A number type.
419
- * @template IfTrue - The branch type if condition is met, (default: `true`).
420
- * @template IfFalse - The branch type if condition is not met, (default: `false`).
421
- * @example
422
- * ```ts
423
- * type A = IfPositive<10>; // ➔ true
424
- * type B = IfPositive<-5>; // ➔ false
425
- * type C = IfPositive<10, "yes", "no">; // ➔ "yes"
426
- * type D = IfPositive<-5, "yes", "no">; // ➔ "no"
427
- * ```
428
- */
429
- type IfPositive<T extends number,IfTrue=true,IfFalse=false>=If<IsPositive<T>,IfTrue,IfFalse>;
430
- /** -------------------------------------------------------
431
- * * ***Utility Type: `IfNegative`.***
432
- * -------------------------------------------------------
433
- * **Conditional: selects one of two branches depending on whether `T` is ***negative***.**
434
- * - Defaults: `IfTrue = true`, `IfFalse = false`.
435
- * @template T - A number type.
436
- * @template IfTrue - The branch type if condition is met, (default: `true`).
437
- * @template IfFalse - The branch type if condition is not met, (default: `false`).
438
- * @example
439
- * ```ts
440
- * type A = IfNegative<-10>; // ➔ true
441
- * type B = IfNegative<5>; // ➔ false
442
- * type C = IfNegative<-10, "yes", "no">; // ➔ "yes"
443
- * type D = IfNegative<5, "yes", "no">; // ➔ "no"
444
- * ```
445
- */
446
- type IfNegative<T extends number,IfTrue=true,IfFalse=false>=If<IsNegative<T>,IfTrue,IfFalse>;
447
- /** -------------------------------------------------------
448
- * * ***Utility Type: `IfPositiveInteger`.***
449
- * -------------------------------------------------------
450
- * **Conditional: selects one of two branches depending on whether `T` is a ***positive integer***.**
451
- * - Defaults: `IfTrue = true`, `IfFalse = false`.
452
- * @template T - A number type.
453
- * @template IfTrue - The branch type if condition is met, (default: `true`).
454
- * @template IfFalse - The branch type if condition is not met, (default: `false`).
455
- * @example
456
- * ```ts
457
- * type A = IfPositiveInteger<42>; // ➔ true
458
- * type B = IfPositiveInteger<-5>; // ➔ false
459
- * type C = IfPositiveInteger<42, "yes", "no">; // ➔ "yes"
460
- * type D = IfPositiveInteger<-5, "yes", "no">; // ➔ "no"
461
- * ```
462
- */
463
- type IfPositiveInteger<T extends number,IfTrue=true,IfFalse=false>=If<IsPositiveInteger<T>,IfTrue,IfFalse>;
464
- /** -------------------------------------------------------
465
- * * ***Utility Type: `IfNegativeInteger`.***
466
- * -------------------------------------------------------
467
- * **Conditional: selects one of two branches depending on whether `T` is a ***negative integer***.**
468
- * - Defaults: `IfTrue = true`, `IfFalse = false`.
469
- * @template T - A number type.
470
- * @template IfTrue - The branch type if condition is met, (default: `true`).
471
- * @template IfFalse - The branch type if condition is not met, (default: `false`) .
472
- * @example
473
- * ```ts
474
- * type A = IfNegativeInteger<-42>; // ➔ true
475
- * type B = IfNegativeInteger<5>; // ➔ false
476
- * type C = IfNegativeInteger<-42, "yes", "no">; // ➔ "yes"
477
- * type D = IfNegativeInteger<5, "yes", "no">; // ➔ "no"
478
- * ```
479
- */
480
- type IfNegativeInteger<T extends number,IfTrue=true,IfFalse=false>=If<IsNegativeInteger<T>,IfTrue,IfFalse>;
481
- /** -------------------------------------------------------
482
- * * ***Utility Type: `IfPositiveFloat`.***
483
- * -------------------------------------------------------
484
- * **Conditional: selects one of two branches depending on whether `T` is a ***positive float***.**
485
- * - Defaults: `IfTrue = true`, `IfFalse = false`.
486
- * @template T - A number type.
487
- * @template IfTrue - The branch type if condition is met, (default: `true`).
488
- * @template IfFalse - The branch type if condition is not met, (default: `false`).
489
- * @example
490
- * ```ts
491
- * type A = IfPositiveFloat<3.14>; // ➔ true
492
- * type B = IfPositiveFloat<-2.5>; // ➔ false
493
- * type C = IfPositiveFloat<3.14, "yes", "no">; // ➔ "yes"
494
- * type D = IfPositiveFloat<-2.5, "yes", "no">; // ➔ "no"
495
- * ```
496
- */
497
- type IfPositiveFloat<T extends number,IfTrue=true,IfFalse=false>=If<IsPositiveFloat<T>,IfTrue,IfFalse>;
498
- /** -------------------------------------------------------
499
- * * ***Utility Type: `IfNegativeFloat`.***
500
- * -------------------------------------------------------
501
- * **Conditional: selects one of two branches depending on whether `T` is a ***negative float***.**
502
- * - Defaults: `IfTrue = true`, `IfFalse = false`.
503
- * @template T - A number type.
504
- * @template IfTrue - The branch type if condition is met, (default: `true`).
505
- * @template IfFalse - The branch type if condition is not met, (default: `false`).
506
- * @example
507
- * ```ts
508
- * type A = IfNegativeFloat<-3.14>; // ➔ true
509
- * type B = IfNegativeFloat<2.5>; // ➔ false
510
- * type C = IfNegativeFloat<-3.14, "yes", "no">; // ➔ "yes"
511
- * type D = IfNegativeFloat<2.5, "yes", "no">; // ➔ "no"
512
- * ```
513
- */
514
- type IfNegativeFloat<T extends number,IfTrue=true,IfFalse=false>=If<IsNegativeFloat<T>,IfTrue,IfFalse>;
515
- /** -------------------------------------------------------
516
- * * ***Utility Type: `ParseNumber`.***
517
- * --------------------------------------------------------
518
- * **Converts a string or property key literal into a ***number literal***.**
519
- * - **Behavior:**
520
- * - Supports decimal numbers only.
521
- * - Automatically trims whitespace.
522
- * - Returns the number literal if valid.
523
- * - Supports scientific notation strings (e.g., `"2e-3"`, `"-5e2"`, `"2E-3"`, `"-5E2"`).
524
- * - **Note:**
525
- * - TypeScript cannot represent very small (`< 1e-6`) or very large (`> 1e15`)
526
- * numbers as literal types:
527
- * - In such cases, scientific notation strings return `0`.
528
- * - Returns `0` for strings representing hexadecimal (`0x...`), octal (`0o...`), or
529
- * binary (`0b...`) if they are string literals.
530
- * - Returns `never` for non-numeric strings or unsupported formats.
531
- * @template T - A string, number, or symbol (property key).
532
- * @example
533
- * ```ts
534
- * // Number:
535
- * type A = ParseNumber<0>; // ➔ 0
536
- * type B = ParseNumber<-0>; // ➔ 0
537
- * type C = ParseNumber<-0.>; // ➔ 0
538
- * type D = ParseNumber<42>; // ➔ 42
539
- * type E = ParseNumber<0.42>; // ➔ 0.42
540
- * type F = ParseNumber<-5>; // ➔ -5
541
- * type G = ParseNumber<-2.5>; // ➔ -2.5
542
- * type H = ParseNumber<2.5e3>; // ➔ 2500
543
- * type I = ParseNumber<-2.5e3>;// ➔ -2500
544
- * type J = ParseNumber<5e3>; // ➔ 5000
545
- * type K = ParseNumber<-5e3>; // ➔ -5000
546
- * type L = ParseNumber<5e21>; // ➔ 5e+21
547
- * type M = ParseNumber<5e-3>; // ➔ 0.005
548
- * type N = ParseNumber<5e-21>; // ➔ 5e-21
549
- * type O = ParseNumber<-5e-3>; // ➔ -0.005
550
- *
551
- * // Numeric String:
552
- * type A = ParseNumber<"0">; // ➔ 0
553
- * type B = ParseNumber<"-0">; // ➔ 0
554
- * type C = ParseNumber<"42">; // ➔ 42
555
- * type D = ParseNumber<"0.42">; // ➔ 0.42
556
- * type E = ParseNumber<"-42">; // ➔ -42
557
- * type F = ParseNumber<"-0.42">; // ➔ -0.42
558
- * type G = ParseNumber<" 42 ">; // ➔ 42
559
- * type H = ParseNumber<" -42 ">; // ➔ -1
560
- *
561
- * // Scientific notation string:
562
- * type S1 = ParseNumber<"2e3">; // ➔ 2000
563
- * type S2 = ParseNumber<"-2e3">; // ➔ -2000
564
- * type S3 = ParseNumber<"2e-3">; // ➔ 0.002
565
- * type S4 = ParseNumber<"-2e-3">; // ➔ -0.002
566
- * type S5 = ParseNumber<"2.5e3">; // ➔ 0
567
- * type S6 = ParseNumber<"2.5e-3">; // ➔ 0
568
- * type S7 = ParseNumber<"2e-7">; // ➔ 0 (too small include "-2e-7" for TypeScript literal)
569
- * type S8 = ParseNumber<"5e21">; // ➔ 0 (too large include "-5e21" for TypeScript literal)
570
- *
571
- * // Number representing hexadecimal, octal or binary:
572
- * type A = ParseNumber<"011">; // ➔ 9 (same as octal but deprecated)
573
- * type B = ParseNumber<"0o11">; // ➔ 9 (octal)
574
- * type C = ParseNumber<"-0o11">; // ➔ -9 (octal)
575
- * type D = ParseNumber<"0x12">; // ➔ 18 (hexadecimal)
576
- * type E = ParseNumber<"-0x12">; // ➔ -18 (hexadecimal)
577
- * type F = ParseNumber<"0b111">; // ➔ 7 (binary)
578
- * type G = ParseNumber<"-0b111">; // ➔ -7 (binary)
579
- *
580
- * // String representing hexadecimal, octal or binary:
581
- * type A = ParseNumber<"0x2A">; // ➔ 0 (hex on string not supported)
582
- * type B = ParseNumber<"0o52">; // ➔ 0 (octal on string not supported)
583
- * type C = ParseNumber<"0b101010">; // ➔ 0 (binary on string not supported)
584
- *
585
- * // Never Result
586
- * type A = ParseNumber<string>; // ➔ never
587
- * type B = ParseNumber<number>; // ➔ never
588
- * type C = ParseNumber<"abc">; // ➔ never
589
- * type D = ParseNumber<"a1">; // ➔ never
590
- * type E = ParseNumber<"3b">; // ➔ never
591
- * ```
592
- */
593
- type ParseNumber<T extends PropertyKey|bigint>=T extends bigint?T:If<number extends T?false:true,IfExtends<OrArr<[ Extends<`-0`,Trim<Extract<T,PropertyKey>>>,Extends<-0,T>,Extends<T,`${"-" | ""}${"0"}.`>]>,true,0,T extends`${"-" | ""}0${"x" | "b" | "o"}${number}`?0:Trim<Extract<T,PropertyKey>>extends`${infer NumT extends number | string}`?T extends`${infer N extends number}.`?N:NumT extends string?ParseScientificNumber<NumT>:NumT:Trim<Extract<T,PropertyKey>>extends number?T:never>,never>;
594
- /** -------------------------------------------------------
595
- * * ***Utility Type: `IsScientificNumber`.***
596
- * -------------------------------------------------------
597
- * **Checks if a string literal `T` represents a **scientific number**.**
598
- * - **A scientific number is defined as a number in the form of:**
599
- * - Optional negative sign (`-`).
600
- * - Mantissa (digits, can be integer or decimal).
601
- * - Exponent indicated by `e` or `E`.
602
- * - Exponent value (digits, optional negative sign).
603
- * - **Important:**
604
- * - TypeScript cannot detect numeric literals in scientific notation
605
- * at type-level because number literals are normalized to decimals:
606
- * - Only string literals like `"2.5E3"` or `"-1e-5"` can be detected.
607
- * @template T - A string literal to check.
608
- * @example
609
- * ```ts
610
- * type A = IsScientificNumber<"1e5">; // ➔ true
611
- * type B = IsScientificNumber<"-1e-5">; // ➔ true
612
- * type C = IsScientificNumber<"2.5E3">; // ➔ true
613
- * type D = IsScientificNumber<"42">; // ➔ false
614
- * type E = IsScientificNumber<"-0.42">; // ➔ false
615
- * type F = IsScientificNumber<string>; // ➔ false
616
- * ```
617
- * @remarks
618
- * - Uses template literal types and conditional type {@link Extends | **`Extends`**}.
619
- * - Returns `true` if `T` is scientific number string literal, otherwise `false`.
620
- * - Returns `boolean` if `T` is generic `string`.
621
- */
622
- type IsScientificNumber<T extends string>=Extends<T,`${"-" | ""}${number}${"e" | "E"}${number}`>;
623
- /** * ***Helper for {@link ParseScientificNumber | **`ParseScientificNumber`**}.*** */
624
- type BuildTuple<L extends number,T extends unknown[]=[]>=T["length"] extends L?T:BuildTuple<L,[...T,unknown]>;
625
- /** * ***Helper for {@link ParseScientificNumber | **`ParseScientificNumber`**}.*** */
626
- type _DecrementParseScientific<N extends number>=BuildTuple<N>extends [ infer _,...infer Rest]?Rest["length"]:never;
627
- /** -------------------------------------------------------
628
- * * ***Utility Type: `ParseScientificNumber`.***
629
- * -------------------------------------------------------
630
- * **Converts a numeric string in scientific notation (e.g., `"2e-3"`, `"-5e2"`)
631
- * into a literal number type.**
632
- * - **Important:**
633
- * - TypeScript cannot represent very small or very large numbers
634
- * as literal types:
635
- * - In such cases, this utility will return `0`.
636
- * @template T - A numeric string to parse. Can be in:
637
- * - Positive or negative scientific notation (e.g., `"1e3"`, `"-2e-2"`).
638
- * - Regular number literal (e.g., `"42"`, `"-5"`).
639
- * @example
640
- * ```ts
641
- * type A1 = ParseScientificNumber<"2e-3">; // ➔ 0.002
642
- * type A2 = ParseScientificNumber<"-2e-3">; // ➔ -0.002
643
- * type A3 = ParseScientificNumber<"5e2">; // ➔ 500
644
- * type A4 = ParseScientificNumber<"-5e2">; // ➔ -500
645
- * type A5 = ParseScientificNumber<"2e-7">; // ➔ 0 (TypeScript cannot represent literal)
646
- * type A6 = ParseScientificNumber<"5e21">; // ➔ 0 (TypeScript cannot represent literal)
647
- * type A7 = ParseScientificNumber<"42">; // ➔ 42
648
- * type A8 = ParseScientificNumber<"-42">; // ➔ -42
649
- * ```
650
- * @remarks
651
- * - Uses type-level string manipulation to handle scientific notation.
652
- * - Negative exponents are adjusted with {@link _DecrementParseScientific | **`_DecrementParseScientific`**} and
653
- * {@link Repeat | **`Repeat`**}.
654
- * - Returns `0` if TypeScript cannot infer the exact numeric literal.
655
- */
656
- type ParseScientificNumber<T extends string>=T extends`-${infer Mantissa}${"e" | "E"}-${infer Exp extends number}`?`-${"0."}${Repeat<"0", _DecrementParseScientific<Exp>>}${Mantissa}`extends`${infer N extends number}`?number extends N?0:N:never:T extends`${infer Mantissa}${"e" | "E"}-${infer Exp extends number}`?`0.${Repeat<"0", _DecrementParseScientific<Exp>>}${Mantissa}`extends`${infer N extends number}`?number extends N?0:N:never:T extends`-${infer Mantissa}${"e" | "E"}${infer Exp extends number}`?`-${Mantissa}${Repeat<"0", Exp>}`extends`${infer N extends number}`?number extends N?0:N:never:T extends`${infer Mantissa}${"e" | "E"}${infer Exp extends number}`?`${Mantissa}${Repeat<"0", Exp>}`extends`${infer N extends number}`?number extends N?0:N:never:T extends`${infer N extends number}`?number extends N?0:N:never;
657
- /** -------------------------------------------------------
658
- * * ***Utility Type: `Abs`.***
659
- * -------------------------------------------------------
660
- * **Computes the ***absolute value*** of `T`.**
661
- * - **Behavior:**
662
- * - Accepts `number` literals or numeric `string` literals.
663
- * - Returns the ***absolute value*** as a `number`.
664
- * - If `T` is not a valid number, ***`like`***:
665
- * - `hex`, `binary`, `octal`, or `non-numeric string` will return `never`.
666
- * @template T - A number type or string literal representing a number.
667
- * @example
668
- * ```ts
669
- * type A = Abs<-42>; // ➔ 42
670
- * type B = Abs<10>; // ➔ 10
671
- * type C = Abs<"11">; // ➔ 11
672
- * type D = Abs<"-11">; // ➔ 11
673
- *
674
- * // Not a number
675
- * type Invalid1 = Abs<"1a">; // ➔ never
676
- * type Invalid2 = Abs<"a1">; // ➔ never
677
- * type Invalid3 = Abs<"a1a">; // ➔ never
678
- * type Invalid4 = Abs<"abc">; // ➔ never
679
- * type Invalid5 = Abs<string>; // ➔ never
680
- * type Invalid6 = Abs<number>; // ➔ never
681
- * ```
682
- */
683
- type Abs<T extends PropertyKey|bigint>=`${Exclude<T, symbol>}`extends`-${infer PositiveT extends number}`?ParseNumber<PositiveT>:ParseNumber<T>;
684
- /** -------------------------------------------------------
685
- * * ***Utility Type: `Negate`.***
686
- * -------------------------------------------------------
687
- * **Produces the ***negated value*** of `T` (multiplies by `-1`).**
688
- * - **Behavior:**
689
- * - Only supports valid **number literals** or **numeric-strings**.
690
- * - Invalid numeric-strings (***like***: `"1a"`, `"abc"`, `hex`, `binary`, `octal`)
691
- * or `non-numeric` types, ***`like`***:
692
- * - `string`, `number`, `symbol` will return `0`.
693
- * @template T - A number type or numeric-string.
694
- * @example
695
- * ```ts
696
- * type A = Negate<5>; // ➔ -5
697
- * type B = Negate<-10>; // ➔ -10
698
- * type C = Negate<0>; // ➔ 0
699
- * type D = Negate<-0>; // ➔ 0
700
- * type E = Negate<"123">; // ➔ -123
701
- *
702
- * // Not a number or numeric-string:
703
- * type Invalid1 = Negate<string>; // ➔ 0
704
- * type Invalid2 = Negate<number>; // ➔ 0
705
- * type Invalid3 = Negate<"abc">; // ➔ 0
706
- * type Invalid4 = Negate<"1a">; // ➔ 0
707
- * type Invalid5 = Negate<"2b">; // ➔ 0
708
- * type Invalid6 = Negate<"0x1f">; // ➔ 0
709
- * type Invalid7 = Negate<"0b101">; // ➔ 0
710
- * type Invalid8 = Negate<"0o77">; // ➔ 0
711
- * ```
712
- */
713
- type Negate<T extends PropertyKey>=ParseNumber<`-${Abs<ParseNumber<T>>}`>;
714
- /** -------------------------------------------------------
715
- * * ***Utility Type: `Split`***
716
- * -------------------------------------------------------
717
- * **A type-level utility that mimics `String.prototype.split()`.**
718
- * @description
719
- * Splits a string literal `Str` into a tuple of substrings,
720
- * using `Del` as the delimiter.
721
- * - **Behavior:**
722
- * - If `Del` is the empty string `""`, the result is a tuple of characters.
723
- * - If `Del` is not found in `Str`, the result is a tuple with the original string.
724
- * - Works only with string literals. If `Str` is just `string`, the result is `string[]`.
725
- * @template Str - The input string literal to be split.
726
- * @template Del - The delimiter used to split the string.
727
- * Defaults to `""` (character-level split).
728
- * @constraints
729
- * - `Str` must be a string literal to get precise results.
730
- * - `Del` can be a string or number (numbers are converted to strings).
731
- * @example
732
- * ```ts
733
- * // ✅ Split into characters
734
- * type A = Split<"abc">; // ➔ ["a", "b", "c"]
735
- *
736
- * // ✅ Split by a comma
737
- * type B = Split<"a,b,c", ",">; // ➔ ["a", "b", "c"]
738
- *
739
- * // ✅ Split by multi-char delimiter
740
- * type C = Split<"2025-08-22", "-">; // ➔ ["2025", "08", "22"]
741
- *
742
- * // ✅ Delimiter not found ➔ returns whole string
743
- * type D = Split<"hello", "|">; // ➔ ["hello"]
744
- *
745
- * // ⚠️ Non-literal string
746
- * type E = Split<string, ",">; // string[]
747
- * ```
748
- */
749
- 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];
750
- /** @private ***types for {@link CharAt}.*** */
751
- type _CharAt<I extends string,N extends number|`${number}`,_S extends string[]=Split<I,"">>=IfExtends<And<Extends<IsPositive<ParseNumber<N>>,true>,Extends<And<Extends<N,keyof _S>,Extends<IsStringLiteral<I>,true>>,true>>,true,_S[Extract<N,keyof _S>],undefined>;
752
- /** -------------------------------------------------------
753
- * * ***Utility Type: `CharAt`.***
754
- * -------------------------------------------------------
755
- * **A type-level utility that extracts the character at a given index `N`
756
- * from a string literal type `I`.**
757
- * - **Behavior:**
758
- * - If the index is out of range, the result is `undefined`.
759
- * - If `I` is not a literal string (just `string`), the result is `undefined`.
760
- * - Only **positive indices** are supported (`0` and above`).
761
- * @template I - The input string literal to extract the character from.
762
- * @template N - The zero-based index of the character to retrieve.
763
- * @example
764
- * ```ts
765
- * // ✅ Basic usage
766
- * type A = CharAt<"hello", 0>; // ➔ "h"
767
- * type B = CharAt<"hello", 1>; // ➔ "e"
768
- * type C = CharAt<"hello", 4>; // ➔ "o"
769
- *
770
- * // ⚠️ Index out of range ➔ undefined
771
- * type D = CharAt<"hello", 5>; // ➔ undefined
772
- * type E = CharAt<"abc", 99>; // ➔ undefined
773
- *
774
- * // ✅ Stringified index also works
775
- * type F = CharAt<"testing", "0">; // ➔ "t"
776
- * type G = CharAt<"testing", "2">; // ➔ "s"
777
- * type H = CharAt<"testing", "6">; // ➔ "g"
778
- * type I = CharAt<"testing", "7">; // ➔ undefined
779
- *
780
- * // ⚠️ Non-literal strings ➔ undefined
781
- * type J = CharAt<string, 2>; // ➔ undefined
782
- *
783
- * // ⚠️ Negative indices are not supported
784
- * type K = CharAt<"abc", -1>; // ➔ undefined
785
- * ```
786
- */
787
- type CharAt<I extends string,N extends number|`${number}`>=_CharAt<I,N>;
788
- /** -------------------------------------------------------
789
- * * ***Utility Type: `IsUnknown`.***
790
- * -------------------------------------------------------
791
- * **Returns a boolean indicating whether the given type `T` is `unknown`.**
792
- * @template T - The type to check.
793
- * @example
794
- * ```ts
795
- * type TrueResult = IsUnknown<unknown>; // ➔ true
796
- * type FalseResult1 = IsUnknown<any>; // ➔ false
797
- * type FalseResult2 = IsUnknown<string>; // ➔ false
798
- * ```
799
- */
800
- type IsUnknown<T>=IsAny<T>extends true?false:[unknown] extends [T]?true:false;
801
- /** -------------------------------------------------------
802
- * * ***Utility Type: `IfUnknown`.***
803
- * -------------------------------------------------------
804
- * - **Conditional type:**
805
- * - Returns `IfTrue` if `T` is `unknown`, otherwise returns `IfFalse`.
806
- * @template T - The type to check.
807
- * @template IfTrue - The type returned if `T` is `unknown` (default: `true`).
808
- * @template IfFalse - The type returned if `T` is not `unknown` (default: `false`).
809
- * @example
810
- * ```ts
811
- * type Result1 = IfUnknown<unknown, "foo", "bar">; // ➔ "foo"
812
- * type Result2 = IfUnknown<string, "foo", "bar">; // ➔ "bar"
813
- * ```
814
- */
815
- type IfUnknown<T,IfTrue=true,IfFalse=false>=If<IsUnknown<T>,IfTrue,IfFalse>;
816
- /** ---------------------------------------------------------------------------
817
- * * ***Type Options for {@link UnknownifyProperties | `UnknownifyProperties`}.***
818
- * ---------------------------------------------------------------------------
819
- * @property makeOptional - If `true`, all properties become optional.
820
- */
821
- type UnknownifyPropertiesOptions={
822
- /**
823
- * If `true`, all properties of the object become optional.
824
- *
825
- * DefaultValue: `false`.
826
- *
827
- * @default false
828
- * @example
829
- * ```ts
830
- * type A = { a: string; b: number };
831
- * type B = UnknownifyProperties<A, { makeOptional: true }>;
832
- * // ➔ { a?: unknown; b?: unknown }
833
- * ```
834
- */
835
- makeOptional:boolean;};
836
- /** -------------------------------------------------------
837
- * * ***Utility Type: `UnknownifyProperties`.***
838
- * -------------------------------------------------------
839
- * **Transforms all properties of an object type `T` to `unknown`.**
840
- * @description Optionally, makes all properties optional based on `Options`.
841
- * @template T - The object type to transform.
842
- * @template Options - Configuration options (default: `{ makeOptional: false }`).
843
- *
844
- * @example
845
- * ```ts
846
- * type A = { a: string; b: number };
847
- * type Result1 = UnknownifyProperties<A>;
848
- * // ➔ { a: unknown; b: unknown }
849
- * type Result2 = UnknownifyProperties<A, { makeOptional: true }>;
850
- * // ➔ { a?: unknown; b?: unknown }
851
- * ```
852
- */
853
- 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;
854
- /** ---------------------------------------------------------------------------
855
- * * ***Options for {@link Mutable | `Mutable`}.***
856
- * ---------------------------------------------------------------------------
857
- * **Configuration options for the ***{@link Mutable | **`Mutable`**}*** type utilities.**
858
- * @example
859
- * ```ts
860
- * type Opt1 = MutableOptions;
861
- * // ➔ { recursive: boolean }
862
- * ```
863
- */
864
- type MutableOptions={
865
- /** * ***Whether to make nested objects mutable recursively.***
866
- *
867
- * - **Behavior:**
868
- * - If `true`, all nested objects will also have their `readonly` removed.
869
- * - Default value: `false`.
870
- *
871
- * @default false
872
- */
873
- recursive:boolean;};
874
- /** -------------------------------------------------------
875
- * * ***Utility Type: `Mutable`.***
876
- * -------------------------------------------------------
877
- * **Removes `readonly` from all properties of the passed type `T`.**
878
- * - If `Options["recursive"]` is `true`, nested objects are also made mutable.
879
- * @template T - The type to make mutable.
880
- * @template Options - Configuration options. Default: `{ recursive: false }`.
881
- * @example
882
- * ```ts
883
- * type Case1 = Mutable<{ readonly a: { readonly b: string } }>;
884
- * // ➔ { a: { b: string } } (non-recursive by default)
885
- * type Case2 = Mutable<{ readonly a: { readonly b: string } }, { recursive: true }>;
886
- * // ➔ { a: { b: string } } (nested properties also mutable)
887
- * ```
888
- */
889
- 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];}>;
890
- /** -------------------------------------------------------
891
- * * ***Utility Type: `MutableOnly`.***
892
- * -------------------------------------------------------
893
- * **Removes `readonly` only from the specified keys `K` of type `T`.**
894
- * @template T - The type to modify.
895
- * @template K - Keys to make mutable.
896
- * @example
897
- * ```ts
898
- * type Case1 = MutableOnly<{ readonly a: string; readonly b: string }, "a">;
899
- * // ➔ { a: string; readonly b: string }
900
- * type Case2 = MutableOnly<{ readonly a: string; readonly b: string }, "a" | "b">;
901
- * // ➔ { a: string; b: string }
902
- * ```
903
- */
904
- type MutableOnly<T,K extends keyof T>=Prettify<Pick<T,Exclude<keyof T,K>>&{-readonly [P in K]:T[P];}>;
905
- /** -------------------------------------------------------
906
- * * ***Utility Type: `MutableExcept`.***
907
- * -------------------------------------------------------
908
- * **Removes `readonly` from all properties of `T` **except** the specified keys `K`.**
909
- * @template T - The type to modify.
910
- * @template K - Keys to keep as readonly.
911
- * @example
912
- * ```ts
913
- * type Case1 = MutableExcept<{ readonly a: string; readonly b: string }, "b">;
914
- * // ➔ { a: string; readonly b: string }
915
- * type Case2 = MutableExcept<{ a: string; readonly b: string }, "a">;
916
- * // ➔ { a: string; b: string } (all except "a" made mutable)
917
- * ```
918
- */
919
- type MutableExcept<T,K extends keyof T>=Prettify<Pick<T,K>&{-readonly [P in Exclude<keyof T,K>]:T[P];}>;
920
- /** -------------------------------------------------------
921
- * * ***Utility Type: `IsArray`.***
922
- * -------------------------------------------------------
923
- * **Returns a boolean whether the passed argument is an array.**
924
- * @example
925
- * type Case1 = IsArray<[]>;
926
- * // ➔ true
927
- * type Case2 = IsArray<string>;
928
- * // ➔ false
929
- */
930
- type IsArray<T>=AndArr<[ Not<IsAny<T>>,Not<IsNever<T>>,Extends<T,readonly unknown[]>]>;
931
- /** -------------------------------------------------------
932
- * * ***Utility Type: `IsMutableArray`.***
933
- * -------------------------------------------------------
934
- * **Returns a boolean whether the passed argument is a mutable array.**
935
- * @example
936
- * type Case1 = IsMutableArray<[]>;
937
- * // ➔ true
938
- * type Case2 = IsMutableArray<readonly []>;
939
- * // ➔ false
940
- */
941
- type IsMutableArray<T>=And<IsArray<T>,NotExtends<Readonly<T>,T>>;
942
- /** -------------------------------------------------------
943
- * * ***Utility Type: `IsReadonlyArray`.***
944
- * -------------------------------------------------------
945
- * **Returns a boolean whether the passed argument is a read-only array.**
946
- * @example
947
- * type Case1 = IsReadonlyArray<readonly []>;
948
- * // ➔ true
949
- * type Case2 = IsReadonlyArray<[]>;
950
- * // ➔ false
951
- */
952
- type IsReadonlyArray<T>=And<IsArray<T>,NotExtends<T,Mutable<T>>>;export type{Abs as A,IsNegativeFloat as B,CharAt as C,IsOdd as D,Even as E,Float as F,IsPositiveFloat as G,IsPositiveInteger as H,IsStringLiteral as I,IsScientificNumber as J,Negative as K,NegativeFloat as L,Mutable as M,Negate as N,NegativeInteger as O,ParseNumber as P,Odd as Q,Repeat as R,Split as S,OddDigit as T,ParseScientificNumber as U,Positive as V,PositiveFloat as W,PositiveInteger as X,IfUnknown as Y,UnknownifyProperties as Z,UnknownifyPropertiesOptions as _,IsNegative as a,IsFloat as b,IsUnknown as c,IsNegativeInteger as d,IsInteger as e,Push as f,IfNegative as g,IsPositive as h,IsEven as i,IsReadonlyArray as j,IfPositive as k,IsArray as l,IsMutableArray as m,MutableExcept as n,MutableOnly as o,MutableOptions as p,EvenDigit as q,IfEven as r,IfFloat as s,IfInteger as t,IfNegativeFloat as u,IfNegativeInteger as v,IfOdd as w,IfPositiveFloat as x,IfPositiveInteger as y,Integer as z};