@rzl-zone/utils-js 3.1.0-beta.2 → 3.1.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.
Files changed (195) hide show
  1. package/README.md +56 -27
  2. package/dist/NumberRangeUnion-DC-C3_Kq.d.ts +23 -23
  3. package/dist/any-BmdI8UbK.d.ts +56 -56
  4. package/dist/arrays-normalize-recursive-CnjYJ9xg.d.ts +66 -66
  5. package/dist/assertions/index.cjs +1 -1
  6. package/dist/assertions/index.d.ts +396 -396
  7. package/dist/assertions/index.js +1 -1
  8. package/dist/chunk-26XIKDJI.cjs +1 -0
  9. package/dist/chunk-2NWHDDM5.js +1 -0
  10. package/dist/chunk-2UIRWYE3.js +1 -0
  11. package/dist/chunk-3KBHD3BS.cjs +1 -0
  12. package/dist/chunk-4HD2O5A4.js +1 -0
  13. package/dist/chunk-5C2SMIGX.cjs +1 -0
  14. package/dist/chunk-5I2B5DOG.js +1 -0
  15. package/dist/chunk-6HQDHIOD.js +1 -0
  16. package/dist/chunk-735HJXBT.cjs +1 -0
  17. package/dist/chunk-7BXIZM57.cjs +1 -0
  18. package/dist/chunk-7KJBDGEP.js +1 -0
  19. package/dist/chunk-7U44T63D.cjs +1 -0
  20. package/dist/chunk-AJ65QFV2.js +1 -0
  21. package/dist/chunk-APHDUCVQ.js +1 -0
  22. package/dist/chunk-BSVZRN7C.js +1 -0
  23. package/dist/chunk-C6JFHUR2.cjs +1 -0
  24. package/dist/chunk-CPLBRGST.js +1 -0
  25. package/dist/chunk-CTBRLEOG.js +1 -0
  26. package/dist/chunk-DUK2K4FB.js +1 -0
  27. package/dist/chunk-DVMHRLKP.cjs +1 -0
  28. package/dist/chunk-E63WVPZE.cjs +1 -0
  29. package/dist/chunk-EBMHQW7X.cjs +1 -0
  30. package/dist/chunk-EGNZCW4K.js +1 -0
  31. package/dist/chunk-FEKDB32T.js +1 -0
  32. package/dist/chunk-FIAAX3UE.js +1 -0
  33. package/dist/chunk-FUS3DVLB.cjs +1 -0
  34. package/dist/chunk-GGRMHIFJ.cjs +1 -0
  35. package/dist/chunk-HQ5GQTEE.js +1 -0
  36. package/dist/chunk-I5X5IN4H.js +1 -0
  37. package/dist/chunk-I7YGXQPI.cjs +1 -0
  38. package/dist/chunk-INUFZJLX.cjs +1 -0
  39. package/dist/chunk-IREHUBF7.js +1 -0
  40. package/dist/chunk-J2RGTPGK.cjs +1 -0
  41. package/dist/chunk-KHO2SBNA.cjs +1 -0
  42. package/dist/chunk-KXIXXSWX.cjs +1 -0
  43. package/dist/chunk-LBMEEJWA.js +1 -0
  44. package/dist/chunk-MC3LXMCQ.js +1 -0
  45. package/dist/chunk-MMSYCIJ2.cjs +1 -1
  46. package/dist/chunk-NU3N4WHD.cjs +1 -0
  47. package/dist/chunk-ODZQXH7E.cjs +1 -0
  48. package/dist/chunk-ONZFBJVW.js +1 -0
  49. package/dist/chunk-PXDRHFIE.js +1 -0
  50. package/dist/chunk-Q6NHYWVX.js +1 -0
  51. package/dist/chunk-QNKGP5DY.js +1 -0
  52. package/dist/chunk-S6Z6I2EG.cjs +1 -0
  53. package/dist/chunk-SMADKXZE.js +1 -0
  54. package/dist/chunk-TSLYDPBJ.js +1 -0
  55. package/dist/chunk-TVXADXCC.cjs +1 -0
  56. package/dist/chunk-UDA26MCU.cjs +1 -0
  57. package/dist/chunk-UET567YM.cjs +1 -0
  58. package/dist/chunk-VEYMQ3UA.js +1 -0
  59. package/dist/chunk-W2W3L2M5.js +1 -0
  60. package/dist/chunk-WBWTXKMC.cjs +1 -0
  61. package/dist/chunk-WVSPXFTY.js +1 -0
  62. package/dist/chunk-XC2PYCT4.cjs +1 -0
  63. package/dist/chunk-XIXA5KDF.cjs +1 -0
  64. package/dist/chunk-Y4O5KZF6.cjs +1 -0
  65. package/dist/chunk-YRM7IJLX.js +1 -0
  66. package/dist/chunk-YT3MSZKK.cjs +1 -0
  67. package/dist/chunk-YXHCULSO.cjs +1 -0
  68. package/dist/chunk-YZR5OGJA.cjs +1 -0
  69. package/dist/chunk-Z4DXK7A6.cjs +1 -0
  70. package/dist/chunk-ZXIWDFEQ.js +1 -0
  71. package/dist/conversions/index.cjs +1 -1
  72. package/dist/conversions/index.d.ts +1347 -1297
  73. package/dist/conversions/index.js +1 -1
  74. package/dist/env/index.cjs +1 -1
  75. package/dist/env/index.d.ts +14 -14
  76. package/dist/env/index.js +1 -1
  77. package/dist/events/index.cjs +1 -1
  78. package/dist/events/index.d.ts +109 -109
  79. package/dist/events/index.js +1 -1
  80. package/dist/extends-Bk_SBGdT.d.ts +330 -330
  81. package/dist/formatting/index.cjs +1 -1
  82. package/dist/formatting/index.d.ts +855 -855
  83. package/dist/formatting/index.js +1 -1
  84. package/dist/generator/index.cjs +1 -1
  85. package/dist/generator/index.d.ts +155 -155
  86. package/dist/generator/index.js +1 -1
  87. package/dist/if-CvT4R7Kh.d.ts +16 -16
  88. package/dist/is-array-Cymwrsmm.d.ts +1119 -0
  89. package/dist/isPlainObject-BVhBAPHX.d.ts +154 -154
  90. package/dist/never-BfayMBF9.d.ts +64 -64
  91. package/dist/next/index.cjs +1 -8
  92. package/dist/next/index.d.ts +183 -183
  93. package/dist/next/index.js +1 -8
  94. package/dist/next/server/index.cjs +1 -2
  95. package/dist/next/server/index.d.ts +25 -25
  96. package/dist/next/server/index.js +1 -2
  97. package/dist/nils-DMz3kU7M.d.ts +155 -155
  98. package/dist/omit-VvmIsZmX.d.ts +25 -25
  99. package/dist/operations/index.cjs +1 -1
  100. package/dist/operations/index.d.ts +120 -120
  101. package/dist/operations/index.js +1 -1
  102. package/dist/or-DyZCRvaU.d.ts +89 -0
  103. package/dist/parsers/index.cjs +1 -1
  104. package/dist/parsers/index.d.ts +34 -34
  105. package/dist/parsers/index.js +1 -1
  106. package/dist/predicates/index.cjs +1 -1
  107. package/dist/predicates/index.d.ts +1774 -1680
  108. package/dist/predicates/index.js +1 -1
  109. package/dist/prettify-C4xLcYOP.d.ts +328 -328
  110. package/dist/promise/index.cjs +1 -1
  111. package/dist/promise/index.d.ts +29 -29
  112. package/dist/promise/index.js +1 -1
  113. package/dist/rzl-utils.global.js +1 -4
  114. package/dist/string-XA-til3C.d.ts +318 -318
  115. package/dist/strings/index.cjs +1 -1
  116. package/dist/strings/index.d.ts +690 -690
  117. package/dist/strings/index.js +1 -1
  118. package/dist/tailwind/index.cjs +1 -0
  119. package/dist/tailwind/index.d.ts +565 -0
  120. package/dist/tailwind/index.js +1 -0
  121. package/dist/type-data-DDs-u2kq.d.ts +241 -241
  122. package/dist/types/index.d.ts +3266 -3266
  123. package/dist/urls/index.cjs +1 -1
  124. package/dist/urls/index.d.ts +373 -373
  125. package/dist/urls/index.js +1 -1
  126. package/package.json +24 -23
  127. package/dist/chunk-25G6B35W.js +0 -1
  128. package/dist/chunk-2AUUPGMN.js +0 -1
  129. package/dist/chunk-2JQQQ625.js +0 -1
  130. package/dist/chunk-445TAVT4.cjs +0 -1
  131. package/dist/chunk-467VEMJH.js +0 -1
  132. package/dist/chunk-56QBKKRE.js +0 -1
  133. package/dist/chunk-5SZUSNGZ.js +0 -1
  134. package/dist/chunk-6Q4I2RPC.cjs +0 -1
  135. package/dist/chunk-6SMJMZ7G.cjs +0 -1
  136. package/dist/chunk-7YWAQOA4.cjs +0 -1
  137. package/dist/chunk-BLCANGFS.js +0 -1
  138. package/dist/chunk-CK3BZGEU.js +0 -1
  139. package/dist/chunk-D43GV6EF.cjs +0 -1
  140. package/dist/chunk-DFSTVQFI.cjs +0 -1
  141. package/dist/chunk-DYRDBYPF.cjs +0 -1
  142. package/dist/chunk-ELDDNERR.js +0 -1
  143. package/dist/chunk-EXXLUO7L.cjs +0 -1
  144. package/dist/chunk-FIEZKTAZ.cjs +0 -1
  145. package/dist/chunk-G72VSVGO.js +0 -1
  146. package/dist/chunk-GAJTFCUA.js +0 -1
  147. package/dist/chunk-GOJNH55O.cjs +0 -1
  148. package/dist/chunk-HXST7RJB.js +0 -1
  149. package/dist/chunk-HXTACM3O.cjs +0 -1
  150. package/dist/chunk-IJTZWWRJ.cjs +0 -1
  151. package/dist/chunk-ISJ33O2J.cjs +0 -1
  152. package/dist/chunk-JISH2VGG.js +0 -1
  153. package/dist/chunk-JQZUWBIX.js +0 -1
  154. package/dist/chunk-K4PLGD7C.js +0 -1
  155. package/dist/chunk-KZQB7H4E.cjs +0 -1
  156. package/dist/chunk-LUVV5KSD.cjs +0 -2
  157. package/dist/chunk-LVUSFXQS.cjs +0 -1
  158. package/dist/chunk-ME5OV5HN.js +0 -1
  159. package/dist/chunk-MF5Y5K4N.cjs +0 -1
  160. package/dist/chunk-MJAW5RAK.js +0 -1
  161. package/dist/chunk-MWLEM7ED.js +0 -1
  162. package/dist/chunk-NNM7QCNB.js +0 -1
  163. package/dist/chunk-NSVLG7NY.js +0 -4
  164. package/dist/chunk-NUHOOAUN.cjs +0 -1
  165. package/dist/chunk-NUVGETPD.js +0 -2
  166. package/dist/chunk-O5VXBNUQ.cjs +0 -4
  167. package/dist/chunk-O7SJR4CY.cjs +0 -1
  168. package/dist/chunk-OX6RLS2F.cjs +0 -1
  169. package/dist/chunk-PFLNHD4B.cjs +0 -1
  170. package/dist/chunk-PSWITZK5.js +0 -1
  171. package/dist/chunk-PUQXRLZH.cjs +0 -1
  172. package/dist/chunk-PYUVKHUF.cjs +0 -1
  173. package/dist/chunk-REFMEB4A.js +0 -1
  174. package/dist/chunk-RHE3M2NJ.cjs +0 -1
  175. package/dist/chunk-RHIBYOFQ.js +0 -1
  176. package/dist/chunk-RV2VULM7.cjs +0 -1
  177. package/dist/chunk-S7GMG4TB.js +0 -1
  178. package/dist/chunk-SW6HYEW7.cjs +0 -1
  179. package/dist/chunk-SYJC7UAW.js +0 -1
  180. package/dist/chunk-TQMZ2LPI.js +0 -1
  181. package/dist/chunk-U4TZO7WV.js +0 -1
  182. package/dist/chunk-UUMKL74S.js +0 -1
  183. package/dist/chunk-VQLAPEL3.js +0 -1
  184. package/dist/chunk-VTR75UID.cjs +0 -1
  185. package/dist/chunk-XFCJDSB2.cjs +0 -1
  186. package/dist/chunk-XOYX4PLZ.cjs +0 -1
  187. package/dist/chunk-Z6FLCEN6.js +0 -1
  188. package/dist/chunk-ZO5364A6.cjs +0 -1
  189. package/dist/index.cjs +0 -1
  190. package/dist/index.d.ts +0 -1
  191. package/dist/index.js +0 -1
  192. package/dist/is-array--YjXV-Wx.d.ts +0 -1207
  193. package/dist/stylings/index.cjs +0 -1
  194. package/dist/stylings/index.d.ts +0 -41
  195. package/dist/stylings/index.js +0 -1
