@rzl-zone/utils-js 2.0.1 → 3.0.0-beta.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/dist/NumberRangeUnion-DC-C3_Kq.d.ts +26 -0
- package/dist/any-BmdI8UbK.d.ts +67 -0
- package/dist/array-CIZRbqTF.d.ts +223 -0
- package/dist/arrays-normalize-recursive-CnjYJ9xg.d.ts +72 -0
- package/dist/assertions/index.cjs +1 -0
- package/dist/assertions/index.d.ts +428 -0
- package/dist/assertions/index.js +1 -0
- package/dist/chunk-2TRAPBZ7.cjs +1 -0
- package/dist/chunk-3D74QO5D.cjs +1 -0
- package/dist/chunk-4DK3RCC4.js +2 -0
- package/dist/chunk-4JOQ45HL.js +1 -0
- package/dist/chunk-55CZALRS.js +1 -0
- package/dist/chunk-56QBKKRE.js +1 -0
- package/dist/chunk-5JFV3GDE.cjs +4 -0
- package/dist/chunk-5SZUSNGZ.js +1 -0
- package/dist/chunk-62HX5Z45.cjs +1 -0
- package/dist/chunk-7NA6DUHR.cjs +2 -0
- package/dist/chunk-7YWAQOA4.cjs +1 -0
- package/dist/chunk-BVPMMWDL.cjs +1 -0
- package/dist/chunk-BYZAD3XN.cjs +1 -0
- package/dist/chunk-CEFYHEM4.cjs +1 -0
- package/dist/chunk-CN53M4QZ.cjs +1 -0
- package/dist/chunk-D47MHBSD.cjs +1 -0
- package/dist/chunk-DGH75GJD.js +1 -0
- package/dist/chunk-E5NUI7PN.js +1 -0
- package/dist/chunk-ELDDNERR.js +1 -0
- package/dist/chunk-EXZ47NOW.js +1 -0
- package/dist/chunk-FDITZ5C6.cjs +1 -0
- package/dist/chunk-FF76ISQ2.js +1 -0
- package/dist/chunk-FIEZKTAZ.cjs +1 -0
- package/dist/chunk-FSSV24W7.cjs +1 -0
- package/dist/chunk-G5LXIEFO.js +0 -0
- package/dist/chunk-GCGU2WB7.js +1 -0
- package/dist/chunk-GECI2YBP.js +1 -0
- package/dist/chunk-GQE4OVHC.cjs +1 -0
- package/dist/chunk-GRVZXQXL.cjs +1 -0
- package/dist/chunk-I4AVNHPA.cjs +1 -0
- package/dist/chunk-JFRL7NKU.js +4 -0
- package/dist/chunk-JWHM3WZQ.cjs +1 -0
- package/dist/chunk-KCQDDZJE.cjs +1 -0
- package/dist/chunk-L54ZPSYJ.js +1 -0
- package/dist/chunk-LVKAYEZ4.js +1 -0
- package/dist/chunk-MBDWTK54.cjs +1 -0
- package/dist/chunk-MMSYCIJ2.cjs +1 -0
- package/dist/chunk-MNGGDB2G.js +1 -0
- package/dist/chunk-MY7BA4GI.cjs +1 -0
- package/dist/chunk-N2IJPIND.cjs +1 -0
- package/dist/chunk-NIMNTEGV.js +1 -0
- package/dist/chunk-NNM7QCNB.js +1 -0
- package/dist/chunk-PUQXRLZH.cjs +1 -0
- package/dist/chunk-PVJF2JHM.js +1 -0
- package/dist/chunk-QCFXEUKL.js +1 -0
- package/dist/chunk-QFCGBBSY.js +1 -0
- package/dist/chunk-QQYAUPSK.cjs +1 -0
- package/dist/chunk-RN3TP3S3.js +1 -0
- package/dist/chunk-RV2VULM7.cjs +1 -0
- package/dist/chunk-SW6HYEW7.cjs +1 -0
- package/dist/chunk-SYJC7UAW.js +1 -0
- package/dist/chunk-TC4VBE4Y.cjs +1 -0
- package/dist/chunk-TUXDINHF.cjs +1 -0
- package/dist/chunk-U5Y2FXMN.cjs +1 -0
- package/dist/chunk-UUPQI6ND.cjs +1 -0
- package/dist/chunk-VYCGZ2S6.js +1 -0
- package/dist/chunk-W5EDKJK3.js +1 -0
- package/dist/chunk-WHAVUFEU.js +1 -0
- package/dist/chunk-XCFIOTCV.js +1 -0
- package/dist/chunk-XE27XPJR.js +1 -0
- package/dist/chunk-XH6MCRLP.js +1 -0
- package/dist/chunk-XVB3ZZEB.js +1 -0
- package/dist/chunk-ZBSIGJFO.cjs +1 -0
- package/dist/chunk-ZYAML74V.js +1 -0
- package/dist/conversions/index.cjs +1 -0
- package/dist/conversions/index.d.ts +1633 -0
- package/dist/conversions/index.js +1 -0
- package/dist/env/index.cjs +1 -0
- package/dist/env/index.d.ts +19 -0
- package/dist/env/index.js +1 -0
- package/dist/events/index.cjs +1 -0
- package/dist/events/index.d.ts +119 -0
- package/dist/events/index.js +1 -0
- package/dist/extends-Mp81Hq9-.d.ts +145 -0
- package/dist/formatting/index.cjs +1 -0
- package/dist/formatting/index.d.ts +912 -0
- package/dist/formatting/index.js +1 -0
- package/dist/generator/index.cjs +1 -0
- package/dist/generator/index.d.ts +163 -0
- package/dist/generator/index.js +1 -0
- package/dist/if-CvT4R7Kh.d.ts +18 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -4313
- package/dist/index.js +1 -1
- package/dist/is-array-Ckm_47hw.d.ts +1557 -0
- package/dist/isPlainObject-BKYaI6a8.d.ts +182 -0
- package/dist/never-BfayMBF9.d.ts +75 -0
- package/dist/next/index.cjs +8 -1
- package/dist/next/index.d.ts +169 -169
- package/dist/next/index.js +8 -1
- package/dist/next/server/index.cjs +2 -1
- package/dist/next/server/index.d.ts +37 -37
- package/dist/next/server/index.js +2 -1
- package/dist/nils-DMz3kU7M.d.ts +177 -0
- package/dist/omit-VvmIsZmX.d.ts +28 -0
- package/dist/operations/index.cjs +1 -0
- package/dist/operations/index.d.ts +182 -0
- package/dist/operations/index.js +1 -0
- package/dist/parsers/index.cjs +1 -0
- package/dist/parsers/index.d.ts +37 -0
- package/dist/parsers/index.js +1 -0
- package/dist/predicates/index.cjs +1 -0
- package/dist/predicates/index.d.ts +1839 -0
- package/dist/predicates/index.js +1 -0
- package/dist/prettify-C4xLcYOP.d.ts +353 -0
- package/dist/promise/index.cjs +1 -0
- package/dist/promise/index.d.ts +40 -0
- package/dist/promise/index.js +1 -0
- package/dist/rzl-utils.global.js +4 -1
- package/dist/strings/index.cjs +1 -0
- package/dist/strings/index.d.ts +816 -0
- package/dist/strings/index.js +1 -0
- package/dist/stylings/index.cjs +1 -0
- package/dist/stylings/index.d.ts +49 -0
- package/dist/stylings/index.js +1 -0
- package/dist/type-data-DDs-u2kq.d.ts +261 -0
- package/dist/types/index.d.ts +3589 -2090
- package/dist/urls/index.cjs +1 -0
- package/dist/urls/index.d.ts +418 -0
- package/dist/urls/index.js +1 -0
- package/package.json +147 -21
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
type Enumerate<N extends number,Acc extends number[]=[]>=Acc["length"] extends N?Acc[number]:Enumerate<N,[...Acc,Acc["length"]]>;
|
|
2
|
+
/** --------------------------------------------------
|
|
3
|
+
* * ***Generate a union type of numbers from `From` to `To` using enumeration.***
|
|
4
|
+
* --------------------------------------------------
|
|
5
|
+
*
|
|
6
|
+
* @template From - Starting number of the range (inclusive).
|
|
7
|
+
* @template To - Ending number of the range (inclusive).
|
|
8
|
+
*
|
|
9
|
+
* @description
|
|
10
|
+
* Produces a **numeric union type** from `From` to `To` (inclusive),
|
|
11
|
+
* using a simpler approach based on `Enumerate<N>` helper type.
|
|
12
|
+
*
|
|
13
|
+
* - ✅ Straightforward & easy to reason about.
|
|
14
|
+
* - ⚠️ Still limited by TypeScript recursion depth (safe up to `999`).
|
|
15
|
+
* - ⚙️ Best used for **smaller ranges** or when readability matters.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* type RangeX = NumberRangeUnion<3, 6>;
|
|
20
|
+
* // ^? 3 | 4 | 5 | 6
|
|
21
|
+
*
|
|
22
|
+
* type RangeY = NumberRangeUnion<0, 2>;
|
|
23
|
+
* // ^? 0 | 1 | 2
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
type NumberRangeUnion<From extends number,To extends number>=From extends To?From:Exclude<Enumerate<To>,Enumerate<From>>extends never?never:Exclude<Enumerate<To>,Enumerate<From>>|To;export type{NumberRangeUnion as N};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import{I as If}from'./if-CvT4R7Kh.js';
|
|
2
|
+
/** -------------------------------------------------------
|
|
3
|
+
* * ***IsAny.***
|
|
4
|
+
* -------------------------------------------------------
|
|
5
|
+
* A type-level utility that checks whether a type is ***`any`***.
|
|
6
|
+
* - Returns `true` if `T` is `any`.
|
|
7
|
+
* - Returns `false` otherwise.
|
|
8
|
+
*
|
|
9
|
+
* @template T - The type to evaluate.
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* type A = IsAny<any>; // ➔ true
|
|
13
|
+
* type B = IsAny<string>; // ➔ false
|
|
14
|
+
* type C = IsAny<unknown>; // ➔ false
|
|
15
|
+
* type D = IsAny<never>; // ➔ false
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
type IsAny<T>=0 extends 1 & T?true:false;
|
|
19
|
+
/** -------------------------------------------------------
|
|
20
|
+
* * ***IfAny.***
|
|
21
|
+
* -------------------------------------------------------
|
|
22
|
+
*
|
|
23
|
+
* A type-level conditional utility that returns one type if ***`T` is `any`***,
|
|
24
|
+
* and another type otherwise.
|
|
25
|
+
* - Defaults to `true` when `T` is `any`.
|
|
26
|
+
* - Defaults to `false` otherwise.
|
|
27
|
+
*
|
|
28
|
+
* @template T - The type to check.
|
|
29
|
+
* @template IfTrue - The type to return if `T` is `any`. *(default: `true`)*
|
|
30
|
+
* @template IfFalse - The type to return if `T` is not `any`. *(default: `false`)*
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* type A = IfAny<any, string, number>;
|
|
35
|
+
* // ➔ string
|
|
36
|
+
* type B = IfAny<string, string, number>;
|
|
37
|
+
* // ➔ number
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
type IfAny<T,IfTrue=true,IfFalse=false>=If<IsAny<T>,IfTrue,IfFalse>;
|
|
41
|
+
/** Configuration options for a type-level utility `AnifyProperties`. */
|
|
42
|
+
type AnifyPropertiesOptions={
|
|
43
|
+
/** If `makeOptional: true`, all properties become optional, otherwise, all properties are required and typed as `any`, defaultValue: `false`.
|
|
44
|
+
*
|
|
45
|
+
* @default false
|
|
46
|
+
*/
|
|
47
|
+
makeOptional:boolean;};
|
|
48
|
+
/** -------------------------------------------------------
|
|
49
|
+
* * ***AnifyProperties.***
|
|
50
|
+
* -------------------------------------------------------
|
|
51
|
+
*
|
|
52
|
+
* A type-level utility that transforms all properties of an object into ***`any`***.
|
|
53
|
+
* - If `makeOptional: true`, all properties become optional.
|
|
54
|
+
* - Otherwise, all properties are required and typed as `any`.
|
|
55
|
+
*
|
|
56
|
+
* @template T - The object type to transform.
|
|
57
|
+
* @template Options - Configuration options. Defaults to `{ makeOptional: false }`.
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* type A = AnifyProperties<{a: string; b: number}>;
|
|
61
|
+
* // ➔ { a: any; b: any }
|
|
62
|
+
*
|
|
63
|
+
* type B = AnifyProperties<{a: string; b: number}, { makeOptional: true }>;
|
|
64
|
+
* // ➔ { a?: any; b?: any }
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
type AnifyProperties<T extends object,Options extends AnifyPropertiesOptions={makeOptional:false;}>={[K in keyof T]:any;}extends infer Result?If<Options["makeOptional"],Partial<Result>,Result>:never;export type{AnifyProperties as A,IsAny as I,AnifyPropertiesOptions as a,IfAny as b};
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import{I as If}from'./if-CvT4R7Kh.js';import{I as IsNever}from'./never-BfayMBF9.js';
|
|
2
|
+
/** -------------------------------------------------------
|
|
3
|
+
* * ***Arrayable.***
|
|
4
|
+
* -------------------------------------------------------
|
|
5
|
+
* Represents a type that can be either:
|
|
6
|
+
* - a single value of type `T`, or
|
|
7
|
+
* - an array of values of type `T`.
|
|
8
|
+
*
|
|
9
|
+
* Useful when a function or API accepts **either one item or multiple items**.
|
|
10
|
+
*
|
|
11
|
+
* @template T - The element type.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* function toArray<T>(input: Arrayable<T>): T[] {
|
|
16
|
+
* return Array.isArray(input) ? input : [input];
|
|
17
|
+
* }
|
|
18
|
+
*
|
|
19
|
+
* type A = Arrayable<string>;
|
|
20
|
+
* // ➔ string | string[]
|
|
21
|
+
*
|
|
22
|
+
* const a: A = "foo";
|
|
23
|
+
* const b: A = ["foo", "bar"];
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
type Arrayable<T>=T|Array<T>;
|
|
27
|
+
/** -------------------------------------------------------
|
|
28
|
+
* * ***MutableArray.***
|
|
29
|
+
* -------------------------------------------------------
|
|
30
|
+
* Recursively creates a **mutable version** of a readonly array, tuple, or object type.
|
|
31
|
+
*
|
|
32
|
+
* By default, TypeScript infers tuple/array literals as `readonly` (especially with `as const`).
|
|
33
|
+
* This utility removes the `readonly` modifier from all elements recursively,
|
|
34
|
+
* turning a readonly tuple, array, or object into a mutable one.
|
|
35
|
+
*
|
|
36
|
+
* Optionally, if `Widen` is `true`, literal types (`1`, `'foo'`, `true`) are widened to
|
|
37
|
+
* their primitive equivalents (`number`, `string`, `boolean`) for easier assignment.
|
|
38
|
+
*
|
|
39
|
+
* @template T - The readonly array, tuple, or object type to make mutable.
|
|
40
|
+
* @template Widen - Whether to widen literal primitive types to their base types (default: `false`).
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* type A = readonly [1, 2, 3];
|
|
45
|
+
* type B = MutableArray<A>;
|
|
46
|
+
* // ➔ [1, 2, 3]
|
|
47
|
+
*
|
|
48
|
+
* const x: A = [1, 2, 3] as const;
|
|
49
|
+
* // x[0] = 9; // ❌ Error: read-only
|
|
50
|
+
*
|
|
51
|
+
* const y: MutableArray<B,true> = [1, 2, 3];
|
|
52
|
+
* y[0] = 9; // ✅ Allowed
|
|
53
|
+
*
|
|
54
|
+
* // Recursive example with objects
|
|
55
|
+
* type Obj = readonly [{ a: 1, b: readonly [2] }];
|
|
56
|
+
* type MutableObj = MutableArray<Obj, true>;
|
|
57
|
+
* // ➔ [{ a: number; b: [number]; }]
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
type MutableArray<T,Widen extends boolean=false>=T extends(...args:any)=>any?T:T extends readonly any[]?{-readonly [K in keyof T]:MutableArray<T[K],Widen>;}:T extends object?{-readonly [K in keyof T]:MutableArray<T[K],Widen>;}:Widen extends true?T extends number?number:T extends string?string:T extends boolean?boolean:T extends bigint?bigint:T extends symbol?symbol:T:T;
|
|
61
|
+
/** --------------------------------------------------
|
|
62
|
+
* * ***GetArrayElementType.***
|
|
63
|
+
* --------------------------------------------------
|
|
64
|
+
* Gets the element type from a readonly array or tuple.
|
|
65
|
+
*
|
|
66
|
+
* ✅ Useful when working with `as const` arrays to extract the union of literal types.
|
|
67
|
+
*
|
|
68
|
+
* @template T - A readonly array or tuple type.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* const roles = ['admin', 'user'] as const;
|
|
73
|
+
* type Role = GetArrayElementType<typeof roles>;
|
|
74
|
+
* // ➔ "admin" | "user"
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
type GetArrayElementType<T extends readonly any[]>=T extends readonly(infer U)[]?U:never;
|
|
78
|
+
/** -------------------------------------------------------
|
|
79
|
+
* * ***EmptyArray.***
|
|
80
|
+
* -------------------------------------------------------
|
|
81
|
+
* A type-level utility that returns `T` if it is an ***empty array***,
|
|
82
|
+
* otherwise returns `never`.
|
|
83
|
+
*
|
|
84
|
+
* @template T - The array type to check.
|
|
85
|
+
* @example
|
|
86
|
+
* ```ts
|
|
87
|
+
* type A = EmptyArray<[]>;
|
|
88
|
+
* // ➔ []
|
|
89
|
+
* type B = EmptyArray<[1]>;
|
|
90
|
+
* // ➔ never
|
|
91
|
+
* type C = EmptyArray<string[]>;
|
|
92
|
+
* // ➔ string[]
|
|
93
|
+
* type D = EmptyArray<number[]>;
|
|
94
|
+
* // ➔ number[]
|
|
95
|
+
* type E = EmptyArray<readonly []>;
|
|
96
|
+
* // ➔ readonly []
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
type EmptyArray<T extends readonly unknown[]>=T extends readonly [ unknown,...unknown[]]?never:T;
|
|
100
|
+
/** -------------------------------------------------------
|
|
101
|
+
* * ***NonEmptyArray.***
|
|
102
|
+
* -------------------------------------------------------
|
|
103
|
+
* A type-level utility that returns `T` if it is a ***non-empty array***,
|
|
104
|
+
* otherwise returns `never`.
|
|
105
|
+
*
|
|
106
|
+
* @template T - The array type to check.
|
|
107
|
+
* @example
|
|
108
|
+
* ```ts
|
|
109
|
+
* type A = NonEmptyArray<[]>;
|
|
110
|
+
* // ➔ never
|
|
111
|
+
* type B = NonEmptyArray<[1]>;
|
|
112
|
+
* // ➔ [1]
|
|
113
|
+
* type C = NonEmptyArray<string[]>;
|
|
114
|
+
* // ➔ never
|
|
115
|
+
* type D = NonEmptyArray<number[]>;
|
|
116
|
+
* // ➔ never
|
|
117
|
+
* type E = NonEmptyArray<readonly []>;
|
|
118
|
+
* // ➔ never
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
type NonEmptyArray<T extends readonly unknown[]>=If<IsNever<EmptyArray<T>>,T,never>;
|
|
122
|
+
/** -------------------------------------------------------
|
|
123
|
+
* * ***IsEmptyArray.***
|
|
124
|
+
* -------------------------------------------------------
|
|
125
|
+
* A type-level utility that evaluates to `true` if `T` is an ***empty array.***
|
|
126
|
+
* (or can be empty per this definition), otherwise `false`.
|
|
127
|
+
*
|
|
128
|
+
* @template T - The array type to check.
|
|
129
|
+
* @example
|
|
130
|
+
* ```ts
|
|
131
|
+
* type A = IsEmptyArray<[]>;
|
|
132
|
+
* // ➔ true
|
|
133
|
+
* type B = IsEmptyArray<[1]>;
|
|
134
|
+
* // ➔ false
|
|
135
|
+
* type C = IsEmptyArray<string[]>;
|
|
136
|
+
* // ➔ true
|
|
137
|
+
* type D = IsEmptyArray<number[]>;
|
|
138
|
+
* // ➔ true
|
|
139
|
+
* type E = IsEmptyArray<readonly []>;
|
|
140
|
+
* // ➔ true
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
type IsEmptyArray<T extends readonly unknown[]>=If<IsNever<EmptyArray<T>>,false,true>;
|
|
144
|
+
/** -------------------------------------------------------
|
|
145
|
+
* * ***IsNonEmptyArray.***
|
|
146
|
+
* -------------------------------------------------------
|
|
147
|
+
* A type-level utility that evaluates to `true` if `T` is a ***non-empty array.***
|
|
148
|
+
* (strictly a non-empty tuple), otherwise `false`.
|
|
149
|
+
*
|
|
150
|
+
* @template T - The array type to check.
|
|
151
|
+
* @example
|
|
152
|
+
* ```ts
|
|
153
|
+
* type A = IsNonEmptyArray<[]>;
|
|
154
|
+
* // ➔ false
|
|
155
|
+
* type B = IsNonEmptyArray<[1]>;
|
|
156
|
+
* // ➔ true
|
|
157
|
+
* type C = IsNonEmptyArray<string[]>;
|
|
158
|
+
* // ➔ false
|
|
159
|
+
* type D = IsNonEmptyArray<number[]>;
|
|
160
|
+
* // ➔ false
|
|
161
|
+
* type E = IsNonEmptyArray<readonly []>;
|
|
162
|
+
* // ➔ false
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
165
|
+
type IsNonEmptyArray<T extends readonly unknown[]>=If<IsNever<EmptyArray<T>>,true,false>;
|
|
166
|
+
/** -------------------------------------------------------
|
|
167
|
+
* * ***IfEmptyArray.***
|
|
168
|
+
* -------------------------------------------------------
|
|
169
|
+
* Returns the second argument if `T` is an ***empty array*** (per this utility),
|
|
170
|
+
* otherwise returns the third argument.
|
|
171
|
+
* - Defaults: `IfTrue = true`, `IfFalse = false`.
|
|
172
|
+
*
|
|
173
|
+
* @template T - The array type to check.
|
|
174
|
+
* @template IfTrue - Returned type if `T` is empty by this definition.
|
|
175
|
+
* @template IfFalse - Returned type if `T` is not empty by this definition.
|
|
176
|
+
* @example
|
|
177
|
+
* ```ts
|
|
178
|
+
* type A = IfEmptyArray<[]>;
|
|
179
|
+
* // ➔ true
|
|
180
|
+
* type B = IfEmptyArray<[1]>;
|
|
181
|
+
* // ➔ false
|
|
182
|
+
* type C = IfEmptyArray<string[]>;
|
|
183
|
+
* // ➔ true
|
|
184
|
+
* type D = IfEmptyArray<readonly []>;
|
|
185
|
+
* // ➔ true
|
|
186
|
+
* type E = IfEmptyArray<[], "yes", "no">;
|
|
187
|
+
* // ➔ "yes"
|
|
188
|
+
* type F = IfEmptyArray<[1], "yes", "no">;
|
|
189
|
+
* // ➔ "no"
|
|
190
|
+
* type G = IfEmptyArray<string[], "yes", "no">;
|
|
191
|
+
* // ➔ "yes"
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
type IfEmptyArray<T extends readonly unknown[],IfTrue=true,IfFalse=false>=If<IsEmptyArray<T>,IfTrue,IfFalse>;
|
|
195
|
+
/** -------------------------------------------------------
|
|
196
|
+
* * ***IfNonEmptyArray.***
|
|
197
|
+
* -------------------------------------------------------
|
|
198
|
+
* Returns the second argument if `T` is a ***non-empty array*** (strict tuple),
|
|
199
|
+
* otherwise returns the third argument.
|
|
200
|
+
* - Defaults: `IfTrue = true`, `IfFalse = false`.
|
|
201
|
+
*
|
|
202
|
+
* @template T - The array type to check.
|
|
203
|
+
* @template IfTrue - Returned type if `T` is non-empty by this definition.
|
|
204
|
+
* @template IfFalse - Returned type if `T` is not non-empty by this definition.
|
|
205
|
+
* @example
|
|
206
|
+
* ```ts
|
|
207
|
+
* type A = IfNonEmptyArray<[]>;
|
|
208
|
+
* // ➔ false
|
|
209
|
+
* type B = IfNonEmptyArray<[1]>;
|
|
210
|
+
* // ➔ true
|
|
211
|
+
* type C = IfNonEmptyArray<string[]>;
|
|
212
|
+
* // ➔ false
|
|
213
|
+
* type D = IfNonEmptyArray<readonly []>;
|
|
214
|
+
* // ➔ false
|
|
215
|
+
* type E = IfNonEmptyArray<[1], "yes", "no">;
|
|
216
|
+
* // ➔ "yes"
|
|
217
|
+
* type F = IfNonEmptyArray<[], "yes", "no">;
|
|
218
|
+
* // ➔ "no"
|
|
219
|
+
* type G = IfNonEmptyArray<string[], "yes", "no">;
|
|
220
|
+
* // ➔ "no"
|
|
221
|
+
* ```
|
|
222
|
+
*/
|
|
223
|
+
type IfNonEmptyArray<T extends readonly unknown[],IfTrue=true,IfFalse=false>=If<IsNonEmptyArray<T>,IfTrue,IfFalse>;export type{Arrayable as A,EmptyArray as E,GetArrayElementType as G,IsEmptyArray as I,MutableArray as M,NonEmptyArray as N,IfEmptyArray as a,IfNonEmptyArray as b,IsNonEmptyArray as c};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/** -------------------------------------------------------
|
|
2
|
+
* * ***FixNeverArrayRecursive.***
|
|
3
|
+
* -------------------------------------------------------
|
|
4
|
+
* A type-level utility that **recursively transforms arrays of type `never[]` into empty arrays**.
|
|
5
|
+
* - Preserves `readonly` modifiers.
|
|
6
|
+
* - Applies recursively for nested arrays.
|
|
7
|
+
* - Leaves other types unchanged.
|
|
8
|
+
*
|
|
9
|
+
* @template T - The input type to recursively fix.
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* type A = FixNeverArrayRecursive<never[]>;
|
|
13
|
+
* // ➔ []
|
|
14
|
+
* type B = FixNeverArrayRecursive<readonly never[]>;
|
|
15
|
+
* // ➔ readonly []
|
|
16
|
+
* type C = FixNeverArrayRecursive<string[]>;
|
|
17
|
+
* // ➔ string[]
|
|
18
|
+
* type D = FixNeverArrayRecursive<(never | string)[]>;
|
|
19
|
+
* // ➔ (never | string)[]
|
|
20
|
+
* type E = FixNeverArrayRecursive<(never[])[]>;
|
|
21
|
+
* // ➔ [][]
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
type FixNeverArrayRecursive<T>=T extends readonly never[]?T extends never[]?[]:readonly []:T extends(infer U)[]?FixNeverArrayRecursive<U>[]:T extends readonly(infer U)[]?readonly FixNeverArrayRecursive<U>[]:T;
|
|
25
|
+
/** -------------------------------------------------------
|
|
26
|
+
* * ***NormalizeEmptyArraysRecursive.***
|
|
27
|
+
* -------------------------------------------------------
|
|
28
|
+
* A type-level utility that **recursively normalizes empty array types** by converting arrays whose element type is `never`, `null`, or `undefined` into empty tuple types (`[]`).
|
|
29
|
+
* - Preserves `readonly` modifiers.
|
|
30
|
+
* - Recurses into nested arrays.
|
|
31
|
+
* - Leaves other array types unchanged.
|
|
32
|
+
*
|
|
33
|
+
* @template T - The input type to normalize.
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* type A = NormalizeEmptyArraysRecursive<never[]>;
|
|
37
|
+
* // ➔ []
|
|
38
|
+
* type B = NormalizeEmptyArraysRecursive<readonly never[]>;
|
|
39
|
+
* // ➔ readonly []
|
|
40
|
+
* type C = NormalizeEmptyArraysRecursive<null[]>;
|
|
41
|
+
* // ➔ []
|
|
42
|
+
* type D = NormalizeEmptyArraysRecursive<(null[] | string[])[]>;
|
|
43
|
+
* // ➔ ([] | string[])[]
|
|
44
|
+
* type E = NormalizeEmptyArraysRecursive<string[]>;
|
|
45
|
+
* // ➔ string[]
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
type NormalizeEmptyArraysRecursive<T>=T extends readonly(infer U)[]?U extends never|null|undefined?T extends readonly unknown[]?T extends(infer E)[]?[]:readonly []:never:T extends(infer E)[]?NormalizeEmptyArraysRecursive<U>[]:readonly NormalizeEmptyArraysRecursive<U>[]:T;
|
|
49
|
+
/** -------------------------------------------------------
|
|
50
|
+
* * ***RemoveEmptyArrayElements.***
|
|
51
|
+
* -------------------------------------------------------
|
|
52
|
+
* A type-level utility that **recursively removes empty array elements (`[]`) from a tuple type**.
|
|
53
|
+
* - If `T` is a tuple, checks the first element:
|
|
54
|
+
* - If `Head` is an empty array type (`[]`), it is removed.
|
|
55
|
+
* - Otherwise, `Head` is preserved.
|
|
56
|
+
* - Repeats recursively on the rest of the tuple.
|
|
57
|
+
* - Leaves non-tuple types unchanged.
|
|
58
|
+
*
|
|
59
|
+
* @template T - The tuple type to process.
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* type A = RemoveEmptyArrayElements<[[], 1, [], 2]>;
|
|
63
|
+
* // ➔ [1, 2]
|
|
64
|
+
* type B = RemoveEmptyArrayElements<[]>;
|
|
65
|
+
* // ➔ []
|
|
66
|
+
* type C = RemoveEmptyArrayElements<[[], [], []]>;
|
|
67
|
+
* // ➔ []
|
|
68
|
+
* type D = RemoveEmptyArrayElements<[1, 2, 3]>;
|
|
69
|
+
* // ➔ [1, 2, 3]
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
type RemoveEmptyArrayElements<T>=T extends [infer Head,...infer Tail]?Head extends []?RemoveEmptyArrayElements<Tail>:[Head,...RemoveEmptyArrayElements<Tail>]:T extends []?[]:T;export type{FixNeverArrayRecursive as F,NormalizeEmptyArraysRecursive as N,RemoveEmptyArrayElements as R};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var chunkI4AVNHPA_cjs=require('../chunk-I4AVNHPA.cjs'),chunk62HX5Z45_cjs=require('../chunk-62HX5Z45.cjs'),chunkBVPMMWDL_cjs=require('../chunk-BVPMMWDL.cjs');require('../chunk-7YWAQOA4.cjs');var chunkCN53M4QZ_cjs=require('../chunk-CN53M4QZ.cjs');Object.defineProperty(exports,"assertIsBigInt",{enumerable:true,get:function(){return chunkI4AVNHPA_cjs.a}});Object.defineProperty(exports,"assertIsNumber",{enumerable:true,get:function(){return chunkI4AVNHPA_cjs.b}});Object.defineProperty(exports,"assertIsArray",{enumerable:true,get:function(){return chunk62HX5Z45_cjs.a}});Object.defineProperty(exports,"assertIsString",{enumerable:true,get:function(){return chunkBVPMMWDL_cjs.a}});Object.defineProperty(exports,"assertIsBoolean",{enumerable:true,get:function(){return chunkCN53M4QZ_cjs.G}});Object.defineProperty(exports,"assertIsPlainObject",{enumerable:true,get:function(){return chunkCN53M4QZ_cjs.m}});
|