@rzl-zone/utils-js 3.3.0 → 3.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +74 -41
- package/dist/assertions/index.d.ts +1 -1
- package/dist/conversions/index.d.ts +1 -1
- package/dist/formatters/index.d.ts +1 -1
- package/dist/generators/index.d.ts +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/{isPlainObject-DGJkcFYw.d.ts → isPlainObject-CEPWPiXh.d.ts} +1 -1
- package/dist/next/index.d.ts +1 -1
- package/dist/operations/index.d.ts +1 -1
- package/dist/predicates/index.d.ts +1 -1
- package/dist/promises/index.d.ts +1 -1
- package/dist/strings/index.d.ts +1 -1
- package/package.json +2 -7
- package/dist/NumberRangeUnion-B6bhM2s7.d.ts +0 -33
- package/dist/any-v4TsK9ES.d.ts +0 -66
- package/dist/arrays-normalize-recursive-BqmVuFlD.d.ts +0 -72
- package/dist/extends-DtdRjDyU.d.ts +0 -343
- package/dist/if-ChM35c_q.d.ts +0 -19
- package/dist/is-array-BJeHxPM3.d.ts +0 -952
- package/dist/never-D89PbPh5.d.ts +0 -66
- package/dist/nils-CO8zLHSB.d.ts +0 -151
- package/dist/or-C6qzKt2I.d.ts +0 -82
- package/dist/override-CL2olHE5.d.ts +0 -59
- package/dist/pick-BSMX6Xe2.d.ts +0 -15
- package/dist/prettify-3o8_Kw6b.d.ts +0 -564
- package/dist/promises-LU7K00H0.d.ts +0 -72
- package/dist/string-B1jlOnws.d.ts +0 -312
- package/dist/types/index.d.ts +0 -3345
|
@@ -1,564 +0,0 @@
|
|
|
1
|
-
import{I as If}from'./if-ChM35c_q.js';import{I as IsNever}from'./never-D89PbPh5.js';
|
|
2
|
-
/** --------------------------------------------------
|
|
3
|
-
* * ***Utility Type: `AnyFunction`.***
|
|
4
|
-
* --------------------------------------------------
|
|
5
|
-
* **A generic type representing **any function** with
|
|
6
|
-
* any arguments and any return type.**
|
|
7
|
-
* @example
|
|
8
|
-
* const fn: AnyFunction = (a, b) => a + b;
|
|
9
|
-
* console.log(fn(1, 2)); // ➔ 3
|
|
10
|
-
*
|
|
11
|
-
* const fn2: AnyFunction = (x, y, z) => x + y - z;
|
|
12
|
-
* console.log(fn2(10, 20, 5)); // ➔ 25
|
|
13
|
-
*/
|
|
14
|
-
type AnyFunction=(...args:any[])=>any;
|
|
15
|
-
/** --------------------------------------------------
|
|
16
|
-
* * ***Utility Type: `NodeBuiltins`.***
|
|
17
|
-
* --------------------------------------------------
|
|
18
|
-
* **Represents Node.js built-in core objects.**
|
|
19
|
-
* @description
|
|
20
|
-
* Includes commonly used Node.js core classes/objects that are not plain objects.
|
|
21
|
-
* - **Examples:**
|
|
22
|
-
* - `Buffer`.
|
|
23
|
-
* - `EventEmitter`.
|
|
24
|
-
* - `Stream`.
|
|
25
|
-
* - `URL`.
|
|
26
|
-
* - `process`.
|
|
27
|
-
* - ❌ Excludes plain objects (`{}`) and primitives.
|
|
28
|
-
* - ⚠️ Note:
|
|
29
|
-
* - This is **not exhaustive** because Node.js has
|
|
30
|
-
* many built-in modules, but it covers the main
|
|
31
|
-
* runtime objects often encountered.
|
|
32
|
-
*/
|
|
33
|
-
type NodeBuiltins=Buffer|NodeJS.EventEmitter|NodeJS.ReadableStream|NodeJS.WritableStream|NodeJS.Process|URL;
|
|
34
|
-
/** --------------------------------------------------
|
|
35
|
-
* * ***Utility Type: `DataTypes`.***
|
|
36
|
-
* --------------------------------------------------
|
|
37
|
-
* **Represents a broad union of commonly used JavaScript data types.**
|
|
38
|
-
* - ✅ ***Includes:***
|
|
39
|
-
* - `Primitive-Types`.
|
|
40
|
-
* - `object`.
|
|
41
|
-
* - `null`.
|
|
42
|
-
* - `undefined`.
|
|
43
|
-
* - `symbol`.
|
|
44
|
-
* - `Any-Function` signature.
|
|
45
|
-
* @example
|
|
46
|
-
* ```ts
|
|
47
|
-
* function isValidType(value: DataTypes): boolean {
|
|
48
|
-
* return value !== undefined && value !== null;
|
|
49
|
-
* }
|
|
50
|
-
* ```
|
|
51
|
-
*/
|
|
52
|
-
type DataTypes=bigint|boolean|AnyFunction|null|number|object|string|symbol|undefined;
|
|
53
|
-
/** --------------------------------------------------
|
|
54
|
-
* * ***Utility Type: `DeepReplaceType`.***
|
|
55
|
-
* --------------------------------------------------
|
|
56
|
-
* **Recursively traverses an array, tuple, or object (including nested structures)
|
|
57
|
-
* and replaces all values of type `Target` with `NewType`.**
|
|
58
|
-
* - ✅ Useful for remapping deeply nested arrays, tuples, or records.
|
|
59
|
-
* @template Arr - The input array, tuple, or object.
|
|
60
|
-
* @template Target - The type to match and replace.
|
|
61
|
-
* @template NewType - The new type to assign to matched values.
|
|
62
|
-
* @example
|
|
63
|
-
* ```ts
|
|
64
|
-
* // Simple tuple
|
|
65
|
-
* type A = [number, string, [number]];
|
|
66
|
-
* type B = DeepReplaceType<A, number, boolean>;
|
|
67
|
-
* // ➔ [boolean, string, [boolean]]
|
|
68
|
-
*
|
|
69
|
-
* // Nested object
|
|
70
|
-
* type Obj = { a: number; b: { c: number; d: string } };
|
|
71
|
-
* type ObjReplaced = DeepReplaceType<Obj, number, boolean>;
|
|
72
|
-
* // ➔ { a: boolean; b: { c: boolean; d: string } }
|
|
73
|
-
*
|
|
74
|
-
* // Mixed array and object
|
|
75
|
-
* type Mixed = [{ x: number }, { y: string, z: number[] }];
|
|
76
|
-
* type MixedReplaced = DeepReplaceType<Mixed, number, boolean>;
|
|
77
|
-
* // ➔ [{ x: boolean }, { y: string, z: boolean[] }]
|
|
78
|
-
* ```
|
|
79
|
-
*/
|
|
80
|
-
type DeepReplaceType<Arr,Target,NewType>=Arr extends Target?NewType:Arr extends object?{[K in keyof Arr]:DeepReplaceType<Arr[K],Target,NewType>;}:Arr;
|
|
81
|
-
/** --------------------------------------------------
|
|
82
|
-
* * ***Utility Type: `TypedArray`.***
|
|
83
|
-
* --------------------------------------------------
|
|
84
|
-
* **Represents all JavaScript **TypedArray** types used for binary data manipulation.**
|
|
85
|
-
* - ✅ ***Includes:***
|
|
86
|
-
* - `Int8Array`.
|
|
87
|
-
* - `Uint8Array`.
|
|
88
|
-
* - `Uint8ClampedArray`.
|
|
89
|
-
* - `Int16Array`.
|
|
90
|
-
* - `Uint16Array`.
|
|
91
|
-
* - `Int32Array`.
|
|
92
|
-
* - `Uint32Array`.
|
|
93
|
-
* - `Float32Array`.
|
|
94
|
-
* - `Float64Array`.
|
|
95
|
-
* - `BigInt64Array`.
|
|
96
|
-
* - `BigUint64Array`.
|
|
97
|
-
*/
|
|
98
|
-
type TypedArray=Int8Array|Uint8Array|Uint8ClampedArray|Int16Array|Uint16Array|Int32Array|Uint32Array|Float32Array|Float64Array|BigInt64Array|BigUint64Array;
|
|
99
|
-
/** --------------------------------------------------
|
|
100
|
-
* * ***Utility Type: `WebApiObjects`.***
|
|
101
|
-
* --------------------------------------------------
|
|
102
|
-
* **Represents common **Web API objects** available in the browser.**
|
|
103
|
-
* - ✅ ***Includes:***
|
|
104
|
-
* - URL: `URL`, `URLSearchParams`.
|
|
105
|
-
* - Networking: `Request`, `Response`, `Headers`, `WebSocket`.
|
|
106
|
-
* - Streams: `ReadableStream`, `WritableStream`, `TransformStream`.
|
|
107
|
-
* - Events: `Event`, `CustomEvent`, `MessageChannel`, `MessagePort`, `MessageEvent`.
|
|
108
|
-
* - DOM: `HTMLElement`, `Node`, `Document`, `Window`, `CanvasRenderingContext2D`.
|
|
109
|
-
* - Encoding: `TextEncoder`, `TextDecoder`.
|
|
110
|
-
* - File: `File`, `FileList`, `ImageBitmap`, `FormData`.
|
|
111
|
-
* - Abort: `AbortController`, `AbortSignal`.
|
|
112
|
-
* - Crypto: `CryptoKey`.
|
|
113
|
-
*/
|
|
114
|
-
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;
|
|
115
|
-
/** --------------------------------------------------
|
|
116
|
-
* * ***Utility Type: `IntlObjects`.***
|
|
117
|
-
* --------------------------------------------------
|
|
118
|
-
* **Represents all **ECMAScript Internationalization API** objects from `Intl`.**
|
|
119
|
-
* - ✅ ***Includes:***
|
|
120
|
-
* - `Intl.Collator`.
|
|
121
|
-
* - `Intl.DateTimeFormat`.
|
|
122
|
-
* - `Intl.NumberFormat`.
|
|
123
|
-
* - `Intl.RelativeTimeFormat`.
|
|
124
|
-
* - `Intl.PluralRules`.
|
|
125
|
-
* - `Intl.ListFormat`.
|
|
126
|
-
* - `Intl.Locale`.
|
|
127
|
-
*/
|
|
128
|
-
type IntlObjects=Intl.Collator|Intl.DateTimeFormat|Intl.NumberFormat|Intl.RelativeTimeFormat|Intl.PluralRules|Intl.ListFormat|Intl.Locale;
|
|
129
|
-
/** --------------------------------------------------
|
|
130
|
-
* * ***Utility Type: `BoxedPrimitivesTypes`.***
|
|
131
|
-
* --------------------------------------------------
|
|
132
|
-
* **Represents JavaScript **boxed primitive objects** (object wrappers for primitive values).**
|
|
133
|
-
* @description
|
|
134
|
-
* Boxed primitives are created using the `new` keyword on primitive wrapper constructors.
|
|
135
|
-
* - ✅ ***Includes (object wrappers):***
|
|
136
|
-
* - `new Number(123)` ➔ `Number`.
|
|
137
|
-
* - `new String("hello")` ➔ `String`.
|
|
138
|
-
* - `new Boolean(true)` ➔ `Boolean`.
|
|
139
|
-
* - ❌ ***Excludes (primitive values):***
|
|
140
|
-
* - `123` ➔ `number`.
|
|
141
|
-
* - `"hello"` ➔ `string`.
|
|
142
|
-
* - `true` ➔ `boolean`.
|
|
143
|
-
* - ℹ️ ***Note:***
|
|
144
|
-
* - These are **rarely used directly** in modern **JavaScript/TypeScript**.
|
|
145
|
-
* - However, they exist for completeness and are sometimes relevant
|
|
146
|
-
* when distinguishing between **primitive values** and **object wrappers**.
|
|
147
|
-
* @example
|
|
148
|
-
* ```ts
|
|
149
|
-
* const a: BoxedPrimitivesTypes = new Number(123);
|
|
150
|
-
* // ➔ ✅ valid
|
|
151
|
-
* const b: BoxedPrimitivesTypes = new String("abc");
|
|
152
|
-
* // ➔ ✅ valid
|
|
153
|
-
* const c: BoxedPrimitivesTypes = new Boolean(false);
|
|
154
|
-
* // ➔ ✅ valid
|
|
155
|
-
*
|
|
156
|
-
* // ❌ Not allowed (primitive values):
|
|
157
|
-
* const x: BoxedPrimitivesTypes = 123;
|
|
158
|
-
* const y: BoxedPrimitivesTypes = "abc";
|
|
159
|
-
* const z: BoxedPrimitivesTypes = true;
|
|
160
|
-
* ```
|
|
161
|
-
*/
|
|
162
|
-
type BoxedPrimitivesTypes=Number|String|Boolean;
|
|
163
|
-
/** --------------------------------------------------
|
|
164
|
-
* * ***Utility Type: `NonPlainObject`.***
|
|
165
|
-
* --------------------------------------------------
|
|
166
|
-
* **Represents all known **non-plain object types**,
|
|
167
|
-
* i.e., values that are **not** considered a `"plain object"` (`{ [key: string]: any }`).**
|
|
168
|
-
* - ✅ ***Includes:***
|
|
169
|
-
* - **Functions**.
|
|
170
|
-
* - **Arrays**.
|
|
171
|
-
* - **Native objects:** `Date`, `RegExp`, `Map`, `Set`, `WeakMap`, `WeakSet`.
|
|
172
|
-
* - **Built-in classes & APIs:** `Promise`, `Error`, `ArrayBuffer`, `DataView`.
|
|
173
|
-
* - **Typed arrays:** `TypedArray`.
|
|
174
|
-
* - **Browser & Node APIs:** `WebApiObjects`, `IntlObjects`, `NodeBuiltins`.
|
|
175
|
-
* - **Symbols**.
|
|
176
|
-
* - **Proxies** (wrapping any object).
|
|
177
|
-
* - The global **`Reflect`** object.
|
|
178
|
-
* - ❌ ***Excludes:***
|
|
179
|
-
* - Plain objects (`{ foo: string }`, `Record<string, any>`), `null` and `undefined`.
|
|
180
|
-
* - ℹ️ ***Note:***
|
|
181
|
-
* - Use this type when you need to differentiate **plain objects** from **all other object-like values**.
|
|
182
|
-
* @example
|
|
183
|
-
* ```ts
|
|
184
|
-
* type A = NonPlainObject;
|
|
185
|
-
*
|
|
186
|
-
* const x: A = new Date();
|
|
187
|
-
* // ➔ ✅ Allowed
|
|
188
|
-
* const y: A = [1, 2, 3];
|
|
189
|
-
* // ➔ ✅ Allowed
|
|
190
|
-
* const z: A = Promise.resolve(123);
|
|
191
|
-
* // ➔ ✅ Allowed
|
|
192
|
-
*
|
|
193
|
-
* // ❌ Not allowed (plain object):
|
|
194
|
-
* // const bad: A = { foo: "bar" };
|
|
195
|
-
* ```
|
|
196
|
-
*/
|
|
197
|
-
type NonPlainObject=BoxedPrimitivesTypes|AnyFunction|Promise<any>|Array<any>|AnObjectNonArray;
|
|
198
|
-
/** --------------------------------------------------
|
|
199
|
-
* * ***Utility Type: `AnObjectNonArray`.***
|
|
200
|
-
* --------------------------------------------------
|
|
201
|
-
* **Represents all **non-null, non-array, object-like values** in JavaScript/Node.js.**
|
|
202
|
-
* - ✅ ***Includes:***
|
|
203
|
-
* - **Built-in objects:** `Date`, `RegExp`, `Error`, `ArrayBuffer`, `DataView`.
|
|
204
|
-
* - **Collections:** `Map`, `Set`, `WeakMap`, `WeakSet`.
|
|
205
|
-
* - **Typed arrays:**
|
|
206
|
-
* `Int8Array`, `Uint8Array`, `Uint8ClampedArray`,
|
|
207
|
-
* `Int16Array`, `Uint16Array`,
|
|
208
|
-
* `Int32Array`, `Uint32Array`,
|
|
209
|
-
* `Float32Array`, `Float64Array`,
|
|
210
|
-
* `BigInt64Array`, `BigUint64Array`.
|
|
211
|
-
* - **Browser Web APIs:**
|
|
212
|
-
* `URL`, `URLSearchParams`, `FormData`, `Headers`, `Response`, `Request`,
|
|
213
|
-
* `ReadableStream`, `WritableStream`, `TransformStream`,
|
|
214
|
-
* `MessageChannel`, `MessagePort`, `MessageEvent`,
|
|
215
|
-
* `Event`, `CustomEvent`, `HTMLElement`, `Node`, `Document`, `Window`,
|
|
216
|
-
* `CanvasRenderingContext2D`,
|
|
217
|
-
* `AbortController`, `AbortSignal`,
|
|
218
|
-
* `TextEncoder`, `TextDecoder`,
|
|
219
|
-
* `CryptoKey`, `File`, `FileList`, `ImageBitmap`, `WebSocket`.
|
|
220
|
-
* - **ECMAScript Internationalization API objects:**
|
|
221
|
-
* `Intl.Collator`, `Intl.DateTimeFormat`, `Intl.NumberFormat`,
|
|
222
|
-
* `Intl.RelativeTimeFormat`, `Intl.PluralRules`,
|
|
223
|
-
* `Intl.ListFormat`, `Intl.Locale`.
|
|
224
|
-
* - **Node.js built-ins:** `Buffer`.
|
|
225
|
-
* - **Symbols**.
|
|
226
|
-
* - **Proxies** (wrapping any object).
|
|
227
|
-
* - The global **`Reflect`** object.
|
|
228
|
-
* - ❌ ***Excludes:***
|
|
229
|
-
* - `null`.
|
|
230
|
-
* - Arrays (`[]`, `new Array()`).
|
|
231
|
-
* - ℹ️ ***Note:***
|
|
232
|
-
* - Use this type when you need to represent **any object-like value except arrays and `null`**.
|
|
233
|
-
* @example
|
|
234
|
-
* ```ts
|
|
235
|
-
* const a: AnObjectNonArray = new Date();
|
|
236
|
-
* const b: AnObjectNonArray = new Map();
|
|
237
|
-
* const c: AnObjectNonArray = Symbol("id");
|
|
238
|
-
*
|
|
239
|
-
* // ❌ These are NOT allowed:
|
|
240
|
-
* // const x: AnObjectNonArray = null;
|
|
241
|
-
* // const y: AnObjectNonArray = [];
|
|
242
|
-
* ```
|
|
243
|
-
*/
|
|
244
|
-
type AnObjectNonArray=Date|RegExp|Map<any,any>|Set<any>|WeakMap<any,any>|WeakSet<any>|Error|ArrayBuffer|DataView|TypedArray|WebApiObjects|IntlObjects|NodeBuiltins|symbol|{[Symbol.toStringTag]:"Proxy";}|typeof Reflect;
|
|
245
|
-
/** -------------------------------------------------------
|
|
246
|
-
* * ***Utility Type: `IsArrayOrTuple`.***
|
|
247
|
-
* -------------------------------------------------------
|
|
248
|
-
* **Checks if a given type `T` is an array or tuple type.**
|
|
249
|
-
* - This includes both mutable (`T[]`) and readonly (`readonly T[]`) arrays.
|
|
250
|
-
* @template T - The type to check.
|
|
251
|
-
* @example
|
|
252
|
-
* type A = IsArrayOrTuple<string[]>;
|
|
253
|
-
* // ➔ true
|
|
254
|
-
* type B = IsArrayOrTuple<readonly [string, number]>;
|
|
255
|
-
* // ➔ true
|
|
256
|
-
* type C = IsArrayOrTuple<string>; // ➔ false
|
|
257
|
-
*/
|
|
258
|
-
type IsArrayOrTuple<T>=T extends readonly any[]?true:false;
|
|
259
|
-
/** -------------------------------------------------------
|
|
260
|
-
* * ***Utility Type: `IsConstructor`.***
|
|
261
|
-
* -------------------------------------------------------
|
|
262
|
-
* **Checks if a given type `T` is a constructor type (`new () => any`).**
|
|
263
|
-
* @template T - The type to check.
|
|
264
|
-
* @returns `true` if `T` is a constructor, otherwise `false`.
|
|
265
|
-
* @example
|
|
266
|
-
* class MyClass {}
|
|
267
|
-
* type A = IsConstructor<typeof MyClass>;
|
|
268
|
-
* // ➔ true
|
|
269
|
-
* type B = IsConstructor<() => void>;
|
|
270
|
-
* // ➔ false
|
|
271
|
-
*/
|
|
272
|
-
type IsConstructor<T>=T extends abstract new(...args:any[])=>any?true:false;
|
|
273
|
-
/** -------------------------------------------------------
|
|
274
|
-
* * ***Utility Type: `IsFunction`.***
|
|
275
|
-
* -------------------------------------------------------
|
|
276
|
-
* **Checks if a given type `T` is a callable function type.**
|
|
277
|
-
* @template T - The type to check.
|
|
278
|
-
* @example
|
|
279
|
-
* type A = IsFunction<() => void>; // ➔ true
|
|
280
|
-
* type B = IsFunction<string>; // ➔ false
|
|
281
|
-
*/
|
|
282
|
-
type IsFunction<T>=T extends AnyFunction?true:false;
|
|
283
|
-
/** -------------------------------------------------------
|
|
284
|
-
* * ***Utility Type: `Primitive`.***
|
|
285
|
-
* -------------------------------------------------------
|
|
286
|
-
* **Represents **all primitive types in JavaScript/TypeScript**,
|
|
287
|
-
* including their literal variants.**
|
|
288
|
-
* - **This type matches:**
|
|
289
|
-
* - Core primitive types:
|
|
290
|
-
* - `string`, `number`, `boolean`, `bigint`, `symbol`, `null`, `undefined`.
|
|
291
|
-
* - Literal counterparts:
|
|
292
|
-
* - `"foo"`, `42`, `true`, etc.
|
|
293
|
-
* - ⚠️ ***Note:***
|
|
294
|
-
* - Unlike some definitions, this does **not** include `void` or `never`,
|
|
295
|
-
* since they are TypeScript-specific keywords, not runtime primitives.
|
|
296
|
-
* @example
|
|
297
|
-
* ```ts
|
|
298
|
-
* type A = Primitive;
|
|
299
|
-
* // ➔ any strict primitive type
|
|
300
|
-
* type B = "hello" extends Primitive ? true : false;
|
|
301
|
-
* // ➔ true
|
|
302
|
-
* type C = void extends Primitive ? true : false;
|
|
303
|
-
* // ➔ false
|
|
304
|
-
* ```
|
|
305
|
-
*/
|
|
306
|
-
type Primitive=string|number|bigint|boolean|symbol|null|undefined;
|
|
307
|
-
/** -------------------------------------------------------
|
|
308
|
-
* * ***Utility Type: `IsPrimitive`.***
|
|
309
|
-
* -------------------------------------------------------
|
|
310
|
-
* **Checks if a given type `T` is a **strict primitive type** in JavaScript/TypeScript,
|
|
311
|
-
* including literal variants.**
|
|
312
|
-
* - **Behavior:**
|
|
313
|
-
* - ***Includes:***
|
|
314
|
-
* - `string`, `number`, `bigint`, `boolean`, `symbol`, `null`, `undefined`.
|
|
315
|
-
* - Literal types like: `"foo"`, `42`, `true`.
|
|
316
|
-
* - ***Excludes:***
|
|
317
|
-
* - `void` (absence of value).
|
|
318
|
-
* - `never` (impossible type).
|
|
319
|
-
* - `object`, `unknown`, `Date`, `arrays`, `functions`, etc.
|
|
320
|
-
* @template T - The type to check
|
|
321
|
-
* @example
|
|
322
|
-
* ```ts
|
|
323
|
-
* type A = IsPrimitive<"foo">; // ➔ true
|
|
324
|
-
* type B = IsPrimitive<null>; // ➔ true
|
|
325
|
-
* type C = IsPrimitive<number>; // ➔ true
|
|
326
|
-
* type D = IsPrimitive<undefined>; // ➔ true
|
|
327
|
-
* type E = IsPrimitive<{}>; // ➔ false
|
|
328
|
-
* type F = IsPrimitive<void>; // ➔ false
|
|
329
|
-
* type G = IsPrimitive<never>; // ➔ false
|
|
330
|
-
* type H = IsPrimitive<unknown>; // ➔ false
|
|
331
|
-
* type I = IsPrimitive<object>; // ➔ false
|
|
332
|
-
* type J = IsPrimitive<Date>; // ➔ false
|
|
333
|
-
* type K = IsPrimitive<[]>; // ➔ false
|
|
334
|
-
* type L = IsPrimitive<() => void>; // ➔ false
|
|
335
|
-
* ```
|
|
336
|
-
*/
|
|
337
|
-
type IsPrimitive<T>=IsNever<T>extends true?false:T extends Primitive?true:false;
|
|
338
|
-
/** -------------------------------------------------------
|
|
339
|
-
* * ***Utility Type: `IsRealPrimitive`.***
|
|
340
|
-
* -------------------------------------------------------
|
|
341
|
-
* **Checks if a given type `T` is a **real primitive type** in JavaScript/TypeScript,
|
|
342
|
-
* based on runtime behavior, **excluding `null`** but including `undefined`.**
|
|
343
|
-
* - **Behavior:**
|
|
344
|
-
* - ***Includes:***
|
|
345
|
-
* - `string`, `number`, `bigint`, `boolean`, `symbol`, `undefined`.
|
|
346
|
-
* - Literal types like: `"foo"`, `42`, `true`.
|
|
347
|
-
* - ***Excludes:***
|
|
348
|
-
* - `null`.
|
|
349
|
-
* - `never` (impossible type).
|
|
350
|
-
* - Objects, arrays, functions, `Date`, `unknown`, etc.
|
|
351
|
-
* - ⚠️ ***Note:***
|
|
352
|
-
* - This aligns with runtime `typeof` checks in JS:
|
|
353
|
-
* - `typeof null === "object"`,
|
|
354
|
-
* so `null` is excluded from **“real primitives”**.
|
|
355
|
-
* @template T - The type to check.
|
|
356
|
-
* @example
|
|
357
|
-
* ```ts
|
|
358
|
-
* type A = IsRealPrimitive<42>; // ➔ true
|
|
359
|
-
* type B = IsRealPrimitive<string>; // ➔ true
|
|
360
|
-
* type C = IsRealPrimitive<boolean>; // ➔ true
|
|
361
|
-
* type D = IsRealPrimitive<undefined>; // ➔ true
|
|
362
|
-
* type E = IsRealPrimitive<{}>; // ➔ false
|
|
363
|
-
* type F = IsRealPrimitive<[]>; // ➔ false
|
|
364
|
-
* type G = IsRealPrimitive<null>; // ➔ false
|
|
365
|
-
* type H = IsRealPrimitive<Date>; // ➔ false
|
|
366
|
-
* type I = IsRealPrimitive<() => void>; // ➔ false
|
|
367
|
-
* ```
|
|
368
|
-
*/
|
|
369
|
-
type IsRealPrimitive<T>=T extends Exclude<Primitive,null>?true:false;
|
|
370
|
-
/** * Applies readonly behavior according to mode. */
|
|
371
|
-
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];};
|
|
372
|
-
/** ---------------------------------------------------------------------------
|
|
373
|
-
* * ***Options for {@link Prettify|`Prettify`}.***
|
|
374
|
-
* ---------------------------------------------------------------------------
|
|
375
|
-
* **Options for customizing the behavior of the {@link Prettify | **`Prettify`**} type utility.**
|
|
376
|
-
*/
|
|
377
|
-
type PrettifyOptions={
|
|
378
|
-
/** -------------------------------------------------------
|
|
379
|
-
* * ***recursive***
|
|
380
|
-
* -------------------------------------------------------
|
|
381
|
-
* **Enables **deep prettification** of types when set to `true`.**
|
|
382
|
-
* @description
|
|
383
|
-
* By default (`false`), {@link Prettify | **`Prettify`**} only flattens the **top-level shape**
|
|
384
|
-
* of objects and intersections. Nested objects, arrays, and tuples remain as-is
|
|
385
|
-
* unless this option is enabled.
|
|
386
|
-
* - ***Behavior when `true`:***
|
|
387
|
-
* - **Plain objects**: Nested intersections are expanded recursively.
|
|
388
|
-
* - **Arrays & tuples**: Each element type is recursively prettified.
|
|
389
|
-
* - **Readonly handling**: Nested properties respect the `readonlyMode` option.
|
|
390
|
-
* - **Functions, constructors, and built-in objects** (Set, Map, Date, Promise, etc.)
|
|
391
|
-
* are **not** affected or expanded.
|
|
392
|
-
* - **Nested intersections**: Combined properties are flattened recursively.
|
|
393
|
-
* - ⚠️ ***Notes:***
|
|
394
|
-
* - Recursive mode only applies to **plain objects**, **arrays**, and **tuples**.
|
|
395
|
-
* - Readonly modifiers on nested properties follow the `readonlyMode` rules:
|
|
396
|
-
* - `"auto"` ➔ keep as-is
|
|
397
|
-
* - `"remove"` ➔ strip readonly
|
|
398
|
-
* - `"preserve"` ➔ make readonly
|
|
399
|
-
* - Arrays and tuples maintain `readonly` if the original type is `readonly` and `readonlyMode` is `"auto"` or `"preserve"`.
|
|
400
|
-
* @default false
|
|
401
|
-
* @example
|
|
402
|
-
* ```ts
|
|
403
|
-
* type Nested = {
|
|
404
|
-
* a: {
|
|
405
|
-
* readonly b: { c: number } & { d: string }
|
|
406
|
-
* } & { e: boolean };
|
|
407
|
-
* list: readonly ({ id: number } & { name: string })[];
|
|
408
|
-
* set: Set<{ x: number } & { y: string }>;
|
|
409
|
-
* };
|
|
410
|
-
*
|
|
411
|
-
* // Top-level only (default)
|
|
412
|
-
* type Shallow = Prettify<Nested>;
|
|
413
|
-
* // ➔ {
|
|
414
|
-
* // a: { readonly b: { c: number } & { d: string } } & { e: boolean };
|
|
415
|
-
* // list: readonly ({ id: number } & { name: string })[];
|
|
416
|
-
* // set: Set<{ x: number } & { y: string }>;
|
|
417
|
-
* // }
|
|
418
|
-
*
|
|
419
|
-
* // Fully recursive flatten
|
|
420
|
-
* type Deep = Prettify<Nested, { recursive: true }>;
|
|
421
|
-
* // ➔ {
|
|
422
|
-
* // a: { readonly b: { c: number; d: string }; e: boolean };
|
|
423
|
-
* // list: readonly { id: number; name: string }[];
|
|
424
|
-
* // set: Set<{ x: number } & { y: string }>; // built-in ignored
|
|
425
|
-
* // }
|
|
426
|
-
* ```
|
|
427
|
-
*/
|
|
428
|
-
recursive?:boolean;
|
|
429
|
-
/** -------------------------------------------------------
|
|
430
|
-
* * ***readonlyMode***
|
|
431
|
-
* -------------------------------------------------------
|
|
432
|
-
* **Determines how `readonly` modifiers are applied to properties
|
|
433
|
-
* when using {@link Prettify}.**
|
|
434
|
-
* - **Modes:**
|
|
435
|
-
* - `"auto"` ➔ Keep `readonly` exactly as in the original type (default).
|
|
436
|
-
* - `"remove"` ➔ Remove all `readonly` modifiers.
|
|
437
|
-
* - `"preserve"` ➔ Make all properties `readonly`.
|
|
438
|
-
* - **Behavior:**
|
|
439
|
-
* - Applies to both **top-level** and **nested properties** (if `recursive` is `true`).
|
|
440
|
-
* - Arrays and tuples preserve or adjust `readonly` according to the selected mode:
|
|
441
|
-
* - `"auto"` ➔ preserve array/tuple readonly as-is.
|
|
442
|
-
* - `"remove"` ➔ array/tuple becomes mutable.
|
|
443
|
-
* - `"preserve"` ➔ array/tuple becomes readonly.
|
|
444
|
-
* - Functions, constructors, and built-in objects (Set, Map, Date, Promise, etc.) are **not affected**.
|
|
445
|
-
* - Nested intersections respect `readonlyMode` recursively if `recursive` is enabled.
|
|
446
|
-
* - ⚠️ ***Notes:***
|
|
447
|
-
* - For nested objects, `readonly` behavior only changes if `recursive: true`.
|
|
448
|
-
* - `readonlyMode` does **not** override `readonly` on function parameters, methods, or constructors.
|
|
449
|
-
* @default "auto"
|
|
450
|
-
* @example
|
|
451
|
-
* ```ts
|
|
452
|
-
* type T = { readonly a: number; b: string };
|
|
453
|
-
*
|
|
454
|
-
* // Default: auto
|
|
455
|
-
* type Auto = Prettify<T, { readonlyMode: "auto" }>;
|
|
456
|
-
* // ➔ { readonly a: number; b: string }
|
|
457
|
-
*
|
|
458
|
-
* // Remove readonly
|
|
459
|
-
* type Remove = Prettify<T, { readonlyMode: "remove" }>;
|
|
460
|
-
* // ➔ { a: number; b: string }
|
|
461
|
-
*
|
|
462
|
-
* // Force all readonly
|
|
463
|
-
* type Preserve = Prettify<T, { readonlyMode: "preserve" }>;
|
|
464
|
-
* // ➔ { readonly a: number; readonly b: string }
|
|
465
|
-
*
|
|
466
|
-
* // Recursive + preserve
|
|
467
|
-
* type Nested = {
|
|
468
|
-
* config: { readonly port: number } & { host: string }
|
|
469
|
-
* };
|
|
470
|
-
* type RecursivePreserve = Prettify<Nested, { recursive: true; readonlyMode: "preserve" }>;
|
|
471
|
-
* // ➔ { readonly config: { readonly port: number; readonly host: string } }
|
|
472
|
-
* ```
|
|
473
|
-
*/
|
|
474
|
-
readonlyMode?:Extract<"auto"|"remove"|"preserve",string>;};
|
|
475
|
-
/** -------------------------------------------------------
|
|
476
|
-
* * ***DefaultPrettifyOptions***
|
|
477
|
-
* -------------------------------------------------------
|
|
478
|
-
* **Default options {@link Prettify | **`Prettify`**} used when no custom options are provided.**
|
|
479
|
-
*/
|
|
480
|
-
type DefaultPrettifyOptions={recursive:false;readonlyMode:"auto";};type MergeReadonlyIntersection<T>=T extends readonly any[]?T:T extends object?{[K in keyof T]:T[K];}:T;
|
|
481
|
-
/** -------------------------------------------------------
|
|
482
|
-
* * ***Utility Type: `Prettify`.***
|
|
483
|
-
* -------------------------------------------------------
|
|
484
|
-
* **Flattens and simplifies complex TypeScript types into a more
|
|
485
|
-
* human-readable form, by forcing the compiler to expand intersections.**
|
|
486
|
-
* @description
|
|
487
|
-
* By default, only the **top-level shape** of an object is flattened.
|
|
488
|
-
* To also prettify **nested objects**, set the `recursive` option.
|
|
489
|
-
* - ⚠️ ***Note:***
|
|
490
|
-
* - `recursive: true` only affects **plain objects** and **arrays/tuples**.
|
|
491
|
-
* - Built-in objects like `Set`, `Map`, `Date`, `Promise`, etc.
|
|
492
|
-
* will **not** be recursively prettified.
|
|
493
|
-
* - `readonly` handling is controlled via the `readonlyMode` option.
|
|
494
|
-
* - **ℹ️ Options:**
|
|
495
|
-
* - `recursive?: boolean` (default: `false`):
|
|
496
|
-
* - Whether to recursively expand nested objects and intersections.
|
|
497
|
-
* - `readonlyMode?: "auto" | "remove" | "preserve"` (default: `"auto"`):
|
|
498
|
-
* - How `readonly` modifiers are treated:
|
|
499
|
-
* - `"auto"` ➔ preserve `readonly` as-is (**default**).
|
|
500
|
-
* - `"remove"` ➔ strip all `readonly`.
|
|
501
|
-
* - `"preserve"` ➔ enforce `readonly` everywhere.
|
|
502
|
-
* @template T - The type to prettify.
|
|
503
|
-
* @template Options - Configuration options.
|
|
504
|
-
* @example
|
|
505
|
-
* ```ts
|
|
506
|
-
* // --- Top-level only (default) ---
|
|
507
|
-
* type T0 = Prettify<{ a: number } & { b: string }>;
|
|
508
|
-
* // ➔ { a: number; b: string }
|
|
509
|
-
*
|
|
510
|
-
* // --- Recursive expansion of nested objects ---
|
|
511
|
-
* type T1 = Prettify<
|
|
512
|
-
* { a: { x: number } & { y: string } } & { b: boolean },
|
|
513
|
-
* { recursive: true }
|
|
514
|
-
* >;
|
|
515
|
-
* // ➔ { a: { x: number; y: string }; b: boolean }
|
|
516
|
-
*
|
|
517
|
-
* // --- Readonly handling modes ---
|
|
518
|
-
* type T2 = { readonly id: number; name: string };
|
|
519
|
-
*
|
|
520
|
-
* type R1 = Prettify<T2>;
|
|
521
|
-
* // (default: readonlyMode = "auto")
|
|
522
|
-
* // ➔ { readonly id: number; name: string }
|
|
523
|
-
*
|
|
524
|
-
* type R2 = Prettify<T2, { readonlyMode: "remove" }>;
|
|
525
|
-
* // ➔ { id: number; name: string }
|
|
526
|
-
*
|
|
527
|
-
* type R3 = Prettify<T2, { readonlyMode: "preserve" }>;
|
|
528
|
-
* // ➔ { readonly id: number; readonly name: string }
|
|
529
|
-
*
|
|
530
|
-
* // --- Readonly + mutable intersection ---
|
|
531
|
-
* type T3 = Prettify<{ readonly a: number } & { a: number; b: boolean }>;
|
|
532
|
-
* // ➔ { a: number; b: boolean }
|
|
533
|
-
* // (in "auto" mode, readonly lose over mutable)
|
|
534
|
-
*
|
|
535
|
-
* // --- Nested readonly with recursive ---
|
|
536
|
-
* type T4 = Prettify<
|
|
537
|
-
* { config: { readonly port: number } & { host: string } },
|
|
538
|
-
* { recursive: true }
|
|
539
|
-
* >;
|
|
540
|
-
* // ➔ { config: { readonly port: number; host: string } }
|
|
541
|
-
*
|
|
542
|
-
* // --- Arrays with readonly ---
|
|
543
|
-
* type T5 = Prettify<
|
|
544
|
-
* { list: readonly ({ id: number } & { name: string })[] },
|
|
545
|
-
* { recursive: true }
|
|
546
|
-
* >;
|
|
547
|
-
* // (readonly on array is preserved in "auto" mode)
|
|
548
|
-
* // ➔ { list: readonly { id: number; name: string }[] }
|
|
549
|
-
*
|
|
550
|
-
* type T6 = Prettify<
|
|
551
|
-
* { list: readonly ({ id: number } & { name: string })[] },
|
|
552
|
-
* { recursive: true; readonlyMode: "remove" }
|
|
553
|
-
* >;
|
|
554
|
-
* // ➔ { list: { id: number; name: string }[] }
|
|
555
|
-
*
|
|
556
|
-
* // --- Built-in objects are ignored (not expanded) ---
|
|
557
|
-
* type T7 = Prettify<
|
|
558
|
-
* { s: Set<{ a: number } & { b: string }> },
|
|
559
|
-
* { recursive: true }
|
|
560
|
-
* >;
|
|
561
|
-
* // ➔ { s: Set<{ a: number } & { b: string }> }
|
|
562
|
-
* ```
|
|
563
|
-
*/
|
|
564
|
-
type Prettify<T,Options extends PrettifyOptions=DefaultPrettifyOptions>=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;export type{AnyFunction as A,BoxedPrimitivesTypes as B,DefaultPrettifyOptions as D,IsArrayOrTuple as I,NonPlainObject as N,Prettify as P,TypedArray as T,WebApiObjects as W,PrettifyOptions as a,IsConstructor as b,IsFunction as c,IsPrimitive as d,IsRealPrimitive as e,Primitive as f,AnObjectNonArray as g,DataTypes as h,DeepReplaceType as i,IntlObjects as j};
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
/** --------------------------------------------------
|
|
2
|
-
* * ***Utility Type: `Awaitable`.***
|
|
3
|
-
* --------------------------------------------------
|
|
4
|
-
* **Represents a type that can be awaited:**
|
|
5
|
-
* - Either a plain value `T` or a `PromiseLike<T>`.
|
|
6
|
-
* @template T - The inner value type.
|
|
7
|
-
* @example
|
|
8
|
-
* ```ts
|
|
9
|
-
* async function wrap<T>(v: Awaitable<T>): Promise<T> {
|
|
10
|
-
* return await v;
|
|
11
|
-
* }
|
|
12
|
-
*
|
|
13
|
-
* const a = wrap(42); // Promise<number>
|
|
14
|
-
* const b = wrap(Promise.resolve("hi")); // Promise<string>
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
|
-
type Awaitable<T>=T|PromiseLike<T>;interface CustomPromiseLike<OnSuccess,OnError>{
|
|
18
|
-
/**
|
|
19
|
-
* Attaches callbacks for the resolution and/or rejection of the Promise.
|
|
20
|
-
* @param onfulfilled The callback to execute when the Promise is resolved.
|
|
21
|
-
* @param onrejected The callback to execute when the Promise is rejected.
|
|
22
|
-
* @returns A Promise for the completion of which ever callback is executed.
|
|
23
|
-
*/
|
|
24
|
-
then<TResult1=OnSuccess,TResult2=never>(onfulfilled?:((value:OnSuccess)=>TResult1|PromiseLike<TResult1>)|null|undefined,onrejected?:((reason:OnError)=>TResult2|PromiseLike<TResult2>)|null|undefined):CustomPromiseType<TResult1|TResult2,OnError>;
|
|
25
|
-
/**
|
|
26
|
-
* Attaches a callback for only the rejection of the Promise.
|
|
27
|
-
* @param onrejected The callback to execute when the Promise is rejected.
|
|
28
|
-
* @returns A Promise for the completion of the callback.
|
|
29
|
-
*/
|
|
30
|
-
catch<TResult=never>(onrejected?:((reason:OnError)=>TResult|PromiseLike<TResult>)|null|undefined):CustomPromiseType<OnSuccess|TResult,OnError>;
|
|
31
|
-
/**
|
|
32
|
-
* Registers a callback to be invoked **exactly once** when the
|
|
33
|
-
* promise settles, with access to both the resolved value and
|
|
34
|
-
* the rejection reason.
|
|
35
|
-
*
|
|
36
|
-
* If the promise is already settled when `finish` is called,
|
|
37
|
-
* the callback executes immediately on the same tick.
|
|
38
|
-
*
|
|
39
|
-
* @param cb Callback receiving the final `(value, error)`.
|
|
40
|
-
* @returns `this` for fluent chaining.
|
|
41
|
-
*/
|
|
42
|
-
finish(cb:(value:OnSuccess|undefined,error:OnError|undefined)=>void):CustomPromiseType<OnSuccess,OnError>;}
|
|
43
|
-
/** --------------------------------------------------
|
|
44
|
-
* * ***Utility Type: `CustomPromiseType`.***
|
|
45
|
-
* --------------------------------------------------
|
|
46
|
-
* **Extends the native `Promise` type to provide explicit typing
|
|
47
|
-
* for both the resolved (`onSuccess`) and rejected (`onError`) values,
|
|
48
|
-
* plus an optional `finish` hook.**
|
|
49
|
-
* - **Behavior:**
|
|
50
|
-
* - ✅ **Strongly types** `success`, `error`, and `finish` handlers.
|
|
51
|
-
* - ⚙️ `finish` runs exactly once after the promise settles (similar to `finish`).
|
|
52
|
-
* @template OnSuccess - The type of the fulfilled value.
|
|
53
|
-
* @template OnError - The type of the rejection reason, defaults to `unknown`.
|
|
54
|
-
* @example
|
|
55
|
-
* ```ts
|
|
56
|
-
* import type { CustomPromiseType } from "@rzl-zone/types";
|
|
57
|
-
* import { CustomsPromise } from "@rzl-zone/promises";
|
|
58
|
-
*
|
|
59
|
-
* const fetchUser = (): CustomPromiseType<User, ApiError> =>
|
|
60
|
-
* CustomsPromise<User, ApiError>((resolve, reject) => {
|
|
61
|
-
* apiCall().then(resolve).catch(reject);
|
|
62
|
-
* });
|
|
63
|
-
*
|
|
64
|
-
* fetchUser()
|
|
65
|
-
* .then(user => console.log(user))
|
|
66
|
-
* .catch(err => console.error(err))
|
|
67
|
-
* .finish((result, error) => {
|
|
68
|
-
* console.log("always runs", { result, error });
|
|
69
|
-
* });
|
|
70
|
-
* ```
|
|
71
|
-
*/
|
|
72
|
-
type CustomPromiseType<OnSuccess,OnError=unknown>=CustomPromiseLike<OnSuccess,OnError>;export type{Awaitable as A,CustomPromiseType as C};
|