@@ -1,1207 +0,0 @@
1
- import{I as IfExtends,E as Extends,N as Not,a as NotExtends}from'./extends-Bk_SBGdT.js';import{I as If}from'./if-CvT4R7Kh.js';import{T as Trim,I as IfNot}from'./string-XA-til3C.js';import{I as IsNever}from'./never-BfayMBF9.js';import{I as IsAny}from'./any-BmdI8UbK.js';import{P as Prettify}from'./prettify-C4xLcYOP.js';
2
- /** -------------------------------------------------------
3
- * * ***And.***
4
- * -------------------------------------------------------
5
- * Performs a **logical AND** operation between two boolean types.
6
- * - Returns `true` if **both** conditions extend `true`.
7
- * - Returns `false` otherwise.
8
- *
9
- * @template Condition1 - The first condition.
10
- * @template Condition2 - The second condition.
11
- * @example
12
- * ```ts
13
- * type Case1 = And<true, true>;
14
- * // ➔ true
15
- * type Case2 = And<false, true>;
16
- * // ➔ false
17
- * type Case3 = And<true, false>;
18
- * // ➔ false
19
- * type Case4 = And<false, false>;
20
- * // ➔ false
21
- * ```
22
- */
23
- type And<Condition1,Condition2>=IfExtends<Condition1,true,Extends<Condition2,true>>;
24
- /** -------------------------------------------------------
25
- * * ***AndArr.***
26
- * -------------------------------------------------------
27
- * Performs a **logical AND** operation across all elements in an array of boolean types.
28
- * - Returns `true` if **all elements** extend `true`.
29
- * - Returns `false` if **any element** is not `true`.
30
- *
31
- * @template Conditions - A readonly array of boolean conditions.
32
- * @example
33
- * ```ts
34
- * type Case1 = AndArr<[true, true, true]>;
35
- * // ➔ true
36
- * type Case2 = AndArr<[true, true, false]>;
37
- * // ➔ false
38
- * type Case3 = AndArr<[false, false, false]>;
39
- * // ➔ false
40
- * type Case4 = AndArr<[]>;
41
- * // ➔ true (vacuous truth)
42
- * ```
43
- */
44
- type AndArr<Conditions extends readonly unknown[]>=Extends<Conditions[number],true>;
45
- /** -------------------------------------------------------
46
- * * ***IsStringLiteral.***
47
- * -------------------------------------------------------
48
- * Returns a boolean whether the passed argument is literal string
49
- *
50
- * @template T - The type value to check.
51
- * @example
52
- * type Case1 = IsStringLiteral<'a'>; // ➔ true
53
- * type Case2 = IsStringLiteral<1>; // ➔ false
54
- * type Case3 = IsStringLiteral<string>; // ➔ false
55
- */
56
- type IsStringLiteral<T>=If<Extends<T,string>,Extends<string,T>extends true?false:true,false>;
57
- /** -------------------------------------------------------
58
- * * ***Or.***
59
- * -------------------------------------------------------
60
- *
61
- * Computes the logical OR of two type-level boolean conditions.
62
- *
63
- * @template Condition1 - First boolean condition.
64
- * @template Condition2 - Second boolean condition.
65
- *
66
- * @example
67
- * ```ts
68
- * type Case1 = Or<true, true>; // true
69
- * type Case2 = Or<false, true>; // true
70
- * type Case3 = Or<false, false>; // false
71
- * type Case4 = Or<true, false>; // true
72
- * ```
73
- *
74
- * @remarks
75
- * - Uses {@link IfExtends} to determine if either condition is `true`.
76
- * - Returns `true` if at least one of the two conditions is `true`.
77
- * - Returns `false` only if both are `false`.
78
- */
79
- type Or<Condition1,Condition2>=IfExtends<Condition1,true,true,IfExtends<Condition2,true>>;
80
- /** -------------------------------------------------------
81
- * * ***OrArr.***
82
- * -------------------------------------------------------
83
- *
84
- * Computes the logical OR of all elements inside a tuple or array of boolean types.
85
- *
86
- * @template Conditions - An array of boolean type elements.
87
- *
88
- * @example
89
- * ```ts
90
- * type Case1 = OrArr<[true, true, true]>; // true
91
- * type Case2 = OrArr<[true, true, false]>; // true
92
- * type Case3 = OrArr<[false, false, false]>; // false
93
- * type Case4 = OrArr<[]>; // false
94
- * ```
95
- *
96
- * @remarks
97
- * - Uses TypeScript's indexed access types and conditional type inference.
98
- * - Returns `true` if at least one element in the array is `true`.
99
- * - Returns `false` if all elements are `false` or array is empty.
100
- */
101
- type OrArr<Conditions extends readonly unknown[]>=true extends Conditions[number]?true:false;
102
- /** -------------------------------------------------------
103
- * * ***Push.***
104
- * -------------------------------------------------------
105
- *
106
- * Appends a type `U` to the end of a tuple or readonly array type `T`.
107
- *
108
- * @template T - The tuple or readonly array type to append to.
109
- * @template U - The type of the element to push.
110
- *
111
- * @example
112
- * ```ts
113
- * type Case1 = Push<[1, 2, 3, 4], 5>;
114
- * // ➔ [1, 2, 3, 4, 5]
115
- *
116
- * type Case2 = Push<["a", "b"], "c">;
117
- * // ➔ ["a", "b", "c"]
118
- * ```
119
- */
120
- 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>>;
121
- /** -------------------------------------------------------
122
- * * ***Repeat.***
123
- * -------------------------------------------------------
124
- *
125
- * Repeats a string literal type `T` a specified number of times `Count`.
126
- * - Supports a range of `[0, 999]` due to TypeScript recursion limits.
127
- * - If `Count > 999`, it is automatically error `Type instantiation is excessively deep and possibly infinite.ts(2589)`.
128
- *
129
- * @template T - The string literal to repeat.
130
- * @template Count - Number of times to repeat.
131
- *
132
- * @example
133
- * ```ts
134
- * type Case0 = Repeat<'x', 0>; // ➔ ''
135
- * type Case1 = Repeat<'x', 1>; // ➔ 'x'
136
- * type Case2 = Repeat<'x', 5>; // ➔ 'xxxxx'
137
- * type Case3 = Repeat<'ab', 3>; // ➔ 'ababab'
138
- *
139
- * // ❌ Invalid:
140
- * type Case1000 = Repeat<'x', 1000>;
141
- * // ➔ same as any (because: TypeScript recursion limits)
142
- * ```
143
- */
144
- type Repeat<T extends string,Count extends number>=_Repeat<T,Count>;
145
- /** -------------------------------------------------------
146
- * * ***OddDigit.***
147
- * -------------------------------------------------------
148
- *
149
- * A union of string literal digits considered ***odd***.
150
- *
151
- * - Includes: `"1" | "3" | "5" | "7" | "9"`.
152
- *
153
- * @example
154
- *
155
- * ```ts
156
- * type A = OddDigit; // ➔ "1" | "3" | "5" | "7" | "9"
157
- * ```
158
- */
159
- type OddDigit="1"|"3"|"5"|"7"|"9";
160
- /** -------------------------------------------------------
161
- * * ***EvenDigit.***
162
- * -------------------------------------------------------
163
- *
164
- * A union of string literal digits considered ***even***.
165
- *
166
- * - Includes: `"0" | "2" | "4" | "6" | "8"`.
167
- *
168
- * @example
169
- *
170
- * ```ts
171
- * type A = EvenDigit; // ➔ "0" | "2" | "4" | "6" | "8"
172
- * ```
173
- */
174
- type EvenDigit="0"|"2"|"4"|"6"|"8";
175
- /** -------------------------------------------------------
176
- * * ***Integer.***
177
- * -------------------------------------------------------
178
- *
179
- * A type-level utility that validates if `T` is an ***integer***.
180
- *
181
- * - Returns `T` if it is an integer.
182
- * - Returns `never` if `T` is a ***float*** (decimal).
183
- *
184
- * @template T - A number type to validate.
185
- *
186
- * @example
187
- *
188
- * ```ts
189
- * type A = Integer<42>; // ➔ 42
190
- * type B = Integer<-10>; // ➔ -10
191
- * type C = Integer<3.14>; // ➔ never
192
- * ```
193
- */
194
- type Integer<T extends number>=`${T}`extends`${string}.${string}`?never:T;
195
- /** -------------------------------------------------------
196
- * * ***Float.***
197
- * -------------------------------------------------------
198
- *
199
- * A type-level utility that validates if `T` is a ***float***.
200
- *
201
- * - Returns `T` if it is a float.
202
- * - Returns `never` if `T` is an ***integer***.
203
- *
204
- * @template T - A number type to validate.
205
- *
206
- * @example
207
- *
208
- * ```ts
209
- * type A = Float<3.14>; // ➔ 3.14
210
- * type B = Float<42>; // ➔ never
211
- * ```
212
- */
213
- type Float<T extends number>=If<IsNever<Integer<T>>,T,never>;
214
- /** -------------------------------------------------------
215
- * * ***Negative.***
216
- * -------------------------------------------------------
217
- *
218
- * Extracts `T` if it is ***negative***, otherwise `never`.
219
- *
220
- * @template T - A number type to check.
221
- *
222
- * @example
223
- *
224
- * ```ts
225
- * type A = Negative<-10>; // ➔ -10
226
- * type B = Negative<5>; // ➔ never
227
- * type C = Negative<0>; // ➔ never
228
- * ```
229
- */
230
- type Negative<T extends number>=`${T}`extends`-${string}`?T:never;
231
- /** -------------------------------------------------------
232
- * * ***Positive.***
233
- * -------------------------------------------------------
234
- *
235
- * Extracts `T` if it is ***positive*** (or zero), otherwise `never`.
236
- *
237
- * @template T - A number type to check.
238
- *
239
- * @example
240
- *
241
- * ```ts
242
- * type A = Positive<10>; // ➔ 10
243
- * type B = Positive<0>; // ➔ 0
244
- * type C = Positive<-5>; // ➔ never
245
- * ```
246
- */
247
- type Positive<T extends number>=If<IsNever<Negative<T>>,T,never>;
248
- /** -------------------------------------------------------
249
- * * ***PositiveInteger.***
250
- * -------------------------------------------------------
251
- *
252
- * Restricts `T` to ***positive integers*** only.
253
- *
254
- * @template T - A number type.
255
- *
256
- * @example
257
- *
258
- * ```ts
259
- * type A = PositiveInteger<42>; // ➔ 42
260
- * type B = PositiveInteger<0>; // ➔ 0
261
- * type C = PositiveInteger<-5>; // ➔ never
262
- * type D = PositiveInteger<3.14>; // ➔ never
263
- * ```
264
- */
265
- type PositiveInteger<T extends number>=Positive<Integer<T>>;
266
- /** -------------------------------------------------------
267
- * * ***NegativeInteger.***
268
- * -------------------------------------------------------
269
- *
270
- * Restricts `T` to ***negative integers*** only.
271
- *
272
- * @template T - A number type.
273
- *
274
- * @example
275
- *
276
- * ```ts
277
- * type A = NegativeInteger<-42>; // ➔ -42
278
- * type B = NegativeInteger<5>; // ➔ never
279
- * type C = NegativeInteger<-3.14>; // ➔ never
280
- * ```
281
- */
282
- type NegativeInteger<T extends number>=Negative<Integer<T>>;
283
- /** -------------------------------------------------------
284
- * * ***PositiveFloat.***
285
- * -------------------------------------------------------
286
- *
287
- * Restricts `T` to ***positive floats*** only.
288
- *
289
- * @template T - A number type.
290
- *
291
- * @example
292
- *
293
- * ```ts
294
- * type A = PositiveFloat<3.14>; // ➔ 3.14
295
- * type B = PositiveFloat<-2.5>; // ➔ never
296
- * type C = PositiveFloat<5>; // ➔ never
297
- * ```
298
- */
299
- type PositiveFloat<T extends number>=Positive<Float<T>>;
300
- /** -------------------------------------------------------
301
- * * ***NegativeFloat.***
302
- * -------------------------------------------------------
303
- *
304
- * Restricts `T` to ***negative floats*** only.
305
- *
306
- * @template T - A number type.
307
- *
308
- * @example
309
- *
310
- * ```ts
311
- * type A = NegativeFloat<-3.14>; // ➔ -3.14
312
- * type B = NegativeFloat<2.5>; // ➔ never
313
- * type C = NegativeFloat<-5>; // ➔ never
314
- * ```
315
- */
316
- type NegativeFloat<T extends number>=Negative<Float<T>>;
317
- /** -------------------------------------------------------
318
- * * ***Even.***
319
- * -------------------------------------------------------
320
- *
321
- * A type-level utility that extracts `T` if it is an ***even integer***.
322
- *
323
- * @template T - A number type to check.
324
- *
325
- * @example
326
- *
327
- * ```ts
328
- * type A = Even<0>; // ➔ 0
329
- * type B = Even<4>; // ➔ 4
330
- * type C = Even<5>; // ➔ never
331
- * type D = Even<24>; // ➔ 24
332
- * type E = Even<27>; // ➔ never
333
- * type F = Even<3.14>; // ➔ never
334
- * ```
335
- */
336
- type Even<T extends number>=IfNot<IsNever<Integer<T>>,`${T}`extends`${string}${EvenDigit}`?T:never,never>;
337
- /** -------------------------------------------------------
338
- * * ***Odd.***
339
- * -------------------------------------------------------
340
- *
341
- * A type-level utility that extracts `T` if it is an ***odd integer***.
342
- *
343
- * @template T - A number type to check.
344
- *
345
- * @example
346
- *
347
- * ```ts
348
- * type A = Odd<0>; // ➔ never
349
- * type B = Odd<5>; // ➔ 5
350
- * type C = Odd<4>; // ➔ never
351
- * type D = Odd<23>; // ➔ 23
352
- * type E = Odd<26>; // ➔ never
353
- * type F = Odd<4.2>; // ➔ never
354
- * ```
355
- */
356
- type Odd<T extends number>=IfNot<IsNever<Integer<T>>,If<IsNever<Even<T>>,T,never>,never>;
357
- /** -------------------------------------------------------
358
- * * ***IsInteger.***
359
- * -------------------------------------------------------
360
- *
361
- * Whether `T` is an ***integer***.
362
- *
363
- * @example
364
- *
365
- * ```ts
366
- * type A = IsInteger<-2>; // ➔ true
367
- * type B = IsInteger<0>; // ➔ true
368
- * type C = IsInteger<42>; // ➔ true
369
- * type D = IsInteger<3.14>; // ➔ false
370
- * ```
371
- */
372
- type IsInteger<T extends number>=Not<IsNever<Integer<T>>>;
373
- /** -------------------------------------------------------
374
- * * ***IsFloat.***
375
- * -------------------------------------------------------
376
- *
377
- * Whether `T` is a ***float***.
378
- *
379
- * @example
380
- *
381
- * ```ts
382
- * type A = IsFloat<3.14>; // ➔ true
383
- * type B = IsFloat<-3.14>; // ➔ true
384
- * type C = IsFloat<0>; // ➔ false
385
- * type D = IsFloat<42>; // ➔ false
386
- * type E = IsFloat<-42>; // ➔ false
387
- * ```
388
- */
389
- type IsFloat<T extends number>=Not<IsNever<Float<T>>>;
390
- /** -------------------------------------------------------
391
- * * ***IsEven.***
392
- * -------------------------------------------------------
393
- *
394
- * Whether `T` is ***even***.
395
- *
396
- * @example
397
- *
398
- * ```ts
399
- * type A = IsEven<0>; // ➔ true
400
- * type B = IsEven<4>; // ➔ true
401
- * type C = IsEven<5>; // ➔ false
402
- * type D = IsEven<24>; // ➔ true
403
- * type E = IsEven<27>; // ➔ false
404
- * type F = IsEven<3.14>; // ➔ false
405
- * ```
406
- */
407
- type IsEven<T extends number>=If<IsInteger<T>,`${T}`extends`${string}${EvenDigit}`?true:false>;
408
- /** -------------------------------------------------------
409
- * * ***IsOdd.***
410
- * -------------------------------------------------------
411
- *
412
- * Whether `T` is ***odd***.
413
- *
414
- * @example
415
- *
416
- * ```ts
417
- * type A = IsEven<0>; // ➔ false
418
- * type B = IsEven<4>; // ➔ false
419
- * type C = IsEven<5>; // ➔ true
420
- * type D = IsEven<24>; // ➔ false
421
- * type E = IsEven<27>; // ➔ true
422
- * type F = IsEven<3.14>; // ➔ true
423
- * ```
424
- */
425
- type IsOdd<T extends number>=If<IsInteger<T>,Not<IsEven<T>>>;
426
- /** -------------------------------------------------------
427
- * * ***IsPositive.***
428
- * -------------------------------------------------------
429
- *
430
- * Whether `T` is ***positive***.
431
- *
432
- * @example
433
- *
434
- * ```ts
435
- * type A = IsPositive<10>; // ➔ true
436
- * type B = IsPositive<0>; // ➔ true
437
- * type C = IsPositive<-5>; // ➔ false
438
- * type D = IsPositive<3.5>; // ➔ true
439
- * type E = IsPositive<-3.5>; // ➔ false
440
- * ```
441
- */
442
- type IsPositive<T extends number>=Not<IsNever<Positive<T>>>;
443
- /** -------------------------------------------------------
444
- * * ***IsNegative.***
445
- * -------------------------------------------------------
446
- *
447
- * Whether `T` is ***negative***.
448
- *
449
- * @example
450
- *
451
- * ```ts
452
- * type A = IsNegative<-10>; // ➔ true
453
- * type B = IsNegative<5>; // ➔ false
454
- * type C = IsNegative<0>; // ➔ false
455
- * type D = IsPositive<3.5>; // ➔ false
456
- * type E = IsPositive<-3.5>; // ➔ true
457
- * ```
458
- */
459
- type IsNegative<T extends number>=Not<IsNever<Negative<T>>>;
460
- /** -------------------------------------------------------
461
- * * ***IsPositiveInteger.***
462
- * -------------------------------------------------------
463
- *
464
- * Whether `T` is a ***positive integer***.
465
- *
466
- * @example
467
- *
468
- * ```ts
469
- * type A = IsPositiveInteger<42>; // ➔ true
470
- * type B = IsPositiveInteger<0>; // ➔ true
471
- * type C = IsPositiveInteger<-5>; // ➔ false
472
- * type D = IsPositiveInteger<3.14>; // ➔ false
473
- * ```
474
- */
475
- type IsPositiveInteger<T extends number>=Not<IsNever<PositiveInteger<T>>>;
476
- /** -------------------------------------------------------
477
- * * ***IsNegativeInteger.***
478
- * -------------------------------------------------------
479
- *
480
- * Whether `T` is a ***negative integer***.
481
- *
482
- * @example
483
- *
484
- * ```ts
485
- * type A = IsNegativeInteger<-42>; // ➔ true
486
- * type B = IsNegativeInteger<5>; // ➔ false
487
- * type C = IsNegativeInteger<-3.14>; // ➔ false
488
- * ```
489
- */
490
- type IsNegativeInteger<T extends number>=Not<IsNever<NegativeInteger<T>>>;
491
- /** -------------------------------------------------------
492
- * * ***IsPositiveFloat.***
493
- * -------------------------------------------------------
494
- *
495
- * Whether `T` is a ***positive float***.
496
- *
497
- * @example
498
- *
499
- * ```ts
500
- * type A = IsPositiveFloat<3.14>; // ➔ true
501
- * type B = IsPositiveFloat<-2.5>; // ➔ false
502
- * type C = IsPositiveFloat<5>; // ➔ false
503
- * ```
504
- */
505
- type IsPositiveFloat<T extends number>=Not<IsNever<PositiveFloat<T>>>;
506
- /** -------------------------------------------------------
507
- * * ***IsNegativeFloat.***
508
- * -------------------------------------------------------
509
- *
510
- * Whether `T` is a ***negative float***.
511
- *
512
- * @example
513
- *
514
- * ```ts
515
- * type A = IsNegativeFloat<-3.14>; // ➔ true
516
- * type B = IsNegativeFloat<2.5>; // ➔ false
517
- * type C = IsNegativeFloat<-5>; // ➔ false
518
- * ```
519
- */
520
- type IsNegativeFloat<T extends number>=Not<IsNever<NegativeFloat<T>>>;
521
- /** -------------------------------------------------------
522
- * * ***IfInteger.***
523
- * -------------------------------------------------------
524
- *
525
- * Conditional: `If` branch if `T` is an ***integer***.
526
- *
527
- * @example
528
- *
529
- * ```ts
530
- * type A = IfInteger<42>; // ➔ true
531
- * type B = IfInteger<3.14>; // ➔ false
532
- * type C = IfInteger<42, "yes", "no">; // ➔ "yes"
533
- * type D = IfInteger<3.14, "yes", "no">; // ➔ "no"
534
- * ```
535
- */
536
- type IfInteger<T extends number,IfTrue=true,IfFalse=false>=If<IsInteger<T>,IfTrue,IfFalse>;
537
- /** -------------------------------------------------------
538
- * * ***IfFloat.***
539
- * -------------------------------------------------------
540
- *
541
- * Conditional: selects one of two branches depending on whether `T` is a ***float***.
542
- *
543
- * - Defaults: `IfTrue = true`, `IfFalse = false`.
544
- *
545
- * @template T - A number type.
546
- * @template IfTrue - The branch type if condition is met. (default: `true`)
547
- * @template IfFalse - The branch type if condition is not met. (default: `false`)
548
- *
549
- * @example
550
- *
551
- * ```ts
552
- * type A = IfFloat<3.14>; // ➔ true
553
- * type B = IfFloat<42>; // ➔ false
554
- * type C = IfFloat<3.14, "yes", "no">; // ➔ "yes"
555
- * type D = IfFloat<42, "yes", "no">; // ➔ "no"
556
- * ```
557
- */
558
- type IfFloat<T extends number,IfTrue=true,IfFalse=false>=If<IsFloat<T>,IfTrue,IfFalse>;
559
- /** -------------------------------------------------------
560
- * * ***IfEven.***
561
- * -------------------------------------------------------
562
- *
563
- * Conditional: selects one of two branches depending on whether `T` is ***even***.
564
- *
565
- * - Defaults: `IfTrue = true`, `IfFalse = false`.
566
- *
567
- * @template T - A number type.
568
- * @template IfTrue - The branch type if condition is met. (default: `true`)
569
- * @template IfFalse - The branch type if condition is not met. (default: `false`)
570
- *
571
- * @example
572
- *
573
- * ```ts
574
- * type A = IfEven<4>; // ➔ true
575
- * type B = IfEven<5>; // ➔ false
576
- * type C = IfEven<4, "even", "odd">; // ➔ "even"
577
- * type D = IfEven<5, "even", "odd">; // ➔ "odd"
578
- * ```
579
- */
580
- type IfEven<T extends number,IfTrue=true,IfFalse=false>=If<IsEven<T>,IfTrue,IfFalse>;
581
- /** -------------------------------------------------------
582
- * * ***IfOdd.***
583
- * -------------------------------------------------------
584
- *
585
- * Conditional: selects one of two branches depending on whether `T` is ***odd***.
586
- *
587
- * - Defaults: `IfTrue = true`, `IfFalse = false`.
588
- *
589
- * @template T - A number type.
590
- * @template IfTrue - The branch type if condition is met. (default: `true`)
591
- * @template IfFalse - The branch type if condition is not met. (default: `false`)
592
- *
593
- * @example
594
- *
595
- * ```ts
596
- * type A = IfOdd<5>; // ➔ true
597
- * type B = IfOdd<4>; // ➔ false
598
- * type C = IfOdd<5, "odd", "even">; // ➔ "odd"
599
- * type D = IfOdd<4, "odd", "even">; // ➔ "even"
600
- * ```
601
- */
602
- type IfOdd<T extends number,IfTrue=true,IfFalse=false>=If<IsOdd<T>,IfTrue,IfFalse>;
603
- /** -------------------------------------------------------
604
- * * ***IfPositive.***
605
- * -------------------------------------------------------
606
- *
607
- * Conditional: selects one of two branches depending on whether `T` is ***positive***.
608
- *
609
- * - Defaults: `IfTrue = true`, `IfFalse = false`.
610
- *
611
- * @template T - A number type.
612
- * @template IfTrue - The branch type if condition is met. (default: `true`)
613
- * @template IfFalse - The branch type if condition is not met. (default: `false`)
614
- *
615
- * @example
616
- *
617
- * ```ts
618
- * type A = IfPositive<10>; // ➔ true
619
- * type B = IfPositive<-5>; // ➔ false
620
- * type C = IfPositive<10, "yes", "no">; // ➔ "yes"
621
- * type D = IfPositive<-5, "yes", "no">; // ➔ "no"
622
- * ```
623
- */
624
- type IfPositive<T extends number,IfTrue=true,IfFalse=false>=If<IsPositive<T>,IfTrue,IfFalse>;
625
- /** -------------------------------------------------------
626
- * * ***IfNegative.***
627
- * -------------------------------------------------------
628
- *
629
- * Conditional: selects one of two branches depending on whether `T` is ***negative***.
630
- *
631
- * - Defaults: `IfTrue = true`, `IfFalse = false`.
632
- *
633
- * @template T - A number type.
634
- * @template IfTrue - The branch type if condition is met. (default: `true`)
635
- * @template IfFalse - The branch type if condition is not met. (default: `false`)
636
- *
637
- * @example
638
- *
639
- * ```ts
640
- * type A = IfNegative<-10>; // ➔ true
641
- * type B = IfNegative<5>; // ➔ false
642
- * type C = IfNegative<-10, "yes", "no">; // ➔ "yes"
643
- * type D = IfNegative<5, "yes", "no">; // ➔ "no"
644
- * ```
645
- */
646
- type IfNegative<T extends number,IfTrue=true,IfFalse=false>=If<IsNegative<T>,IfTrue,IfFalse>;
647
- /** -------------------------------------------------------
648
- * * ***IfPositiveInteger.***
649
- * -------------------------------------------------------
650
- *
651
- * Conditional: selects one of two branches depending on whether `T` is a ***positive integer***.
652
- *
653
- * - Defaults: `IfTrue = true`, `IfFalse = false`.
654
- *
655
- * @template T - A number type.
656
- * @template IfTrue - The branch type if condition is met. (default: `true`)
657
- * @template IfFalse - The branch type if condition is not met. (default: `false`)
658
- *
659
- * @example
660
- *
661
- * ```ts
662
- * type A = IfPositiveInteger<42>; // ➔ true
663
- * type B = IfPositiveInteger<-5>; // ➔ false
664
- * type C = IfPositiveInteger<42, "yes", "no">; // ➔ "yes"
665
- * type D = IfPositiveInteger<-5, "yes", "no">; // ➔ "no"
666
- * ```
667
- */
668
- type IfPositiveInteger<T extends number,IfTrue=true,IfFalse=false>=If<IsPositiveInteger<T>,IfTrue,IfFalse>;
669
- /** -------------------------------------------------------
670
- * * ***IfNegativeInteger.***
671
- * -------------------------------------------------------
672
- *
673
- * Conditional: selects one of two branches depending on whether `T` is a ***negative integer***.
674
- *
675
- * - Defaults: `IfTrue = true`, `IfFalse = false`.
676
- *
677
- * @template T - A number type.
678
- * @template IfTrue - The branch type if condition is met. (default: `true`)
679
- * @template IfFalse - The branch type if condition is not met. (default: `false`)
680
- *
681
- * @example
682
- *
683
- * ```ts
684
- * type A = IfNegativeInteger<-42>; // ➔ true
685
- * type B = IfNegativeInteger<5>; // ➔ false
686
- * type C = IfNegativeInteger<-42, "yes", "no">; // ➔ "yes"
687
- * type D = IfNegativeInteger<5, "yes", "no">; // ➔ "no"
688
- * ```
689
- */
690
- type IfNegativeInteger<T extends number,IfTrue=true,IfFalse=false>=If<IsNegativeInteger<T>,IfTrue,IfFalse>;
691
- /** -------------------------------------------------------
692
- * * ***IfPositiveFloat.***
693
- * -------------------------------------------------------
694
- *
695
- * Conditional: selects one of two branches depending on whether `T` is a ***positive float***.
696
- *
697
- * - Defaults: `IfTrue = true`, `IfFalse = false`.
698
- *
699
- * @template T - A number type.
700
- * @template IfTrue - The branch type if condition is met. (default: `true`)
701
- * @template IfFalse - The branch type if condition is not met. (default: `false`)
702
- *
703
- * @example
704
- *
705
- * ```ts
706
- * type A = IfPositiveFloat<3.14>; // ➔ true
707
- * type B = IfPositiveFloat<-2.5>; // ➔ false
708
- * type C = IfPositiveFloat<3.14, "yes", "no">; // ➔ "yes"
709
- * type D = IfPositiveFloat<-2.5, "yes", "no">; // ➔ "no"
710
- * ```
711
- */
712
- type IfPositiveFloat<T extends number,IfTrue=true,IfFalse=false>=If<IsPositiveFloat<T>,IfTrue,IfFalse>;
713
- /** -------------------------------------------------------
714
- * * ***IfNegativeFloat.***
715
- * -------------------------------------------------------
716
- * Conditional: selects one of two branches depending on whether `T` is a ***negative float***.
717
- * - Defaults: `IfTrue = true`, `IfFalse = false`.
718
- *
719
- * @template T - A number type.
720
- * @template IfTrue - The branch type if condition is met. (default: `true`)
721
- * @template IfFalse - The branch type if condition is not met. (default: `false`)
722
- * @example
723
- * ```ts
724
- * type A = IfNegativeFloat<-3.14>; // ➔ true
725
- * type B = IfNegativeFloat<2.5>; // ➔ false
726
- * type C = IfNegativeFloat<-3.14, "yes", "no">; // ➔ "yes"
727
- * type D = IfNegativeFloat<2.5, "yes", "no">; // ➔ "no"
728
- * ```
729
- */
730
- type IfNegativeFloat<T extends number,IfTrue=true,IfFalse=false>=If<IsNegativeFloat<T>,IfTrue,IfFalse>;
731
- /** -------------------------------------------------------
732
- * * ***ParseNumber.***
733
- * --------------------------------------------------------
734
- * Converts a string or property key literal into a ***number literal***.
735
- * - Supports decimal numbers only.
736
- * - Automatically trims whitespace.
737
- * - Returns the number literal if valid.
738
- * - Supports scientific notation strings (e.g., `"2e-3"`, `"-5e2"`, `"2E-3"`, `"-5E2"`).
739
- * - **Note:** TypeScript cannot represent very small (<1e-6) or very large (>1e15)
740
- * numbers as literal types. In such cases, scientific notation strings return `0`.
741
- * - Returns `0` for strings representing hexadecimal (`0x...`), octal (`0o...`), or binary (`0b...`) if they are string literals.
742
- * - Returns `never` for non-numeric strings or unsupported formats.
743
- *
744
- * @template T - A string, number, or symbol (property key).
745
- * @example
746
- * ```ts
747
- * // Number:
748
- * type A = ParseNumber<0>; // ➔ 0
749
- * type B = ParseNumber<-0>; // ➔ 0
750
- * type C = ParseNumber<-0.>; // ➔ 0
751
- * type D = ParseNumber<42>; // ➔ 42
752
- * type E = ParseNumber<0.42>; // ➔ 0.42
753
- * type F = ParseNumber<-5>; // ➔ -5
754
- * type G = ParseNumber<-2.5>; // ➔ -2.5
755
- * type H = ParseNumber<2.5e3>; // ➔ 2500
756
- * type I = ParseNumber<-2.5e3>;// ➔ -2500
757
- * type J = ParseNumber<5e3>; // ➔ 5000
758
- * type K = ParseNumber<-5e3>; // ➔ -5000
759
- * type L = ParseNumber<5e21>; // ➔ 5e+21
760
- * type M = ParseNumber<5e-3>; // ➔ 0.005
761
- * type N = ParseNumber<5e-21>; // ➔ 5e-21
762
- * type O = ParseNumber<-5e-3>; // ➔ -0.005
763
- *
764
- * // Numeric String:
765
- * type A = ParseNumber<"0">; // ➔ 0
766
- * type B = ParseNumber<"-0">; // ➔ 0
767
- * type C = ParseNumber<"42">; // ➔ 42
768
- * type D = ParseNumber<"0.42">; // ➔ 0.42
769
- * type E = ParseNumber<"-42">; // ➔ -42
770
- * type F = ParseNumber<"-0.42">; // ➔ -0.42
771
- * type G = ParseNumber<" 42 ">; // ➔ 42
772
- * type H = ParseNumber<" -42 ">; // ➔ -1
773
- *
774
- * // Scientific notation string:
775
- * type S1 = ParseNumber<"2e3">; // ➔ 2000
776
- * type S2 = ParseNumber<"-2e3">; // ➔ -2000
777
- * type S3 = ParseNumber<"2e-3">; // ➔ 0.002
778
- * type S4 = ParseNumber<"-2e-3">; // ➔ -0.002
779
- * type S5 = ParseNumber<"2.5e3">; // ➔ 0
780
- * type S6 = ParseNumber<"2.5e-3">; // ➔ 0
781
- * type S7 = ParseNumber<"2e-7">; // ➔ 0 (too small include "-2e-7" for TypeScript literal)
782
- * type S8 = ParseNumber<"5e21">; // ➔ 0 (too large include "-5e21" for TypeScript literal)
783
- *
784
- * // Number representing hexadecimal, octal or binary:
785
- * type A = ParseNumber<"011">; // ➔ 9 (same as octal but deprecated)
786
- * type B = ParseNumber<"0o11">; // ➔ 9 (octal)
787
- * type C = ParseNumber<"-0o11">; // ➔ -9 (octal)
788
- * type D = ParseNumber<"0x12">; // ➔ 18 (hexadecimal)
789
- * type E = ParseNumber<"-0x12">; // ➔ -18 (hexadecimal)
790
- * type F = ParseNumber<"0b111">; // ➔ 7 (binary)
791
- * type G = ParseNumber<"-0b111">; // ➔ -7 (binary)
792
- *
793
- * // String representing hexadecimal, octal or binary:
794
- * type A = ParseNumber<"0x2A">; // ➔ 0 (hex on string not supported)
795
- * type B = ParseNumber<"0o52">; // ➔ 0 (octal on string not supported)
796
- * type C = ParseNumber<"0b101010">; // ➔ 0 (binary on string not supported)
797
- *
798
- * // Never Result
799
- * type A = ParseNumber<string>; // ➔ never
800
- * type B = ParseNumber<number>; // ➔ never
801
- * type C = ParseNumber<"abc">; // ➔ never
802
- * type D = ParseNumber<"a1">; // ➔ never
803
- * type E = ParseNumber<"3b">; // ➔ never
804
- * ```
805
- */
806
- 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>;
807
- /** -------------------------------------------------------
808
- * * ***IsScientificNumber.***
809
- * -------------------------------------------------------
810
- *
811
- * Checks if a string literal `T` represents a **scientific number**.
812
- *
813
- * A scientific number is defined as a number in the form of:
814
- * - Optional negative sign (`-`)
815
- * - Mantissa (digits, can be integer or decimal)
816
- * - Exponent indicated by `e` or `E`
817
- * - Exponent value (digits, optional negative sign)
818
- *
819
- * **Important:** TypeScript cannot detect numeric literals in scientific notation
820
- * at type-level because number literals are normalized to decimals.
821
- * Only string literals like `"2.5E3"` or `"-1e-5"` can be detected.
822
- *
823
- * @template T - A string literal to check.
824
- *
825
- * @example
826
- * ```ts
827
- * type A = IsScientificNumber<"1e5">; // true
828
- * type B = IsScientificNumber<"-1e-5">; // true
829
- * type C = IsScientificNumber<"2.5E3">; // true
830
- * type D = IsScientificNumber<"42">; // false
831
- * type E = IsScientificNumber<"-0.42">; // false
832
- * type F = IsScientificNumber<string>; // false
833
- * ```
834
- *
835
- * @remarks
836
- * - Uses template literal types and conditional type {@link Extends}.
837
- * - Returns `true` if `T` is scientific number string literal, otherwise `false`.
838
- * - Returns `boolean` if `T` is generic `string`.
839
- */
840
- type IsScientificNumber<T extends string>=Extends<T,`${"-" | ""}${number}${"e" | "E"}${number}`>;
841
- /**
842
- * Helper for {@link ParseScientificNumber}
843
- */
844
- type BuildTuple<L extends number,T extends unknown[]=[]>=T["length"] extends L?T:BuildTuple<L,[...T,unknown]>;
845
- /**
846
- * Helper for {@link ParseScientificNumber}
847
- */
848
- type _DecrementParseScientific<N extends number>=BuildTuple<N>extends [ infer _,...infer Rest]?Rest["length"]:never;
849
- /** -------------------------------------------------------
850
- * * ***ParseScientificNumber***
851
- * -------------------------------------------------------
852
- *
853
- * Converts a numeric string in scientific notation (e.g., `"2e-3"`, `"-5e2"`)
854
- * into a literal number type.
855
- *
856
- * **Important:** TypeScript cannot represent very small or very large numbers
857
- * as literal types. In such cases, this utility will return `0`.
858
- *
859
- * @template T - A numeric string to parse. Can be in:
860
- * - Positive or negative scientific notation (e.g., `"1e3"`, `"-2e-2"`)
861
- * - Regular number literal (e.g., `"42"`, `"-5"`)
862
- *
863
- * @example
864
- * ```ts
865
- * type A1 = ParseScientificNumber<"2e-3">; // 0.002
866
- * type A2 = ParseScientificNumber<"-2e-3">; // -0.002
867
- * type A3 = ParseScientificNumber<"5e2">; // 500
868
- * type A4 = ParseScientificNumber<"-5e2">; // -500
869
- * type A5 = ParseScientificNumber<"2e-7">; // 0 (TypeScript cannot represent literal)
870
- * type A6 = ParseScientificNumber<"5e21">; // 0 (TypeScript cannot represent literal)
871
- * type A7 = ParseScientificNumber<"42">; // 42
872
- * type A8 = ParseScientificNumber<"-42">; // -42
873
- * ```
874
- *
875
- * @remarks
876
- * - Uses type-level string manipulation to handle scientific notation.
877
- * - Negative exponents are adjusted with {@link _DecrementParseScientific} and {@link Repeat}.
878
- * - Returns `0` if TypeScript cannot infer the exact numeric literal.
879
- */
880
- 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;
881
- /** -------------------------------------------------------
882
- * * ***Abs.***
883
- * -------------------------------------------------------
884
- *
885
- * Computes the ***absolute value*** of `T`.
886
- *
887
- * - Accepts `number` literals or numeric `string` literals.
888
- * - Returns the ***absolute value*** as a `number`.
889
- * - If `T` is not a valid number (e.g., hex, binary, octal, or non-numeric string), the result is `never`.
890
- *
891
- * @template T - A number type or string literal representing a number.
892
- *
893
- * @example
894
- *
895
- * ```ts
896
- * type A = Abs<-42>; // ➔ 42
897
- * type B = Abs<10>; // ➔ 10
898
- * type C = Abs<"11">; // ➔ 11
899
- * type D = Abs<"-11">; // ➔ 11
900
- *
901
- * // Not a number
902
- * type Invalid1 = Abs<"1a">; // ➔ never
903
- * type Invalid2 = Abs<"a1">; // ➔ never
904
- * type Invalid3 = Abs<"a1a">; // ➔ never
905
- * type Invalid4 = Abs<"abc">; // ➔ never
906
- * type Invalid5 = Abs<string>; // ➔ never
907
- * type Invalid6 = Abs<number>; // ➔ never
908
- * ```
909
- */
910
- type Abs<T extends PropertyKey|bigint>=`${Exclude<T, symbol>}`extends`-${infer PositiveT extends number}`?ParseNumber<PositiveT>:ParseNumber<T>;
911
- /** -------------------------------------------------------
912
- * * ***Negate.***
913
- * -------------------------------------------------------
914
- *
915
- * Produces the ***negated value*** of `T` (multiplies by `-1`).
916
- *
917
- * - Only supports valid **number literals** or **numeric-strings**.
918
- * - Invalid numeric-strings (e.g. `"1a"`, `"abc"`, hex, binary, octal)
919
- * or non-numeric types (e.g. `string`, `number`, `symbol`) will return `0`.
920
- *
921
- * @template T - A number type or numeric-string.
922
- *
923
- * @example
924
- *
925
- * ```ts
926
- * type A = Negate<5>; // ➔ -5
927
- * type B = Negate<-10>; // ➔ -10
928
- * type C = Negate<0>; // ➔ 0
929
- * type D = Negate<-0>; // ➔ 0
930
- * type E = Negate<"123">; // ➔ -123
931
- *
932
- * // Not a number or numeric-string:
933
- * type Invalid1 = Negate<string>; // ➔ 0
934
- * type Invalid2 = Negate<number>; // ➔ 0
935
- * type Invalid3 = Negate<"abc">; // ➔ 0
936
- * type Invalid4 = Negate<"1a">; // ➔ 0
937
- * type Invalid5 = Negate<"2b">; // ➔ 0
938
- * type Invalid6 = Negate<"0x1f">; // ➔ 0
939
- * type Invalid7 = Negate<"0b101">; // ➔ 0
940
- * type Invalid8 = Negate<"0o77">; // ➔ 0
941
- * ```
942
- */
943
- type Negate<T extends PropertyKey>=ParseNumber<`-${Abs<ParseNumber<T>>}`>;
944
- /** -------------------------------------------------------
945
- * * ***Split***
946
- * -------------------------------------------------------
947
- *
948
- * A type-level utility that mimics `String.prototype.split()`.
949
- * Splits a string literal `Str` into a tuple of substrings,
950
- * using `Del` as the delimiter.
951
- *
952
- * - If `Del` is the empty string `""`, the result is a tuple of characters.
953
- * - If `Del` is not found in `Str`, the result is a tuple with the original string.
954
- * - Works only with string literals. If `Str` is just `string`, the result is `string[]`.
955
- *
956
- * @template Str - The input string literal to be split.
957
- * @template Del - The delimiter used to split the string.
958
- * Defaults to `""` (character-level split).
959
- *
960
- * #### Constraints
961
- * - `Str` must be a string literal to get precise results.
962
- * - `Del` can be a string or number (numbers are converted to strings).
963
- *
964
- * #### Examples
965
- * ```ts
966
- * // ✅ Split into characters
967
- * type A = Split<"abc">; // ["a", "b", "c"]
968
- *
969
- * // ✅ Split by a comma
970
- * type B = Split<"a,b,c", ",">; // ["a", "b", "c"]
971
- *
972
- * // ✅ Split by multi-char delimiter
973
- * type C = Split<"2025-08-22", "-">; // ["2025", "08", "22"]
974
- *
975
- * // ✅ Delimiter not found → returns whole string
976
- * type D = Split<"hello", "|">; // ["hello"]
977
- *
978
- * // ⚠️ Non-literal string
979
- * type E = Split<string, ",">; // string[]
980
- * ```
981
- */
982
- 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 _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>;
983
- /** -------------------------------------------------------
984
- * * ***CharAt.***
985
- * -------------------------------------------------------
986
- * A type-level utility that extracts the character at a given index `N`
987
- * from a string literal type `I`.
988
- * - If the index is out of range, the result is `undefined`.
989
- * - If `I` is not a literal string (just `string`), the result is `undefined`.
990
- * - Only **positive indices** are supported (`0` and above`).
991
- *
992
- * @template I - The input string literal to extract the character from.
993
- * @template N - The zero-based index of the character to retrieve.
994
- * Can be a `number` or a stringified number (e.g. `2` or "2").
995
- * @example
996
- * ```ts
997
- * // ✅ Basic usage
998
- * type A = CharAt<"hello", 0>; // ➔ "h"
999
- * type B = CharAt<"hello", 1>; // ➔ "e"
1000
- * type C = CharAt<"hello", 4>; // ➔ "o"
1001
- *
1002
- * // ✅ Index out of range → undefined
1003
- * type D = CharAt<"hello", 5>; // ➔ undefined
1004
- * type E = CharAt<"abc", 99>; // ➔ undefined
1005
- *
1006
- * // ✅ Stringified index also works
1007
- * type F = CharAt<"testing", "0">; // ➔ "t"
1008
- * type G = CharAt<"testing", "2">; // ➔ "s"
1009
- * type H = CharAt<"testing", "6">; // ➔ "g"
1010
- * type I = CharAt<"testing", "7">; // ➔ undefined
1011
- *
1012
- * // ⚠️ Non-literal strings → undefined
1013
- * type J = CharAt<string, 2>; // ➔ undefined
1014
- *
1015
- * // ⚠️ Negative indices are not supported
1016
- * type K = CharAt<"abc", -1>; // ➔ undefined
1017
- * ```
1018
- */
1019
- type CharAt<I extends string,N extends number|`${number}`>=_CharAt<I,N>;
1020
- /** -------------------------------------------------------
1021
- * * ***IsUnknown.***
1022
- * -------------------------------------------------------
1023
- * Returns a boolean indicating whether the given type `T` is `unknown`.
1024
- *
1025
- * @template T - The type to check.
1026
- *
1027
- * @example
1028
- * ```ts
1029
- * type TrueResult = IsUnknown<unknown>; // ➔ true
1030
- * type FalseResult1 = IsUnknown<any>; // ➔ false
1031
- * type FalseResult2 = IsUnknown<string>; // ➔ false
1032
- * ```
1033
- */
1034
- type IsUnknown<T>=IsAny<T>extends true?false:[unknown] extends [T]?true:false;
1035
- /** -------------------------------------------------------
1036
- * * ***IfUnknown.***
1037
- * -------------------------------------------------------
1038
- * Conditional type: returns `IfTrue` if `T` is `unknown`, otherwise returns `IfFalse`.
1039
- *
1040
- * @template T - The type to check.
1041
- * @template IfTrue - The type returned if `T` is `unknown` (default: `true`).
1042
- * @template IfFalse - The type returned if `T` is not `unknown` (default: `false`).
1043
- *
1044
- * @example
1045
- * ```ts
1046
- * type Result1 = IfUnknown<unknown, "foo", "bar">; // ➔ "foo"
1047
- * type Result2 = IfUnknown<string, "foo", "bar">; // ➔ "bar"
1048
- * ```
1049
- */
1050
- type IfUnknown<T,IfTrue=true,IfFalse=false>=If<IsUnknown<T>,IfTrue,IfFalse>;
1051
- /** -------------------------------------------------------
1052
- * * ***UnknownifyPropertiesOptions.***
1053
- * -------------------------------------------------------
1054
- * Options for `UnknownifyProperties`.
1055
- *
1056
- * @property makeOptional - If `true`, all properties become optional.
1057
- */
1058
- type UnknownifyPropertiesOptions={
1059
- /**
1060
- * If `true`, all properties of the object become optional.
1061
- *
1062
- * DefaultValue: `false`.
1063
- *
1064
- * @default false
1065
- * @example
1066
- * ```ts
1067
- * type A = { a: string; b: number };
1068
- *
1069
- * type B = UnknownifyProperties<A, { makeOptional: true }>;
1070
- * // ➔ { a?: unknown; b?: unknown }
1071
- * ```
1072
- */
1073
- makeOptional:boolean;};
1074
- /** -------------------------------------------------------
1075
- * * ***UnknownifyProperties.***
1076
- * -------------------------------------------------------
1077
- * Transforms all properties of an object type `T` to `unknown`.
1078
- * Optionally, makes all properties optional based on `Options`.
1079
- *
1080
- * @template T - The object type to transform.
1081
- * @template Options - Configuration options (default: `{ makeOptional: false }`).
1082
- *
1083
- * @example
1084
- * ```ts
1085
- * type A = { a: string; b: number };
1086
- *
1087
- * type Result1 = UnknownifyProperties<A>;
1088
- * // ➔ { a: unknown; b: unknown }
1089
- *
1090
- * type Result2 = UnknownifyProperties<A, { makeOptional: true }>;
1091
- * // ➔ { a?: unknown; b?: unknown }
1092
- * ```
1093
- */
1094
- 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;
1095
- /** -------------------------------------------------------
1096
- * * ***MutableOptions***
1097
- * -------------------------------------------------------
1098
- *
1099
- * Configuration options for the ***{@link Mutable}*** type utilities.
1100
- *
1101
- * @property recursive - Whether to make nested objects mutable recursively.
1102
- * - If `true`, all nested objects will also have their `readonly` removed.
1103
- * - Default: `false`.
1104
- *
1105
- * @example
1106
- * ```ts
1107
- * type Opt1 = MutableOptions;
1108
- * // ➔ { recursive: boolean }
1109
- * ```
1110
- */
1111
- type MutableOptions={
1112
- /** Whether to make nested objects mutable recursively.
1113
- *
1114
- * - If `true`, all nested objects will also have their `readonly` removed.
1115
- * - Default value: `false`.
1116
- *
1117
- * @default false
1118
- */
1119
- recursive:boolean;};
1120
- /** -------------------------------------------------------
1121
- * * ***Mutable.***
1122
- * -------------------------------------------------------
1123
- * Removes `readonly` from all properties of the passed type `T`.
1124
- * - If `Options["recursive"]` is `true`, nested objects are also made mutable.
1125
- *
1126
- * @template T - The type to make mutable.
1127
- * @template Options - Configuration options. Default: `{ recursive: false }`.
1128
- * @example
1129
- * ```ts
1130
- * type Case1 = Mutable<{ readonly a: { readonly b: string } }>;
1131
- * // ➔ { a: { b: string } } (non-recursive by default)
1132
- *
1133
- * type Case2 = Mutable<{ readonly a: { readonly b: string } }, { recursive: true }>;
1134
- * // ➔ { a: { b: string } } (nested properties also mutable)
1135
- * ```
1136
- */
1137
- 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];}>;
1138
- /** -------------------------------------------------------
1139
- * * ***MutableOnly.***
1140
- * -------------------------------------------------------
1141
- * Removes `readonly` only from the specified keys `K` of type `T`.
1142
- *
1143
- * @template T - The type to modify.
1144
- * @template K - Keys to make mutable.
1145
- * @example
1146
- * ```ts
1147
- * type Case1 = MutableOnly<{ readonly a: string; readonly b: string }, "a">;
1148
- * // ➔ { a: string; readonly b: string }
1149
- *
1150
- * type Case2 = MutableOnly<{ readonly a: string; readonly b: string }, "a" | "b">;
1151
- * // ➔ { a: string; b: string }
1152
- * ```
1153
- */
1154
- type MutableOnly<T,K extends keyof T>=Prettify<Pick<T,Exclude<keyof T,K>>&{-readonly [P in K]:T[P];}>;
1155
- /** -------------------------------------------------------
1156
- * * ***MutableExcept.***
1157
- * -------------------------------------------------------
1158
- * Removes `readonly` from all properties of `T` **except** the specified keys `K`.
1159
- *
1160
- * @template T - The type to modify.
1161
- * @template K - Keys to keep as readonly.
1162
- * @example
1163
- * ```ts
1164
- * type Case1 = MutableExcept<{ readonly a: string; readonly b: string }, "b">;
1165
- * // ➔ { a: string; readonly b: string }
1166
- *
1167
- * type Case2 = MutableExcept<{ a: string; readonly b: string }, "a">;
1168
- * // ➔ { a: string; b: string } (all except "a" made mutable)
1169
- * ```
1170
- */
1171
- type MutableExcept<T,K extends keyof T>=Prettify<Pick<T,K>&{-readonly [P in Exclude<keyof T,K>]:T[P];}>;
1172
- /** -------------------------------------------------------
1173
- * * ***IsArray.***
1174
- * -------------------------------------------------------
1175
- * Returns a boolean whether the passed argument is an array.
1176
- *
1177
- * @example
1178
- * type Case1 = IsArray<[]>;
1179
- * // ➔ true
1180
- * type Case2 = IsArray<string>;
1181
- * // ➔ false
1182
- */
1183
- type IsArray<T>=AndArr<[ Not<IsAny<T>>,Not<IsNever<T>>,Extends<T,readonly unknown[]>]>;
1184
- /** -------------------------------------------------------
1185
- * * ***IsMutableArray.***
1186
- * -------------------------------------------------------
1187
- * Returns a boolean whether the passed argument is a mutable array.
1188
- *
1189
- * @example
1190
- * type Case1 = IsMutableArray<[]>;
1191
- * // ➔ true
1192
- * type Case2 = IsMutableArray<readonly []>;
1193
- * // ➔ false
1194
- */
1195
- type IsMutableArray<T>=And<IsArray<T>,NotExtends<Readonly<T>,T>>;
1196
- /** -------------------------------------------------------
1197
- * * ***IsReadonlyArray.***
1198
- * -------------------------------------------------------
1199
- * Returns a boolean whether the passed argument is a read-only array.
1200
- *
1201
- * @example
1202
- * type Case1 = IsReadonlyArray<readonly []>;
1203
- * // ➔ true
1204
- * type Case2 = IsReadonlyArray<[]>;
1205
- * // ➔ false
1206
- */
1207
- type IsReadonlyArray<T>=And<IsArray<T>,NotExtends<T,Mutable<T>>>;export type{PositiveInteger as $,And as A,IfPositiveFloat as B,CharAt as C,IfPositiveInteger as D,Even as E,Float as F,Integer as G,IsNegativeFloat as H,IsStringLiteral as I,IsOdd as J,IsPositiveFloat as K,IsPositiveInteger as L,Mutable as M,Negate as N,Or as O,ParseNumber as P,IsScientificNumber as Q,Repeat as R,Split as S,Negative as T,NegativeFloat as U,NegativeInteger as V,Odd as W,OddDigit as X,ParseScientificNumber as Y,Positive as Z,PositiveFloat as _,IsNegative as a,IfUnknown as a0,UnknownifyProperties as a1,UnknownifyPropertiesOptions as a2,Abs as b,IsFloat as c,IsUnknown as d,IsNegativeInteger as e,OrArr as f,AndArr as g,IsInteger as h,Push as i,IfNegative as j,IsPositive as k,IsEven as l,IsReadonlyArray as m,IfPositive as n,IsArray as o,IsMutableArray as p,MutableExcept as q,MutableOnly as r,MutableOptions as s,EvenDigit as t,IfEven as u,IfFloat as v,IfInteger as w,IfNegativeFloat as x,IfNegativeInteger as y,IfOdd as z};