@rzl-zone/build-tools 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/.references/index.d.cts +18 -0
- package/dist/.references/index.d.ts +18 -0
- package/dist/bundler/rolldown.cjs +32 -0
- package/dist/bundler/rolldown.cjs.map +1 -0
- package/dist/bundler/rolldown.d.cts +162 -0
- package/dist/bundler/rolldown.d.ts +162 -0
- package/dist/bundler/rolldown.js +25 -0
- package/dist/bundler/rolldown.js.map +1 -0
- package/dist/bundler/tsdown.cjs +132 -0
- package/dist/bundler/tsdown.cjs.map +1 -0
- package/dist/bundler/tsdown.d.cts +1165 -0
- package/dist/bundler/tsdown.d.ts +1165 -0
- package/dist/bundler/tsdown.js +124 -0
- package/dist/bundler/tsdown.js.map +1 -0
- package/dist/bundler/utils.cjs +24 -0
- package/dist/bundler/utils.cjs.map +1 -0
- package/dist/bundler/utils.d.cts +40 -0
- package/dist/bundler/utils.d.ts +40 -0
- package/dist/bundler/utils.js +21 -0
- package/dist/bundler/utils.js.map +1 -0
- package/dist/client-XhkdKJ4d.js +160 -0
- package/dist/client-XhkdKJ4d.js.map +1 -0
- package/dist/client-u8yLSxEI.cjs +221 -0
- package/dist/client-u8yLSxEI.cjs.map +1 -0
- package/dist/commander-kit/index.cjs +569 -0
- package/dist/commander-kit/index.cjs.map +1 -0
- package/dist/commander-kit/index.d.cts +1383 -0
- package/dist/commander-kit/index.d.ts +1383 -0
- package/dist/commander-kit/index.js +550 -0
- package/dist/commander-kit/index.js.map +1 -0
- package/dist/extra-CVuXMpEw.d.ts +994 -0
- package/dist/extra-CxDwtQEy.d.cts +994 -0
- package/dist/fast-globe-options-6r2aj6UC.d.ts +126 -0
- package/dist/fast-globe-options-BFt__e__.d.cts +126 -0
- package/dist/helper-BdjaR8Yv.js +215 -0
- package/dist/helper-BdjaR8Yv.js.map +1 -0
- package/dist/helper-DorgNsB9.cjs +377 -0
- package/dist/helper-DorgNsB9.cjs.map +1 -0
- package/dist/identity-BJ0QX7AJ.js +88 -0
- package/dist/identity-BJ0QX7AJ.js.map +1 -0
- package/dist/identity-CxR9DRMh.cjs +100 -0
- package/dist/identity-CxR9DRMh.cjs.map +1 -0
- package/dist/index-B-NeF7PU.d.cts +670 -0
- package/dist/index-CzxZta4Z.d.ts +356 -0
- package/dist/index-Idak1iwg.d.cts +356 -0
- package/dist/index-PXsb85LI.d.ts +670 -0
- package/dist/index.cjs +1689 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2193 -0
- package/dist/index.d.ts +2193 -0
- package/dist/index.js +1641 -0
- package/dist/index.js.map +1 -0
- package/dist/package-banner-6RzEf-mV.cjs +54 -0
- package/dist/package-banner-6RzEf-mV.cjs.map +1 -0
- package/dist/package-banner-BzheZbxy.js +41 -0
- package/dist/package-banner-BzheZbxy.js.map +1 -0
- package/dist/server-B2hBoGDR.cjs +181 -0
- package/dist/server-B2hBoGDR.cjs.map +1 -0
- package/dist/server-CWrDd29Y.js +142 -0
- package/dist/server-CWrDd29Y.js.map +1 -0
- package/dist/utils/client.cjs +23 -0
- package/dist/utils/client.d.cts +887 -0
- package/dist/utils/client.d.ts +887 -0
- package/dist/utils/client.js +12 -0
- package/dist/utils/server.cjs +17 -0
- package/dist/utils/server.d.cts +124 -0
- package/dist/utils/server.d.ts +124 -0
- package/dist/utils/server.js +12 -0
- package/package.json +151 -0
|
@@ -0,0 +1,994 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* ========================================================================
|
|
3
|
+
* @rzl-zone/build-tools
|
|
4
|
+
* ------------------------------------------------------------------------
|
|
5
|
+
* Version: `0.0.5`
|
|
6
|
+
* Author: `Rizalvin Dwiky <rizalvindwiky1998@gmail.com>`
|
|
7
|
+
* Repository: `https://github.com/rzl-zone/rzl-zone/tree/main/packages/build-tools`
|
|
8
|
+
* ========================================================================
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/** -------------------------------------------------------
|
|
12
|
+
* * ***Utility Type: `If`.***
|
|
13
|
+
* -------------------------------------------------------
|
|
14
|
+
* - **Conditional:**
|
|
15
|
+
* - Returns the second argument if the first argument is `true`, otherwise
|
|
16
|
+
* returns the third argument.
|
|
17
|
+
* - Defaults: `IfTrue = true`, `IfFalse = false`.
|
|
18
|
+
* @template Condition - The boolean condition to check.
|
|
19
|
+
* @template IfTrue - The branch type if condition is `true`. (default: `true`).
|
|
20
|
+
* @template IfFalse - The branch type if condition is `false`. (default: `false`).
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* type A = If<true, "valid">;
|
|
24
|
+
* // ➔ "valid"
|
|
25
|
+
* type B = If<false, "valid", "invalid">;
|
|
26
|
+
* // ➔ "invalid"
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
type If<Condition, IfTrue = true, IfFalse = false> = Condition extends true ? IfTrue : IfFalse;
|
|
30
|
+
/** -------------------------------------------------------
|
|
31
|
+
* * ***Utility Type: `IsNever`.***
|
|
32
|
+
* -------------------------------------------------------
|
|
33
|
+
* ****Conditional**: returns `true` if `T` is `never`, otherwise `false`.**
|
|
34
|
+
* @template T - Type to check.
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* type A = IsNever<never>; // ➔ true
|
|
38
|
+
* type B = IsNever<true>; // ➔ false
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
type IsNever<T> = [T] extends [never] ? true : false;
|
|
42
|
+
/** -------------------------------------------------------
|
|
43
|
+
* * ***Utility Type: `IfNever`.***
|
|
44
|
+
* -------------------------------------------------------
|
|
45
|
+
* **Conditional**: Selects one of two branches depending on whether `T` is `never`.**
|
|
46
|
+
* - Defaults: `IfTrue = true`, `IfFalse = false`.
|
|
47
|
+
* @template T - Type to check.
|
|
48
|
+
* @template IfTrue - The branch type if `T` is `never`, (default: `true`).
|
|
49
|
+
* @template IfFalse - The branch type if `T` is not `never`, (default: `false`).
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* type A = IfNever<never>;
|
|
53
|
+
* // ➔ true
|
|
54
|
+
* type B = IfNever<string>;
|
|
55
|
+
* // ➔ false
|
|
56
|
+
* type C = IfNever<never, 'valid', 'no'>;
|
|
57
|
+
* // ➔ 'valid'
|
|
58
|
+
* type D = IfNever<string, 'valid', 'no'>;
|
|
59
|
+
* // ➔ 'no'
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
/** -------------------------------------------------------
|
|
63
|
+
* * ***Utility Type: `Arrayable`.***
|
|
64
|
+
* -------------------------------------------------------
|
|
65
|
+
* **Useful when a function or API accepts **either one item or multiple items**.**
|
|
66
|
+
* - **Represents a type that can be either:**
|
|
67
|
+
* - a single value of type `T`, or an array of values of type `T`.
|
|
68
|
+
* @template T - The element type.
|
|
69
|
+
* @example
|
|
70
|
+
* ```ts
|
|
71
|
+
* function toArray<T>(input: Arrayable<T>): T[] {
|
|
72
|
+
* return Array.isArray(input) ? input : [input];
|
|
73
|
+
* }
|
|
74
|
+
*
|
|
75
|
+
* type A = Arrayable<string>;
|
|
76
|
+
* // ➔ string | string[]
|
|
77
|
+
*
|
|
78
|
+
* const a: A = "foo";
|
|
79
|
+
* const b: A = ["foo", "bar"];
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
type Arrayable<T> = T | Array<T>;
|
|
83
|
+
/** -------------------------------------------------------
|
|
84
|
+
* * ***Utility Type: `MutableArray`.***
|
|
85
|
+
* -------------------------------------------------------
|
|
86
|
+
* **Recursively creates a **mutable version** of a readonly array, tuple, or object type.**
|
|
87
|
+
* @description
|
|
88
|
+
* By default, TypeScript infers tuple/array literals as `readonly` (especially with `as const`).
|
|
89
|
+
* This utility removes the `readonly` modifier from all elements recursively,
|
|
90
|
+
* turning a readonly tuple, array, or object into a mutable one.
|
|
91
|
+
* - **Behavior:**
|
|
92
|
+
* - Optionally, if `Widen` is `true`, literal types (`1`, `'foo'`, `true`) are widened to
|
|
93
|
+
* their primitive equivalents (`number`, `string`, `boolean`) for easier assignment.
|
|
94
|
+
* @template T - The readonly array, tuple, or object type to make mutable.
|
|
95
|
+
* @template Widen - Whether to widen literal primitive types to their base types (default: `false`).
|
|
96
|
+
* @example
|
|
97
|
+
* ```ts
|
|
98
|
+
* type A = readonly [1, 2, 3];
|
|
99
|
+
* type B = MutableArray<A>;
|
|
100
|
+
* // ➔ [1, 2, 3]
|
|
101
|
+
*
|
|
102
|
+
* const x: A = [1, 2, 3] as const;
|
|
103
|
+
* // x[0] = 9; // ❌ Error: read-only
|
|
104
|
+
*
|
|
105
|
+
* const y: MutableArray<B,true> = [1, 2, 3];
|
|
106
|
+
* y[0] = 9; // ✅ Allowed
|
|
107
|
+
*
|
|
108
|
+
* // Recursive example with objects
|
|
109
|
+
* type Obj = readonly [{ a: 1, b: readonly [2] }];
|
|
110
|
+
* type MutableObj = MutableArray<Obj, true>;
|
|
111
|
+
* // ➔ [{ a: number; b: [number]; }]
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
/** -------------------------------------------------------
|
|
115
|
+
* * ***Utility Type: `AnyString`.***
|
|
116
|
+
* -------------------------------------------------------
|
|
117
|
+
* **A utility type that represents **any string value** while
|
|
118
|
+
* preventing unwanted widening of string literals to `string`.**
|
|
119
|
+
* @description
|
|
120
|
+
* This is achieved by intersecting `string` with `{}`,
|
|
121
|
+
* ensuring that the type remains assignable to `string`
|
|
122
|
+
* but is treated as a unique type in generic constraints.
|
|
123
|
+
* - **Useful in scenarios where:**
|
|
124
|
+
* - You want to accept **any string**, but still preserve
|
|
125
|
+
* literal types in inference.
|
|
126
|
+
* - You need stricter typing than just `string`.
|
|
127
|
+
* @example
|
|
128
|
+
* ```ts
|
|
129
|
+
* declare function acceptsAnyString<T extends AnyString>(value: T): T;
|
|
130
|
+
*
|
|
131
|
+
* // Preserves literal
|
|
132
|
+
* const a = acceptsAnyString("hello");
|
|
133
|
+
* // ➔ "hello"
|
|
134
|
+
*
|
|
135
|
+
* // Also allows generic string
|
|
136
|
+
* const b = acceptsAnyString(String("world"));
|
|
137
|
+
* // ➔ string
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
type AnyString = {} & string;
|
|
141
|
+
/** -------------------------------------------------------
|
|
142
|
+
* * ***Utility Type: `EmptyString`.***
|
|
143
|
+
* -------------------------------------------------------
|
|
144
|
+
* - **Conditional type:**
|
|
145
|
+
* - Returns the type `T` only if it is the empty string `""`.
|
|
146
|
+
* - Optionally trims whitespace before checking.
|
|
147
|
+
* - **Behavior:**
|
|
148
|
+
* - If `WithTrim` is `true` (default), trims `T` before checking.
|
|
149
|
+
* - If `T` is the general `string` type, returns `never`.
|
|
150
|
+
* - If `T` is empty (after optional trimming), returns `T` or `Trim<T>`.
|
|
151
|
+
* @template T - The string type to check.
|
|
152
|
+
* @template WithTrim - Whether to trim whitespace before checking (default `true`).
|
|
153
|
+
* @example
|
|
154
|
+
* ```ts
|
|
155
|
+
* // Basic empty string
|
|
156
|
+
* type Case1 = EmptyString<"">;
|
|
157
|
+
* // ➔ ""
|
|
158
|
+
*
|
|
159
|
+
* // Non-empty string
|
|
160
|
+
* type Case2 = EmptyString<"abc">;
|
|
161
|
+
* // ➔ never
|
|
162
|
+
*
|
|
163
|
+
* // General string type
|
|
164
|
+
* type Case3 = EmptyString<string>;
|
|
165
|
+
* // ➔ never
|
|
166
|
+
*
|
|
167
|
+
* // With leading/trailing whitespace
|
|
168
|
+
* type Case4 = EmptyString<" ", true>;
|
|
169
|
+
* // ➔ "" (trimmed)
|
|
170
|
+
* type Case5 = EmptyString<" ", false>;
|
|
171
|
+
* // ➔ never (not trimmed)
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
174
|
+
/** --------------------------------------------------
|
|
175
|
+
* * ***Utility Type: `AnyFunction`.***
|
|
176
|
+
* --------------------------------------------------
|
|
177
|
+
* **A generic type representing **any function** with
|
|
178
|
+
* any arguments and any return type.**
|
|
179
|
+
* @example
|
|
180
|
+
* const fn: AnyFunction = (a, b) => a + b;
|
|
181
|
+
* console.log(fn(1, 2)); // ➔ 3
|
|
182
|
+
*
|
|
183
|
+
* const fn2: AnyFunction = (x, y, z) => x + y - z;
|
|
184
|
+
* console.log(fn2(10, 20, 5)); // ➔ 25
|
|
185
|
+
*/
|
|
186
|
+
type AnyFunction = (...args: any[]) => any;
|
|
187
|
+
/** --------------------------------------------------
|
|
188
|
+
* * ***Utility Type: `ArgumentTypes`.***
|
|
189
|
+
* --------------------------------------------------
|
|
190
|
+
* **Extracts the **argument types** of a given function type `F`.**
|
|
191
|
+
* - ✅ Useful when you need to infer or reuse the parameter types
|
|
192
|
+
* from an existing function signature.
|
|
193
|
+
* @template F - A function type from which to extract argument types.
|
|
194
|
+
* @example
|
|
195
|
+
* ```ts
|
|
196
|
+
* type Args = ArgumentTypes<(a: number, b: string) => void>;
|
|
197
|
+
* // ➔ [number, string]
|
|
198
|
+
* ```
|
|
199
|
+
*/
|
|
200
|
+
/** --------------------------------------------------
|
|
201
|
+
* * ***Utility Type: `NodeBuiltins`.***
|
|
202
|
+
* --------------------------------------------------
|
|
203
|
+
* **Represents Node.js built-in core objects.**
|
|
204
|
+
* @description
|
|
205
|
+
* Includes commonly used Node.js core classes/objects that are not plain objects.
|
|
206
|
+
* - **Examples:**
|
|
207
|
+
* - `Buffer`.
|
|
208
|
+
* - `EventEmitter`.
|
|
209
|
+
* - `Stream`.
|
|
210
|
+
* - `URL`.
|
|
211
|
+
* - `process`.
|
|
212
|
+
* - ❌ Excludes plain objects (`{}`) and primitives.
|
|
213
|
+
* - ⚠️ Note:
|
|
214
|
+
* - This is **not exhaustive** because Node.js has
|
|
215
|
+
* many built-in modules, but it covers the main
|
|
216
|
+
* runtime objects often encountered.
|
|
217
|
+
*/
|
|
218
|
+
type NodeBuiltins = Buffer | NodeJS.EventEmitter | NodeJS.ReadableStream | NodeJS.WritableStream | NodeJS.Process | URL;
|
|
219
|
+
/** --------------------------------------------------
|
|
220
|
+
* * ***Utility Type: `DataTypes`.***
|
|
221
|
+
* --------------------------------------------------
|
|
222
|
+
* **Represents a broad union of commonly used JavaScript data types.**
|
|
223
|
+
* - ✅ ***Includes:***
|
|
224
|
+
* - `Primitive-Types`.
|
|
225
|
+
* - `object`.
|
|
226
|
+
* - `null`.
|
|
227
|
+
* - `undefined`.
|
|
228
|
+
* - `symbol`.
|
|
229
|
+
* - `Any-Function` signature.
|
|
230
|
+
* @example
|
|
231
|
+
* ```ts
|
|
232
|
+
* function isValidType(value: DataTypes): boolean {
|
|
233
|
+
* return value !== undefined && value !== null;
|
|
234
|
+
* }
|
|
235
|
+
* ```
|
|
236
|
+
*/
|
|
237
|
+
/** --------------------------------------------------
|
|
238
|
+
* * ***Utility Type: `TypedArray`.***
|
|
239
|
+
* --------------------------------------------------
|
|
240
|
+
* **Represents all JavaScript **TypedArray** types used for binary data manipulation.**
|
|
241
|
+
* - ✅ ***Includes:***
|
|
242
|
+
* - `Int8Array`.
|
|
243
|
+
* - `Uint8Array`.
|
|
244
|
+
* - `Uint8ClampedArray`.
|
|
245
|
+
* - `Int16Array`.
|
|
246
|
+
* - `Uint16Array`.
|
|
247
|
+
* - `Int32Array`.
|
|
248
|
+
* - `Uint32Array`.
|
|
249
|
+
* - `Float32Array`.
|
|
250
|
+
* - `Float64Array`.
|
|
251
|
+
* - `BigInt64Array`.
|
|
252
|
+
* - `BigUint64Array`.
|
|
253
|
+
*/
|
|
254
|
+
type TypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array;
|
|
255
|
+
/** --------------------------------------------------
|
|
256
|
+
* * ***Utility Type: `WebApiObjects`.***
|
|
257
|
+
* --------------------------------------------------
|
|
258
|
+
* **Represents common **Web API objects** available in the browser.**
|
|
259
|
+
* - ✅ ***Includes:***
|
|
260
|
+
* - URL: `URL`, `URLSearchParams`.
|
|
261
|
+
* - Networking: `Request`, `Response`, `Headers`, `WebSocket`.
|
|
262
|
+
* - Streams: `ReadableStream`, `WritableStream`, `TransformStream`.
|
|
263
|
+
* - Events: `Event`, `CustomEvent`, `MessageChannel`, `MessagePort`, `MessageEvent`.
|
|
264
|
+
* - DOM: `HTMLElement`, `Node`, `Document`, `Window`, `CanvasRenderingContext2D`.
|
|
265
|
+
* - Encoding: `TextEncoder`, `TextDecoder`.
|
|
266
|
+
* - File: `File`, `FileList`, `ImageBitmap`, `FormData`.
|
|
267
|
+
* - Abort: `AbortController`, `AbortSignal`.
|
|
268
|
+
* - Crypto: `CryptoKey`.
|
|
269
|
+
*/
|
|
270
|
+
type WebApiObjects = URL | URLSearchParams | FormData | Headers | Response | Request | ReadableStream<any> | WritableStream<any> | TransformStream<any, any> | MessageChannel | MessagePort | MessageEvent | Event | CustomEvent | HTMLElement | Node | Document | Window | AbortController | AbortSignal | TextEncoder | TextDecoder | CryptoKey | File | FileList | ImageBitmap | CanvasRenderingContext2D | WebSocket;
|
|
271
|
+
/** --------------------------------------------------
|
|
272
|
+
* * ***Utility Type: `IntlObjects`.***
|
|
273
|
+
* --------------------------------------------------
|
|
274
|
+
* **Represents all **ECMAScript Internationalization API** objects from `Intl`.**
|
|
275
|
+
* - ✅ ***Includes:***
|
|
276
|
+
* - `Intl.Collator`.
|
|
277
|
+
* - `Intl.DateTimeFormat`.
|
|
278
|
+
* - `Intl.NumberFormat`.
|
|
279
|
+
* - `Intl.RelativeTimeFormat`.
|
|
280
|
+
* - `Intl.PluralRules`.
|
|
281
|
+
* - `Intl.ListFormat`. (if environment is supported).
|
|
282
|
+
* - `Intl.Locale`. (if environment is supported).
|
|
283
|
+
*/
|
|
284
|
+
type IntlObjects = { [K in keyof typeof Intl]: (typeof Intl)[K] extends (abstract new (...args: any[]) => infer R) ? R : never }[keyof typeof Intl];
|
|
285
|
+
/** --------------------------------------------------
|
|
286
|
+
* * ***Utility Type: `BoxedPrimitivesTypes`.***
|
|
287
|
+
* --------------------------------------------------
|
|
288
|
+
* **Represents JavaScript **boxed primitive objects** (object wrappers for primitive values).**
|
|
289
|
+
* @description
|
|
290
|
+
* Boxed primitives are created using the `new` keyword on primitive wrapper constructors.
|
|
291
|
+
* - ✅ ***Includes (object wrappers):***
|
|
292
|
+
* - `new Number(123)` ➔ `Number`.
|
|
293
|
+
* - `new String("hello")` ➔ `String`.
|
|
294
|
+
* - `new Boolean(true)` ➔ `Boolean`.
|
|
295
|
+
* - ❌ ***Excludes (primitive values):***
|
|
296
|
+
* - `123` ➔ `number`.
|
|
297
|
+
* - `"hello"` ➔ `string`.
|
|
298
|
+
* - `true` ➔ `boolean`.
|
|
299
|
+
* - ℹ️ ***Note:***
|
|
300
|
+
* - These are **rarely used directly** in modern **JavaScript/TypeScript**.
|
|
301
|
+
* - However, they exist for completeness and are sometimes relevant
|
|
302
|
+
* when distinguishing between **primitive values** and **object wrappers**.
|
|
303
|
+
* @example
|
|
304
|
+
* ```ts
|
|
305
|
+
* const a: BoxedPrimitivesTypes = new Number(123);
|
|
306
|
+
* // ➔ ✅ valid
|
|
307
|
+
* const b: BoxedPrimitivesTypes = new String("abc");
|
|
308
|
+
* // ➔ ✅ valid
|
|
309
|
+
* const c: BoxedPrimitivesTypes = new Boolean(false);
|
|
310
|
+
* // ➔ ✅ valid
|
|
311
|
+
*
|
|
312
|
+
* // ❌ Not allowed (primitive values):
|
|
313
|
+
* const x: BoxedPrimitivesTypes = 123;
|
|
314
|
+
* const y: BoxedPrimitivesTypes = "abc";
|
|
315
|
+
* const z: BoxedPrimitivesTypes = true;
|
|
316
|
+
* ```
|
|
317
|
+
*/
|
|
318
|
+
type BoxedPrimitivesTypes = Number | String | Boolean;
|
|
319
|
+
/** --------------------------------------------------
|
|
320
|
+
* * ***Utility Type: `NonPlainObject`.***
|
|
321
|
+
* --------------------------------------------------
|
|
322
|
+
* **Represents all known **non-plain object types**,
|
|
323
|
+
* i.e., values that are **not** considered a `"plain object"` (`{ [key: string]: any }`).**
|
|
324
|
+
* - ✅ ***Includes:***
|
|
325
|
+
* - **Functions**.
|
|
326
|
+
* - **Arrays**.
|
|
327
|
+
* - **Native objects:** `Date`, `RegExp`, `Map`, `Set`, `WeakMap`, `WeakSet`.
|
|
328
|
+
* - **Built-in classes & APIs:** `Promise`, `Error`, `ArrayBuffer`, `DataView`.
|
|
329
|
+
* - **Typed arrays:** `TypedArray`.
|
|
330
|
+
* - **Browser & Node APIs:** `WebApiObjects`, `IntlObjects`, `NodeBuiltins`.
|
|
331
|
+
* - **Symbols**.
|
|
332
|
+
* - **Proxies** (wrapping any object).
|
|
333
|
+
* - The global **`Reflect`** object.
|
|
334
|
+
* - ❌ ***Excludes:***
|
|
335
|
+
* - Plain objects (`{ foo: string }`, `Record<string, any>`), `null` and `undefined`.
|
|
336
|
+
* - ℹ️ ***Note:***
|
|
337
|
+
* - Use this type when you need to differentiate **plain objects** from **all other object-like values**.
|
|
338
|
+
* @example
|
|
339
|
+
* ```ts
|
|
340
|
+
* type A = NonPlainObject;
|
|
341
|
+
*
|
|
342
|
+
* const x: A = new Date();
|
|
343
|
+
* // ➔ ✅ Allowed
|
|
344
|
+
* const y: A = [1, 2, 3];
|
|
345
|
+
* // ➔ ✅ Allowed
|
|
346
|
+
* const z: A = Promise.resolve(123);
|
|
347
|
+
* // ➔ ✅ Allowed
|
|
348
|
+
*
|
|
349
|
+
* // ❌ Not allowed (plain object):
|
|
350
|
+
* // const bad: A = { foo: "bar" };
|
|
351
|
+
* ```
|
|
352
|
+
*/
|
|
353
|
+
type NonPlainObject = BoxedPrimitivesTypes | AnyFunction | Promise<any> | Array<any> | AnObjectNonArray;
|
|
354
|
+
/** --------------------------------------------------
|
|
355
|
+
* * ***Utility Type: `AnObjectNonArray`.***
|
|
356
|
+
* --------------------------------------------------
|
|
357
|
+
* **Represents all **non-null, non-array, object-like values** in JavaScript/Node.js.**
|
|
358
|
+
* - ✅ ***Includes:***
|
|
359
|
+
* - **Built-in objects:** `Date`, `RegExp`, `Error`, `ArrayBuffer`, `DataView`.
|
|
360
|
+
* - **Collections:** `Map`, `Set`, `WeakMap`, `WeakSet`.
|
|
361
|
+
* - **Typed arrays:**
|
|
362
|
+
* `Int8Array`, `Uint8Array`, `Uint8ClampedArray`,
|
|
363
|
+
* `Int16Array`, `Uint16Array`,
|
|
364
|
+
* `Int32Array`, `Uint32Array`,
|
|
365
|
+
* `Float32Array`, `Float64Array`,
|
|
366
|
+
* `BigInt64Array`, `BigUint64Array`.
|
|
367
|
+
* - **Browser Web APIs:**
|
|
368
|
+
* `URL`, `URLSearchParams`, `FormData`, `Headers`, `Response`, `Request`,
|
|
369
|
+
* `ReadableStream`, `WritableStream`, `TransformStream`,
|
|
370
|
+
* `MessageChannel`, `MessagePort`, `MessageEvent`,
|
|
371
|
+
* `Event`, `CustomEvent`, `HTMLElement`, `Node`, `Document`, `Window`,
|
|
372
|
+
* `CanvasRenderingContext2D`,
|
|
373
|
+
* `AbortController`, `AbortSignal`,
|
|
374
|
+
* `TextEncoder`, `TextDecoder`,
|
|
375
|
+
* `CryptoKey`, `File`, `FileList`, `ImageBitmap`, `WebSocket`.
|
|
376
|
+
* - **ECMAScript Internationalization API objects:**
|
|
377
|
+
* `Intl.Collator`, `Intl.DateTimeFormat`, `Intl.NumberFormat`,
|
|
378
|
+
* `Intl.RelativeTimeFormat`, `Intl.PluralRules`,
|
|
379
|
+
* `Intl.ListFormat`, `Intl.Locale`.
|
|
380
|
+
* - **Node.js built-ins:** `Buffer`.
|
|
381
|
+
* - **Symbols**.
|
|
382
|
+
* - **Proxies** (wrapping any object).
|
|
383
|
+
* - The global **`Reflect`** object.
|
|
384
|
+
* - ❌ ***Excludes:***
|
|
385
|
+
* - `null`.
|
|
386
|
+
* - Arrays (`[]`, `new Array()`).
|
|
387
|
+
* - ℹ️ ***Note:***
|
|
388
|
+
* - Use this type when you need to represent **any object-like value except arrays and `null`**.
|
|
389
|
+
* @example
|
|
390
|
+
* ```ts
|
|
391
|
+
* const a: AnObjectNonArray = new Date();
|
|
392
|
+
* const b: AnObjectNonArray = new Map();
|
|
393
|
+
* const c: AnObjectNonArray = Symbol("id");
|
|
394
|
+
*
|
|
395
|
+
* // ❌ These are NOT allowed:
|
|
396
|
+
* // const x: AnObjectNonArray = null;
|
|
397
|
+
* // const y: AnObjectNonArray = [];
|
|
398
|
+
* ```
|
|
399
|
+
*/
|
|
400
|
+
type AnObjectNonArray = Date | RegExp | Map<any, any> | Set<any> | WeakMap<any, any> | WeakSet<any> | Error | ArrayBuffer | DataView | TypedArray | WebApiObjects | IntlObjects | NodeBuiltins | symbol | {
|
|
401
|
+
[Symbol.toStringTag]: "Proxy";
|
|
402
|
+
} | typeof Reflect;
|
|
403
|
+
/** -------------------------------------------------------
|
|
404
|
+
* * ***Utility Type: `IsGeneralArray`.***
|
|
405
|
+
* -------------------------------------------------------
|
|
406
|
+
* **Checks if `T` is a **general array type** (`X[]` or `ReadonlyArray<X>`)
|
|
407
|
+
* instead of a tuple literal.**
|
|
408
|
+
* - **Behavior:**
|
|
409
|
+
* - Returns `true` for `string[]`, `(number | boolean)[]`, `any[]`, etc.
|
|
410
|
+
* - Returns `false` for tuples like `[]`, `[1, 2, 3]`, or `[string, number]`.
|
|
411
|
+
* @template T - The type to check.
|
|
412
|
+
* @example
|
|
413
|
+
* ```ts
|
|
414
|
+
* type A = IsGeneralArray<string[]>; // ➔ true
|
|
415
|
+
* type B = IsGeneralArray<[]>; // ➔ false
|
|
416
|
+
* type C = IsGeneralArray<[1, 2, 3]>; // ➔ false
|
|
417
|
+
* type D = IsGeneralArray<ReadonlyArray<number>>; // ➔ true
|
|
418
|
+
* ```
|
|
419
|
+
*/
|
|
420
|
+
/** -------------------------------------------------------
|
|
421
|
+
* * ***Utility Type: `IsArrayOrTuple`.***
|
|
422
|
+
* -------------------------------------------------------
|
|
423
|
+
* **Checks if a given type `T` is an array or tuple type.**
|
|
424
|
+
* - This includes both mutable (`T[]`) and readonly (`readonly T[]`) arrays.
|
|
425
|
+
* @template T - The type to check.
|
|
426
|
+
* @example
|
|
427
|
+
* type A = IsArrayOrTuple<string[]>;
|
|
428
|
+
* // ➔ true
|
|
429
|
+
* type B = IsArrayOrTuple<readonly [string, number]>;
|
|
430
|
+
* // ➔ true
|
|
431
|
+
* type C = IsArrayOrTuple<string>; // ➔ false
|
|
432
|
+
*/
|
|
433
|
+
type IsArrayOrTuple<T> = T extends readonly any[] ? true : false;
|
|
434
|
+
/** -------------------------------------------------------
|
|
435
|
+
* * ***Utility Type: `IsConstructor`.***
|
|
436
|
+
* -------------------------------------------------------
|
|
437
|
+
* **Checks whether a given type `T` is a constructor type.**
|
|
438
|
+
*
|
|
439
|
+
* This utility evaluates to `true` if `T` has a constructor
|
|
440
|
+
* signature, including constructors of **abstract classes**.
|
|
441
|
+
*
|
|
442
|
+
* It uses the `abstract new (...args) => instance` signature,
|
|
443
|
+
* meaning it matches any type that represents a constructor —
|
|
444
|
+
* even if the class cannot be instantiated directly.
|
|
445
|
+
*
|
|
446
|
+
* - **Behavior:**
|
|
447
|
+
* - Evaluates to `true` if `T` has a compatible constructor signature.
|
|
448
|
+
* - Optionally validates the **constructor parameter tuple**
|
|
449
|
+
* and **instance type** using the generic parameters `A` and `R`.
|
|
450
|
+
*
|
|
451
|
+
* - **Difference from {@link IsNewable | `IsNewable`}:**
|
|
452
|
+
* - `IsConstructor` returns `true` for **both concrete and abstract constructors**.
|
|
453
|
+
* - `IsNewable` only returns `true` for constructors that can be
|
|
454
|
+
* instantiated with `new`.
|
|
455
|
+
*
|
|
456
|
+
* In other words:
|
|
457
|
+
*
|
|
458
|
+
* ```ts
|
|
459
|
+
* IsConstructor ⊇ IsNewable
|
|
460
|
+
* ```
|
|
461
|
+
*
|
|
462
|
+
* @template T - The type to check.
|
|
463
|
+
* @template A - Expected constructor parameter tuple (default: `any[]`).
|
|
464
|
+
* @template R - Expected instance type (default: `any`).
|
|
465
|
+
*
|
|
466
|
+
* @example
|
|
467
|
+
* ```ts
|
|
468
|
+
* class A {}
|
|
469
|
+
* abstract class B {}
|
|
470
|
+
*
|
|
471
|
+
* type T1 = IsConstructor<typeof A>;
|
|
472
|
+
* // ➔ true
|
|
473
|
+
* type T2 = IsConstructor<typeof B>;
|
|
474
|
+
* // ➔ true
|
|
475
|
+
* ```
|
|
476
|
+
*
|
|
477
|
+
* @example
|
|
478
|
+
* ```ts
|
|
479
|
+
* class User {
|
|
480
|
+
* constructor(x: number, y: string) {}
|
|
481
|
+
* }
|
|
482
|
+
*
|
|
483
|
+
* type T1 = IsConstructor<typeof User, [number, string], User>;
|
|
484
|
+
* // ➔ true
|
|
485
|
+
* type T2 = IsConstructor<typeof User, [string], User>;
|
|
486
|
+
* // ➔ false
|
|
487
|
+
* ```
|
|
488
|
+
*
|
|
489
|
+
* @example
|
|
490
|
+
* ```ts
|
|
491
|
+
* type T1 = IsConstructor<() => void>;
|
|
492
|
+
* // ➔ false
|
|
493
|
+
* ```
|
|
494
|
+
*/
|
|
495
|
+
type IsConstructor<T, A extends any[] = any[], R = any> = T extends (abstract new (...args: A) => R) ? true : false;
|
|
496
|
+
/** -------------------------------------------------------
|
|
497
|
+
* * ***Utility Type: `IsFunction`.***
|
|
498
|
+
* -------------------------------------------------------
|
|
499
|
+
* **Checks if a given type `T` is a callable function type.**
|
|
500
|
+
* @template T - The type to check.
|
|
501
|
+
* @example
|
|
502
|
+
* type A = IsFunction<() => void>; // ➔ true
|
|
503
|
+
* type B = IsFunction<string>; // ➔ false
|
|
504
|
+
*/
|
|
505
|
+
type IsFunction<T> = T extends AnyFunction ? true : false;
|
|
506
|
+
/** -------------------------------------------------------
|
|
507
|
+
* * ***Utility Type: `Primitive`.***
|
|
508
|
+
* -------------------------------------------------------
|
|
509
|
+
* **Represents **all primitive types in JavaScript/TypeScript**,
|
|
510
|
+
* including their literal variants.**
|
|
511
|
+
* - **This type matches:**
|
|
512
|
+
* - Core primitive types:
|
|
513
|
+
* - `string`, `number`, `boolean`, `bigint`, `symbol`, `null`, `undefined`.
|
|
514
|
+
* - Literal counterparts:
|
|
515
|
+
* - `"foo"`, `42`, `true`, etc.
|
|
516
|
+
* - ⚠️ ***Note:***
|
|
517
|
+
* - Unlike some definitions, this does **not** include `void` or `never`,
|
|
518
|
+
* since they are TypeScript-specific keywords, not runtime primitives.
|
|
519
|
+
* @example
|
|
520
|
+
* ```ts
|
|
521
|
+
* type A = Primitive;
|
|
522
|
+
* // ➔ any strict primitive type
|
|
523
|
+
* type B = "hello" extends Primitive ? true : false;
|
|
524
|
+
* // ➔ true
|
|
525
|
+
* type C = void extends Primitive ? true : false;
|
|
526
|
+
* // ➔ false
|
|
527
|
+
* ```
|
|
528
|
+
*/
|
|
529
|
+
type Primitive = string | number | bigint | boolean | symbol | null | undefined;
|
|
530
|
+
/** -------------------------------------------------------
|
|
531
|
+
* * ***Utility Type: `IsPrimitive`.***
|
|
532
|
+
* -------------------------------------------------------
|
|
533
|
+
* **Checks if a given type `T` is a **strict primitive type** in JavaScript/TypeScript,
|
|
534
|
+
* including literal variants.**
|
|
535
|
+
* - **Behavior:**
|
|
536
|
+
* - ***Includes:***
|
|
537
|
+
* - `string`, `number`, `bigint`, `boolean`, `symbol`, `null`, `undefined`.
|
|
538
|
+
* - Literal types like: `"foo"`, `42`, `true`.
|
|
539
|
+
* - ***Excludes:***
|
|
540
|
+
* - `void` (absence of value).
|
|
541
|
+
* - `never` (impossible type).
|
|
542
|
+
* - `object`, `unknown`, `Date`, `arrays`, `functions`, etc.
|
|
543
|
+
* @template T - The type to check
|
|
544
|
+
* @example
|
|
545
|
+
* ```ts
|
|
546
|
+
* type A = IsPrimitive<"foo">; // ➔ true
|
|
547
|
+
* type B = IsPrimitive<null>; // ➔ true
|
|
548
|
+
* type C = IsPrimitive<number>; // ➔ true
|
|
549
|
+
* type D = IsPrimitive<undefined>; // ➔ true
|
|
550
|
+
* type E = IsPrimitive<{}>; // ➔ false
|
|
551
|
+
* type F = IsPrimitive<void>; // ➔ false
|
|
552
|
+
* type G = IsPrimitive<never>; // ➔ false
|
|
553
|
+
* type H = IsPrimitive<unknown>; // ➔ false
|
|
554
|
+
* type I = IsPrimitive<object>; // ➔ false
|
|
555
|
+
* type J = IsPrimitive<Date>; // ➔ false
|
|
556
|
+
* type K = IsPrimitive<[]>; // ➔ false
|
|
557
|
+
* type L = IsPrimitive<() => void>; // ➔ false
|
|
558
|
+
* ```
|
|
559
|
+
*/
|
|
560
|
+
type IsPrimitive<T> = IsNever<T> extends true ? false : T extends Primitive ? true : false;
|
|
561
|
+
/** -------------------------------------------------------
|
|
562
|
+
* * ***Utility Type: `IsRealPrimitive`.***
|
|
563
|
+
* -------------------------------------------------------
|
|
564
|
+
* **Checks if a given type `T` is a **real primitive type** in JavaScript/TypeScript,
|
|
565
|
+
* based on runtime behavior, **excluding `null`** but including `undefined`.**
|
|
566
|
+
* - **Behavior:**
|
|
567
|
+
* - ***Includes:***
|
|
568
|
+
* - `string`, `number`, `bigint`, `boolean`, `symbol`, `undefined`.
|
|
569
|
+
* - Literal types like: `"foo"`, `42`, `true`.
|
|
570
|
+
* - ***Excludes:***
|
|
571
|
+
* - `null`.
|
|
572
|
+
* - `never` (impossible type).
|
|
573
|
+
* - Objects, arrays, functions, `Date`, `unknown`, etc.
|
|
574
|
+
* - ⚠️ ***Note:***
|
|
575
|
+
* - This aligns with runtime `typeof` checks in JS:
|
|
576
|
+
* - `typeof null === "object"`,
|
|
577
|
+
* so `null` is excluded from **“real primitives”**.
|
|
578
|
+
* @template T - The type to check.
|
|
579
|
+
* @example
|
|
580
|
+
* ```ts
|
|
581
|
+
* type A = IsRealPrimitive<42>; // ➔ true
|
|
582
|
+
* type B = IsRealPrimitive<string>; // ➔ true
|
|
583
|
+
* type C = IsRealPrimitive<boolean>; // ➔ true
|
|
584
|
+
* type D = IsRealPrimitive<undefined>; // ➔ true
|
|
585
|
+
* type E = IsRealPrimitive<{}>; // ➔ false
|
|
586
|
+
* type F = IsRealPrimitive<[]>; // ➔ false
|
|
587
|
+
* type G = IsRealPrimitive<null>; // ➔ false
|
|
588
|
+
* type H = IsRealPrimitive<Date>; // ➔ false
|
|
589
|
+
* type I = IsRealPrimitive<() => void>; // ➔ false
|
|
590
|
+
* ```
|
|
591
|
+
*/
|
|
592
|
+
/** * Applies readonly behavior according to mode. */
|
|
593
|
+
type ApplyReadonlyMode<T, Mode extends PrettifyOptions["readonlyMode"]> = Mode extends "remove" ? { -readonly [K in keyof T]: T[K] } : Mode extends "preserve" ? { readonly [K in keyof T]: T[K] } : { [K in keyof T]: T[K] };
|
|
594
|
+
/** ---------------------------------------------------------------------------
|
|
595
|
+
* * ***Options for {@link Prettify|`Prettify`}.***
|
|
596
|
+
* ---------------------------------------------------------------------------
|
|
597
|
+
* **Options for customizing the behavior of the {@link Prettify | **`Prettify`**} type utility.**
|
|
598
|
+
*/
|
|
599
|
+
type PrettifyOptions = {
|
|
600
|
+
/** -------------------------------------------------------
|
|
601
|
+
* * ***recursive***
|
|
602
|
+
* -------------------------------------------------------
|
|
603
|
+
* **Enables **deep prettification** of types when set to `true`.**
|
|
604
|
+
* @description
|
|
605
|
+
* By default (`false`), {@link Prettify | **`Prettify`**} only flattens the **top-level shape**
|
|
606
|
+
* of objects and intersections. Nested objects, arrays, and tuples remain as-is
|
|
607
|
+
* unless this option is enabled.
|
|
608
|
+
* - ***Behavior when `true`:***
|
|
609
|
+
* - **Plain objects**: Nested intersections are expanded recursively.
|
|
610
|
+
* - **Arrays & tuples**: Each element type is recursively prettified.
|
|
611
|
+
* - **Readonly handling**: Nested properties respect the `readonlyMode` option.
|
|
612
|
+
* - **Functions, constructors, and built-in objects** (Set, Map, Date, Promise, etc.)
|
|
613
|
+
* are **not** affected or expanded.
|
|
614
|
+
* - **Nested intersections**: Combined properties are flattened recursively.
|
|
615
|
+
* - ⚠️ ***Notes:***
|
|
616
|
+
* - Recursive mode only applies to **plain objects**, **arrays**, and **tuples**.
|
|
617
|
+
* - Readonly modifiers on nested properties follow the `readonlyMode` rules:
|
|
618
|
+
* - `"auto"` ➔ keep as-is
|
|
619
|
+
* - `"remove"` ➔ strip readonly
|
|
620
|
+
* - `"preserve"` ➔ make readonly
|
|
621
|
+
* - Arrays and tuples maintain `readonly` if the original type is `readonly` and `readonlyMode` is `"auto"` or `"preserve"`.
|
|
622
|
+
* @default false
|
|
623
|
+
* @example
|
|
624
|
+
* ```ts
|
|
625
|
+
* type Nested = {
|
|
626
|
+
* a: {
|
|
627
|
+
* readonly b: { c: number } & { d: string }
|
|
628
|
+
* } & { e: boolean };
|
|
629
|
+
* list: readonly ({ id: number } & { name: string })[];
|
|
630
|
+
* set: Set<{ x: number } & { y: string }>;
|
|
631
|
+
* };
|
|
632
|
+
*
|
|
633
|
+
* // Top-level only (default)
|
|
634
|
+
* type Shallow = Prettify<Nested>;
|
|
635
|
+
* // ➔ {
|
|
636
|
+
* // a: { readonly b: { c: number } & { d: string } } & { e: boolean };
|
|
637
|
+
* // list: readonly ({ id: number } & { name: string })[];
|
|
638
|
+
* // set: Set<{ x: number } & { y: string }>;
|
|
639
|
+
* // }
|
|
640
|
+
*
|
|
641
|
+
* // Fully recursive flatten
|
|
642
|
+
* type Deep = Prettify<Nested, { recursive: true }>;
|
|
643
|
+
* // ➔ {
|
|
644
|
+
* // a: { readonly b: { c: number; d: string }; e: boolean };
|
|
645
|
+
* // list: readonly { id: number; name: string }[];
|
|
646
|
+
* // set: Set<{ x: number } & { y: string }>; // built-in ignored
|
|
647
|
+
* // }
|
|
648
|
+
* ```
|
|
649
|
+
*/
|
|
650
|
+
recursive?: boolean;
|
|
651
|
+
/** -------------------------------------------------------
|
|
652
|
+
* * ***readonlyMode***
|
|
653
|
+
* -------------------------------------------------------
|
|
654
|
+
* **Determines how `readonly` modifiers are applied to properties
|
|
655
|
+
* when using {@link Prettify}.**
|
|
656
|
+
* - **Modes:**
|
|
657
|
+
* - `"auto"` ➔ Keep `readonly` exactly as in the original type (default).
|
|
658
|
+
* - `"remove"` ➔ Remove all `readonly` modifiers.
|
|
659
|
+
* - `"preserve"` ➔ Make all properties `readonly`.
|
|
660
|
+
* - **Behavior:**
|
|
661
|
+
* - Applies to both **top-level** and **nested properties** (if `recursive` is `true`).
|
|
662
|
+
* - Arrays and tuples preserve or adjust `readonly` according to the selected mode:
|
|
663
|
+
* - `"auto"` ➔ preserve array/tuple readonly as-is.
|
|
664
|
+
* - `"remove"` ➔ array/tuple becomes mutable.
|
|
665
|
+
* - `"preserve"` ➔ array/tuple becomes readonly.
|
|
666
|
+
* - Functions, constructors, and built-in objects (Set, Map, Date, Promise, etc.) are **not affected**.
|
|
667
|
+
* - Nested intersections respect `readonlyMode` recursively if `recursive` is enabled.
|
|
668
|
+
* - ⚠️ ***Notes:***
|
|
669
|
+
* - For nested objects, `readonly` behavior only changes if `recursive: true`.
|
|
670
|
+
* - `readonlyMode` does **not** override `readonly` on function parameters, methods, or constructors.
|
|
671
|
+
* @default "auto"
|
|
672
|
+
* @example
|
|
673
|
+
* ```ts
|
|
674
|
+
* type T = { readonly a: number; b: string };
|
|
675
|
+
*
|
|
676
|
+
* // Default: auto
|
|
677
|
+
* type Auto = Prettify<T, { readonlyMode: "auto" }>;
|
|
678
|
+
* // ➔ { readonly a: number; b: string }
|
|
679
|
+
*
|
|
680
|
+
* // Remove readonly
|
|
681
|
+
* type Remove = Prettify<T, { readonlyMode: "remove" }>;
|
|
682
|
+
* // ➔ { a: number; b: string }
|
|
683
|
+
*
|
|
684
|
+
* // Force all readonly
|
|
685
|
+
* type Preserve = Prettify<T, { readonlyMode: "preserve" }>;
|
|
686
|
+
* // ➔ { readonly a: number; readonly b: string }
|
|
687
|
+
*
|
|
688
|
+
* // Recursive + preserve
|
|
689
|
+
* type Nested = {
|
|
690
|
+
* config: { readonly port: number } & { host: string }
|
|
691
|
+
* };
|
|
692
|
+
* type RecursivePreserve = Prettify<Nested, { recursive: true; readonlyMode: "preserve" }>;
|
|
693
|
+
* // ➔ { readonly config: { readonly port: number; readonly host: string } }
|
|
694
|
+
* ```
|
|
695
|
+
*/
|
|
696
|
+
readonlyMode?: Extract<"auto" | "remove" | "preserve", string>;
|
|
697
|
+
/** ---------------------------------
|
|
698
|
+
* * ***Skips applying the prettify transformation.***
|
|
699
|
+
* ---------------------------------
|
|
700
|
+
*
|
|
701
|
+
* When enabled, the output will be returned as-is without running the
|
|
702
|
+
* prettify step.
|
|
703
|
+
*
|
|
704
|
+
* @default false
|
|
705
|
+
*
|
|
706
|
+
*/
|
|
707
|
+
skipPrettify?: boolean;
|
|
708
|
+
};
|
|
709
|
+
/** -------------------------------------------------------
|
|
710
|
+
* * ***DefaultPrettifyOptions***
|
|
711
|
+
* -------------------------------------------------------
|
|
712
|
+
* **Default options {@link Prettify | **`Prettify`**} used when no custom options are provided.**
|
|
713
|
+
*/
|
|
714
|
+
type DefaultPrettifyOptions = {
|
|
715
|
+
skipPrettify: false;
|
|
716
|
+
recursive: false;
|
|
717
|
+
readonlyMode: "auto";
|
|
718
|
+
};
|
|
719
|
+
type MergeReadonlyIntersection<T> = T extends readonly any[] ? T : T extends object ? { [K in keyof T]: T[K] } : T;
|
|
720
|
+
/** -------------------------------------------------------
|
|
721
|
+
* * ***Utility Type: `Prettify`.***
|
|
722
|
+
* -------------------------------------------------------
|
|
723
|
+
* **Flattens and simplifies complex TypeScript types into a more
|
|
724
|
+
* human-readable form, by forcing the compiler to expand intersections.**
|
|
725
|
+
* @description
|
|
726
|
+
* By default, only the **top-level shape** of an object is flattened.
|
|
727
|
+
* To also prettify **nested objects**, set the `recursive` option.
|
|
728
|
+
* - ⚠️ ***Note:***
|
|
729
|
+
* - `recursive: true` only affects **plain objects** and **arrays/tuples**.
|
|
730
|
+
* - Built-in objects like `Set`, `Map`, `Date`, `Promise`, etc.
|
|
731
|
+
* will **not** be recursively prettified.
|
|
732
|
+
* - `readonly` handling is controlled via the `readonlyMode` option.
|
|
733
|
+
* - **ℹ️ Options:**
|
|
734
|
+
* - `recursive?: boolean` (default: `false`):
|
|
735
|
+
* - Whether to recursively expand nested objects and intersections.
|
|
736
|
+
* - `readonlyMode?: "auto" | "remove" | "preserve"` (default: `"auto"`):
|
|
737
|
+
* - How `readonly` modifiers are treated:
|
|
738
|
+
* - `"auto"` ➔ preserve `readonly` as-is (**default**).
|
|
739
|
+
* - `"remove"` ➔ strip all `readonly`.
|
|
740
|
+
* - `"preserve"` ➔ enforce `readonly` everywhere.
|
|
741
|
+
* @template T - The type to prettify.
|
|
742
|
+
* @template Options - Configuration options.
|
|
743
|
+
* @example
|
|
744
|
+
* ```ts
|
|
745
|
+
* // --- Top-level only (default) ---
|
|
746
|
+
* type T0 = Prettify<{ a: number } & { b: string }>;
|
|
747
|
+
* // ➔ { a: number; b: string }
|
|
748
|
+
*
|
|
749
|
+
* // --- Recursive expansion of nested objects ---
|
|
750
|
+
* type T1 = Prettify<
|
|
751
|
+
* { a: { x: number } & { y: string } } & { b: boolean },
|
|
752
|
+
* { recursive: true }
|
|
753
|
+
* >;
|
|
754
|
+
* // ➔ { a: { x: number; y: string }; b: boolean }
|
|
755
|
+
*
|
|
756
|
+
* // --- Readonly handling modes ---
|
|
757
|
+
* type T2 = { readonly id: number; name: string };
|
|
758
|
+
*
|
|
759
|
+
* type R1 = Prettify<T2>;
|
|
760
|
+
* // (default: readonlyMode = "auto")
|
|
761
|
+
* // ➔ { readonly id: number; name: string }
|
|
762
|
+
*
|
|
763
|
+
* type R2 = Prettify<T2, { readonlyMode: "remove" }>;
|
|
764
|
+
* // ➔ { id: number; name: string }
|
|
765
|
+
*
|
|
766
|
+
* type R3 = Prettify<T2, { readonlyMode: "preserve" }>;
|
|
767
|
+
* // ➔ { readonly id: number; readonly name: string }
|
|
768
|
+
*
|
|
769
|
+
* // --- Readonly + mutable intersection ---
|
|
770
|
+
* type T3 = Prettify<{ readonly a: number } & { a: number; b: boolean }>;
|
|
771
|
+
* // ➔ { a: number; b: boolean }
|
|
772
|
+
* // (in "auto" mode, readonly lose over mutable)
|
|
773
|
+
*
|
|
774
|
+
* // --- Nested readonly with recursive ---
|
|
775
|
+
* type T4 = Prettify<
|
|
776
|
+
* { config: { readonly port: number } & { host: string } },
|
|
777
|
+
* { recursive: true }
|
|
778
|
+
* >;
|
|
779
|
+
* // ➔ { config: { readonly port: number; host: string } }
|
|
780
|
+
*
|
|
781
|
+
* // --- Arrays with readonly ---
|
|
782
|
+
* type T5 = Prettify<
|
|
783
|
+
* { list: readonly ({ id: number } & { name: string })[] },
|
|
784
|
+
* { recursive: true }
|
|
785
|
+
* >;
|
|
786
|
+
* // (readonly on array is preserved in "auto" mode)
|
|
787
|
+
* // ➔ { list: readonly { id: number; name: string }[] }
|
|
788
|
+
*
|
|
789
|
+
* type T6 = Prettify<
|
|
790
|
+
* { list: readonly ({ id: number } & { name: string })[] },
|
|
791
|
+
* { recursive: true; readonlyMode: "remove" }
|
|
792
|
+
* >;
|
|
793
|
+
* // ➔ { list: { id: number; name: string }[] }
|
|
794
|
+
*
|
|
795
|
+
* // --- Built-in objects are ignored (not expanded) ---
|
|
796
|
+
* type T7 = Prettify<
|
|
797
|
+
* { s: Set<{ a: number } & { b: string }> },
|
|
798
|
+
* { recursive: true }
|
|
799
|
+
* >;
|
|
800
|
+
* // ➔ { s: Set<{ a: number } & { b: string }> }
|
|
801
|
+
* ```
|
|
802
|
+
*/
|
|
803
|
+
type Prettify<T, Options extends PrettifyOptions = DefaultPrettifyOptions> = Options["skipPrettify"] extends true ? T : IsPrimitive<T> extends true ? T : IsFunction<T> extends true ? T : IsConstructor<T> extends true ? T : IsArrayOrTuple<T> extends true ? ApplyReadonlyMode<{ [K in keyof T]: If<Options["recursive"], Prettify<T[K], Options>, T[K]> }, Options["readonlyMode"]> : T extends NonPlainObject ? T : T extends object ? ApplyReadonlyMode<MergeReadonlyIntersection<{ [K in keyof T]: If<Options["recursive"], Prettify<T[K], Options>, T[K]> }>, Options["readonlyMode"]> : T;
|
|
804
|
+
/** ---------------------------------------------------------------------------
|
|
805
|
+
* * ***Options for {@link Mutable | `Mutable`}.***
|
|
806
|
+
* ---------------------------------------------------------------------------
|
|
807
|
+
* **Configuration options for the ***{@link Mutable | **`Mutable`**}*** type utilities.**
|
|
808
|
+
* @example
|
|
809
|
+
* ```ts
|
|
810
|
+
* type Opt1 = MutableOptions;
|
|
811
|
+
* // ➔ { recursive: boolean }
|
|
812
|
+
* ```
|
|
813
|
+
*/
|
|
814
|
+
/** -------------------------------------------------------
|
|
815
|
+
* * ***Utility Type: `NonUndefined`.***
|
|
816
|
+
* -------------------------------------------------------
|
|
817
|
+
* **Remove `undefined` from the given type `T`.**
|
|
818
|
+
* @template T - The type to filter.
|
|
819
|
+
* @example
|
|
820
|
+
* ```ts
|
|
821
|
+
* type A = NonUndefined<string | undefined>;
|
|
822
|
+
* // ➔ string
|
|
823
|
+
* type B = NonUndefined<number | null | undefined>;
|
|
824
|
+
* // ➔ number | null
|
|
825
|
+
* type C = NonUndefined<undefined>;
|
|
826
|
+
* // ➔ never
|
|
827
|
+
* ```
|
|
828
|
+
*/
|
|
829
|
+
type NonUndefined<T> = T extends undefined ? never : T;
|
|
830
|
+
/** --------------------------------------------------
|
|
831
|
+
* * ***Utility Type: `KeepNil`.***
|
|
832
|
+
* --------------------------------------------------
|
|
833
|
+
* **Keeps `null` and/or `undefined` in the output type **only if** they
|
|
834
|
+
* exist in the input type `T`, otherwise, resolves to `never`.**
|
|
835
|
+
* @template T - Input type to check for `null` and `undefined`.
|
|
836
|
+
* @example
|
|
837
|
+
* ```ts
|
|
838
|
+
* type A = KeepNil<string | null>;
|
|
839
|
+
* // ➔ null
|
|
840
|
+
* type B = KeepNil<number | undefined>;
|
|
841
|
+
* // ➔ undefined
|
|
842
|
+
* type C = KeepNil<string | null | undefined>;
|
|
843
|
+
* // ➔ null | undefined
|
|
844
|
+
* type D = KeepNil<boolean>;
|
|
845
|
+
* // ➔ never
|
|
846
|
+
* ```
|
|
847
|
+
*/
|
|
848
|
+
/** --------------------------------------------------
|
|
849
|
+
* * ***Utility Type: `OmitStrict`.***
|
|
850
|
+
* --------------------------------------------------
|
|
851
|
+
* **Strictly omits keys `K` from type `T`, with optional flattening for readability using `Prettify`.**
|
|
852
|
+
* - **Behavior:**
|
|
853
|
+
* - ✅ Enhances autocomplete and type inspection clarity in editors.
|
|
854
|
+
* - ✅ Optionally flattens nested intersections or mapped types into a cleaner shape.
|
|
855
|
+
* @template T - The original object type.
|
|
856
|
+
* @template K - The keys to omit from `T`.
|
|
857
|
+
* @template PrettifyOptions - Options controlling whether the resulting
|
|
858
|
+
* type should be normalized using the `Prettify` helper.
|
|
859
|
+
* @example
|
|
860
|
+
* ```ts
|
|
861
|
+
* type A = { a: number; b: string; c: boolean };
|
|
862
|
+
* type B = OmitStrict<A, 'b'>;
|
|
863
|
+
* // ➔ { a: number; c: boolean }
|
|
864
|
+
*
|
|
865
|
+
* type C = OmitStrict<A, 'b', { skipPrettify: true }>;
|
|
866
|
+
* // ➔ Omit without prettifying, keeps intersection structure
|
|
867
|
+
*
|
|
868
|
+
* type D = OmitStrict<A, 'b', true, { recursive: false }>;
|
|
869
|
+
* // ➔ Prettifies only top level, does not recurse into nested objects
|
|
870
|
+
* ```
|
|
871
|
+
*/
|
|
872
|
+
type OmitStrict<T, K extends keyof T, PrettifyOptions$9 extends PrettifyOptions = DefaultPrettifyOptions> = Prettify<Omit<T, K>, PrettifyOptions$9>;
|
|
873
|
+
/** ----------------------------------------------------------------
|
|
874
|
+
* * ***Options for {@link OverrideTypes | `OverrideTypes`}.***
|
|
875
|
+
* ----------------------------------------------------------------
|
|
876
|
+
* Configuration options controlling how overriding behaves.
|
|
877
|
+
*/
|
|
878
|
+
type OverrideTypesOptions = {
|
|
879
|
+
/** * ***Whether overriding keys must exist in the base type `T`.***
|
|
880
|
+
*
|
|
881
|
+
* - If `true`, all keys of `U` must exist in `T`.
|
|
882
|
+
* - If `false`, additional keys from `U` are allowed and will be added
|
|
883
|
+
* to the resulting type.
|
|
884
|
+
*
|
|
885
|
+
* @default true
|
|
886
|
+
*/
|
|
887
|
+
strictKeys: boolean;
|
|
888
|
+
/** * ***Options forwarded to {@link Prettify | `Prettify`}.***
|
|
889
|
+
*
|
|
890
|
+
* Controls how the resulting type is normalized.
|
|
891
|
+
*/
|
|
892
|
+
prettifyOptions?: PrettifyOptions;
|
|
893
|
+
};
|
|
894
|
+
type StrictOverrideConstraint<T, U, Strict extends boolean> = Strict extends true ? { [K in keyof U]: K extends keyof T ? unknown : never } : unknown;
|
|
895
|
+
type ResolvePrettifyOptions<O extends OverrideTypesOptions> = O["prettifyOptions"] extends PrettifyOptions ? O["prettifyOptions"] : DefaultPrettifyOptions;
|
|
896
|
+
/** --------------------------------------------------
|
|
897
|
+
* * ***Utility Type: `OverrideTypes`.***
|
|
898
|
+
* --------------------------------------------------
|
|
899
|
+
* Overrides properties in type `T` using properties from type `U`.
|
|
900
|
+
*
|
|
901
|
+
* Keys that exist in both `T` and `U` will take the value type from `U`,
|
|
902
|
+
* while all other properties from `T` remain unchanged.
|
|
903
|
+
*
|
|
904
|
+
* The behavior can be configured using {@link OverrideTypesOptions}.
|
|
905
|
+
*
|
|
906
|
+
* @template T - The base object type whose properties will be overridden.
|
|
907
|
+
* @template U - The object type providing overriding property types.
|
|
908
|
+
* @template Options - Configuration controlling override behavior.
|
|
909
|
+
*
|
|
910
|
+
* @remarks
|
|
911
|
+
* - When `Options["strictKeys"]` is `true` (default), all keys in `U`
|
|
912
|
+
* **must already exist in `T`**.
|
|
913
|
+
* - When `strictKeys` is `false`, `U` may introduce **additional keys**
|
|
914
|
+
* which will be added to the resulting type.
|
|
915
|
+
* - The resulting type is normalized using {@link Prettify}.
|
|
916
|
+
*
|
|
917
|
+
* @example
|
|
918
|
+
* // Basic override
|
|
919
|
+
* type A = { a: number; b: string };
|
|
920
|
+
* type B = { b: boolean };
|
|
921
|
+
* type C = OverrideTypes<A, B>;
|
|
922
|
+
* // Result:
|
|
923
|
+
* // {
|
|
924
|
+
* // a: number;
|
|
925
|
+
* // b: boolean;
|
|
926
|
+
* // }
|
|
927
|
+
*
|
|
928
|
+
* @example
|
|
929
|
+
* // Strict key enforcement (default)
|
|
930
|
+
* type A = { a: number; b: string };
|
|
931
|
+
* type B = { x: string[]; b: boolean };
|
|
932
|
+
* // @ts-expect-error
|
|
933
|
+
* type C = OverrideTypes<A, B>;
|
|
934
|
+
* // Error: "x" is not assignable to keyof A
|
|
935
|
+
*
|
|
936
|
+
* @example
|
|
937
|
+
* // Allow additional keys
|
|
938
|
+
* type A = { a: number; b: string };
|
|
939
|
+
* type B = { x: string[]; b: boolean };
|
|
940
|
+
* type C = OverrideTypes<A, B, { strictKeys: false }>;
|
|
941
|
+
* // Result:
|
|
942
|
+
* // {
|
|
943
|
+
* // a: number;
|
|
944
|
+
* // b: boolean;
|
|
945
|
+
* // x: string[];
|
|
946
|
+
* // }
|
|
947
|
+
*
|
|
948
|
+
* @example
|
|
949
|
+
* // Custom Prettify options
|
|
950
|
+
* type A = { a: number; b: string };
|
|
951
|
+
* type B = { b: boolean };
|
|
952
|
+
* type C = OverrideTypes<
|
|
953
|
+
* A,
|
|
954
|
+
* B,
|
|
955
|
+
* {
|
|
956
|
+
* strictKeys: true;
|
|
957
|
+
* prettifyOptions: { skipPrettify: true };
|
|
958
|
+
* }
|
|
959
|
+
* >;
|
|
960
|
+
*/
|
|
961
|
+
type OverrideTypes<T, U extends StrictOverrideConstraint<T, U, Options["strictKeys"]>, Options extends OverrideTypesOptions = {
|
|
962
|
+
strictKeys: true;
|
|
963
|
+
prettifyOptions: DefaultPrettifyOptions;
|
|
964
|
+
}> = Options["strictKeys"] extends true ? Exclude<keyof U, keyof T> extends never ? Prettify<OmitStrict<T, Extract<keyof U, keyof T>, ResolvePrettifyOptions<Options>> & U, ResolvePrettifyOptions<Options>> : never : Prettify<OmitStrict<T, Extract<keyof U, keyof T>, ResolvePrettifyOptions<Options>> & { [K in keyof U]: U[K] }, ResolvePrettifyOptions<Options>>;
|
|
965
|
+
/** --------------------------------------------------
|
|
966
|
+
* * ***Utility Type: `StrictAwaitable`.***
|
|
967
|
+
* --------------------------------------------------
|
|
968
|
+
* **Represents a value that may be synchronous or a
|
|
969
|
+
* native `Promise`.**
|
|
970
|
+
*
|
|
971
|
+
* Unlike {@link Awaitable | `Awaitable`}, this type **does not accept
|
|
972
|
+
* arbitrary thenables (`PromiseLike`)** and only allows
|
|
973
|
+
* real `Promise` instances.
|
|
974
|
+
*
|
|
975
|
+
* This is sometimes preferred for **tooling APIs or
|
|
976
|
+
* controlled async flows** where supporting generic
|
|
977
|
+
* thenables is unnecessary or undesirable.
|
|
978
|
+
*
|
|
979
|
+
* --------------------------------------------------
|
|
980
|
+
* @template T - The inner value type.
|
|
981
|
+
*
|
|
982
|
+
* @example
|
|
983
|
+
* ```ts
|
|
984
|
+
* function maybeAsync<T>(v: StrictAwaitable<T>): Promise<T> {
|
|
985
|
+
* return Promise.resolve(v);
|
|
986
|
+
* }
|
|
987
|
+
*
|
|
988
|
+
* maybeAsync(123); // Promise<number>
|
|
989
|
+
* maybeAsync(Promise.resolve("ok")); // Promise<string>
|
|
990
|
+
* ```
|
|
991
|
+
*/
|
|
992
|
+
type StrictAwaitable<T> = T | Promise<T>;
|
|
993
|
+
export { OmitStrict as a, PrettifyOptions as c, NonUndefined as i, StrictAwaitable as l, Arrayable as n, OverrideTypes as o, DefaultPrettifyOptions as r, Prettify as s, AnyString as t };
|
|
994
|
+
//# sourceMappingURL=extra-CxDwtQEy.d.cts.map
|