@rzl-zone/utils-js 3.3.1 → 3.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,66 +0,0 @@
1
- import{I as If}from'./if-ChM35c_q.js';
2
- /** -------------------------------------------------------
3
- * * ***Utility Type: `IsNever`.***
4
- * -------------------------------------------------------
5
- * ****Conditional**: returns `true` if `T` is `never`, otherwise `false`.**
6
- * @template T - Type to check.
7
- * @example
8
- * ```ts
9
- * type A = IsNever<never>; // ➔ true
10
- * type B = IsNever<true>; // ➔ false
11
- * ```
12
- */
13
- type IsNever<T>=[T] extends [never]?true:false;
14
- /** -------------------------------------------------------
15
- * * ***Utility Type: `IfNever`.***
16
- * -------------------------------------------------------
17
- * ****Conditional**: Selects one of two branches depending on whether `T` is `never`.**
18
- * - Defaults: `IfTrue = true`, `IfFalse = false`.
19
- * @template T - Type to check.
20
- * @template IfTrue - The branch type if `T` is `never`, (default: `true`).
21
- * @template IfFalse - The branch type if `T` is not `never`, (default: `false`).
22
- * @example
23
- * ```ts
24
- * type A = IfNever<never>;
25
- * // ➔ true
26
- * type B = IfNever<string>;
27
- * // ➔ false
28
- * type C = IfNever<never, 'valid', 'no'>;
29
- * // ➔ 'valid'
30
- * type D = IfNever<string, 'valid', 'no'>;
31
- * // ➔ 'no'
32
- * ```
33
- */
34
- type IfNever<T,IfTrue=true,IfFalse=false>=If<IsNever<T>,IfTrue,IfFalse>;
35
- /** -------------------------------------------------------
36
- * * ***Utility Type: `NeverifyPropertiesOptions`.***
37
- * -------------------------------------------------------
38
- * **Configuration options for the ***{@link NeverifyProperties | `NeverifyProperties`}*** type utility.**
39
- * @example
40
- * ```ts
41
- * type Opt1 = NeverifyPropertiesOptions;
42
- * // ➔ { makeOptional: boolean }
43
- * ```
44
- */
45
- type NeverifyPropertiesOptions={
46
- /** * ***Whether to make all properties optional, defaultValue: `false`.***
47
- *
48
- * @default false
49
- */
50
- makeOptional:boolean;};
51
- /** -------------------------------------------------------
52
- * * ***Utility Type: `NeverifyProperties`.***
53
- * -------------------------------------------------------
54
- * **Turns all properties of an object to type `never`.**
55
- * - If `Options["makeOptional"]` is `true`, properties will be optional.
56
- * @template T - Object type to transform.
57
- * @template Options - Configuration options (default: `{ makeOptional: false }`).
58
- * @example
59
- * ```ts
60
- * type A = NeverifyProperties<{ a: string; b: string }>;
61
- * // ➔ { a: never; b: never }
62
- * type B = NeverifyProperties<{ a: string; b: string }, { makeOptional: true }>;
63
- * // ➔ { a?: never; b?: never }
64
- * ```
65
- */
66
- type NeverifyProperties<T extends object,Options extends NeverifyPropertiesOptions={makeOptional:false;}>={[K in keyof T]:never;}extends infer Result?If<Options["makeOptional"],Partial<Result>,Result>:never;export type{IsNever as I,NeverifyProperties as N,IfNever as a,NeverifyPropertiesOptions as b};
@@ -1,151 +0,0 @@
1
- /** --------------------------------------------------
2
- * * ***Utility Type: `Nullish`.***
3
- * --------------------------------------------------
4
- * **Useful as a shorthand when working with optional or missing values.**
5
- * - **Represents all values considered **`nullish`**:**
6
- * - `null`
7
- * - `undefined`
8
- */
9
- type Nullish=null|undefined;
10
- /** --------------------------------------------------
11
- * * ***Utility Type: `Nullable`.***
12
- * --------------------------------------------------
13
- * **Represents a type that can be either `T` or `null`.**
14
- * @template T - The base type.
15
- * @example
16
- * ```ts
17
- * type A = Nullable<string>; // ➔ string | null
18
- * ```
19
- */
20
- type Nullable<T>=T|null;
21
- /** --------------------------------------------------
22
- * * ***Utility Type: `Nilable`.***
23
- * --------------------------------------------------
24
- * **Represents a type that can be either `T`, `null`, or `undefined`.**
25
- * @template T - The base type.
26
- * @example
27
- * ```ts
28
- * type A = Nilable<number>; // ➔ number | null | undefined
29
- * ```
30
- */
31
- type Nilable<T>=T|null|undefined;
32
- /** --------------------------------------------------
33
- * * ***Utility Type: `Undefinedable`.***
34
- * --------------------------------------------------
35
- * **Represents a type that can be either `T` or `undefined`.**
36
- * @template T - The base type.
37
- * @example
38
- * ```ts
39
- * type A = Undefinedable<boolean>; // ➔ boolean | undefined
40
- * ```
41
- */
42
- type Undefinedable<T>=T|undefined;
43
- /** -------------------------------------------------------
44
- * * ***Utility Type: `NonNil`.***
45
- * -------------------------------------------------------
46
- * **Removes both `null` and `undefined` from the given type `T`.**
47
- * @template T - The type to filter.
48
- * @example
49
- * ```ts
50
- * type A = NonNil<string | null | undefined>;
51
- * // ➔ string
52
- * type B = NonNil<number | null>;
53
- * // ➔ number
54
- * type C = NonNil<undefined | null>;
55
- * // ➔ never
56
- * type D = NonNil<boolean | undefined>;
57
- * // ➔ boolean
58
- * ```
59
- */
60
- type NonNil<T>=T extends null|undefined?never:T;
61
- /** -------------------------------------------------------
62
- * * ***Utility Type: `NonNull`.***
63
- * -------------------------------------------------------
64
- * **Removes `null` from the given type `T`.**
65
- * @template T - The type to filter.
66
- * @example
67
- * ```ts
68
- * type A = NonNull<string | null>;
69
- * // ➔ string
70
- * type B = NonNull<number | null | undefined>;
71
- * // ➔ number | undefined
72
- * type C = NonNull<null>;
73
- * // ➔ never
74
- * ```
75
- */
76
- type NonNull<T>=T extends null?never:T;
77
- /** -------------------------------------------------------
78
- * * ***Utility Type: `NonUndefined`.***
79
- * -------------------------------------------------------
80
- * **Remove `undefined` from the given type `T`.**
81
- * @template T - The type to filter.
82
- * @example
83
- * ```ts
84
- * type A = NonUndefined<string | undefined>;
85
- * // ➔ string
86
- * type B = NonUndefined<number | null | undefined>;
87
- * // ➔ number | null
88
- * type C = NonUndefined<undefined>;
89
- * // ➔ never
90
- * ```
91
- */
92
- type NonUndefined<T>=T extends undefined?never:T;
93
- /** --------------------------------------------------
94
- * * ***Utility Type: `KeepNil`.***
95
- * --------------------------------------------------
96
- * **Keeps `null` and/or `undefined` in the output type **only if** they
97
- * exist in the input type `T`, otherwise, resolves to `never`.**
98
- * @template T - Input type to check for `null` and `undefined`.
99
- * @example
100
- * ```ts
101
- * type A = KeepNil<string | null>;
102
- * // ➔ null
103
- * type B = KeepNil<number | undefined>;
104
- * // ➔ undefined
105
- * type C = KeepNil<string | null | undefined>;
106
- * // ➔ null | undefined
107
- * type D = KeepNil<boolean>;
108
- * // ➔ never
109
- * ```
110
- */
111
- type KeepNil<T>=(null extends T?null:never)|(undefined extends T?undefined:never);
112
- /** --------------------------------------------------
113
- * * ***Utility Type: `KeepNull`.***
114
- * --------------------------------------------------
115
- * **Keeps `null` in the output type **only if** the input type `T` includes `null`, otherwise resolves to `never`.**
116
- * @template T - Input type to check for `null`.
117
- * @example
118
- * ```ts
119
- * type A = KeepNull<string | null>; // ➔ null
120
- * type B = KeepNull<string>; // ➔ never
121
- * ```
122
- */
123
- type KeepNull<T>=null extends T?null:never;
124
- /** --------------------------------------------------
125
- * * ***Utility Type: `KeepUndef`.***
126
- * --------------------------------------------------
127
- * **Keeps `undefined` in the output type **only if** the input type `T` includes `undefined`, otherwise resolves to `never`.**
128
- * @template T - Input type to check for `undefined`.
129
- * @example
130
- * ```ts
131
- * type A = KeepUndef<number | undefined>; // ➔ undefined
132
- * type B = KeepUndef<number>; // ➔ never
133
- * ```
134
- */
135
- type KeepUndef<T>=undefined extends T?undefined:never;
136
- /** -------------------------------------------------------
137
- * * ***Utility Type: `NullToUndefined`.***
138
- * -------------------------------------------------------
139
- * **Transforms `null` or `undefined` types into `undefined`, otherwise, returns
140
- * the original type `T` unchanged.**
141
- * @template T - The input type to transform.
142
- * @example
143
- * ```ts
144
- * type A = NullToUndefined<null>; // ➔ undefined
145
- * type B = NullToUndefined<undefined>; // ➔ undefined
146
- * type C = NullToUndefined<string>; // ➔ string
147
- * type D = NullToUndefined<null[]>; // ➔ null[]
148
- * type E = NullToUndefined<(string | null)[]>; // ➔ (string | null)[]
149
- * ```
150
- */
151
- type NullToUndefined<T>=T extends null?undefined:T extends undefined?undefined:T;export type{KeepNil as K,NonUndefined as N,Undefinedable as U,KeepNull as a,KeepUndef as b,Nilable as c,NonNil as d,NonNull as e,Nullable as f,NullToUndefined as g,Nullish as h};
@@ -1,82 +0,0 @@
1
- import{E as Extends,I as IfExtends}from'./extends-DtdRjDyU.js';
2
- /** -------------------------------------------------------
3
- * * ***Utility Type: `And`.***
4
- * -------------------------------------------------------
5
- * **Performs a **logical AND** operation between two boolean types.**
6
- * - **Behavior:**
7
- * - Returns `true` if **both** conditions extend `true`.
8
- * - Returns `false` for otherwise.
9
- * @template Condition1 - The first condition.
10
- * @template Condition2 - The second condition.
11
- * @example
12
- * ```ts
13
- * type Case1 = And<true, true>;
14
- * // ➔ true
15
- * type Case2 = And<false, true>;
16
- * // ➔ false
17
- * type Case3 = And<true, false>;
18
- * // ➔ false
19
- * type Case4 = And<false, false>;
20
- * // ➔ false
21
- * ```
22
- */
23
- type And<Condition1,Condition2>=IfExtends<Condition1,true,Extends<Condition2,true>>;
24
- /** -------------------------------------------------------
25
- * * ***Utility Type: `AndArr`.***
26
- * -------------------------------------------------------
27
- * **Performs a **logical AND** operation across all elements in an array of
28
- * boolean types.**
29
- * - **Behavior:**
30
- * - Returns `true` if **all elements** extend `true`.
31
- * - Returns `false` if **any element** is not `true`.
32
- * @template Conditions - A readonly array of boolean conditions.
33
- * @example
34
- * ```ts
35
- * type Case1 = AndArr<[true, true, true]>;
36
- * // ➔ true
37
- * type Case2 = AndArr<[true, true, false]>;
38
- * // ➔ false
39
- * type Case3 = AndArr<[false, false, false]>;
40
- * // ➔ false
41
- * type Case4 = AndArr<[]>;
42
- * // ➔ false
43
- * ```
44
- */
45
- type AndArr<Conditions extends readonly unknown[]>=Extends<[],Conditions>extends true?false:Extends<Conditions[number],true>;
46
- /** -------------------------------------------------------
47
- * * ***Utility Type: `Or`.***
48
- * -------------------------------------------------------
49
- * **Computes the logical OR of two type-level boolean conditions.**
50
- * @template Condition1 - First boolean condition.
51
- * @template Condition2 - Second boolean condition.
52
- * @example
53
- * ```ts
54
- * type Case1 = Or<true, true>; // ➔ true
55
- * type Case2 = Or<false, true>; // ➔ true
56
- * type Case3 = Or<false, false>; // ➔ false
57
- * type Case4 = Or<true, false>; // ➔ true
58
- * ```
59
- * @remarks
60
- * - Uses {@link IfExtends | **`IfExtends`**} to determine if either condition is `true`.
61
- * - Returns `true` if at least one of the two conditions is `true`.
62
- * - Returns `false` only if both are `false`.
63
- */
64
- type Or<Condition1,Condition2>=IfExtends<Condition1,true,true,IfExtends<Condition2,true>>;
65
- /** -------------------------------------------------------
66
- * * ***Utility Type: `OrArr`.***
67
- * -------------------------------------------------------
68
- * **Computes the logical OR of all elements inside a tuple or array of boolean types.**
69
- * @template Conditions - An array of boolean type elements.
70
- * @example
71
- * ```ts
72
- * type Case1 = OrArr<[true, true, true]>; // ➔ true
73
- * type Case2 = OrArr<[true, true, false]>; // ➔ true
74
- * type Case3 = OrArr<[false, false, false]>; // ➔ false
75
- * type Case4 = OrArr<[]>; // ➔ false
76
- * ```
77
- * @remarks
78
- * - Uses TypeScript's indexed access types and conditional type inference.
79
- * - Returns `true` if at least one element in the array is `true`.
80
- * - Returns `false` if all elements are `false` or array is empty.
81
- */
82
- type OrArr<Conditions extends readonly unknown[]>=true extends Conditions[number]?true:false;export type{And as A,OrArr as O,AndArr as a,Or as b};
@@ -1,59 +0,0 @@
1
- import{P as Prettify}from'./prettify-3o8_Kw6b.js';
2
- /** --------------------------------------------------
3
- * * ***Utility Type: `ExtractStrict`.***
4
- * --------------------------------------------------
5
- * **Performs a stricter version of the built-in `Extract<T, U>`
6
- * with improved type narrowing.**
7
- * - ✅ Especially useful in generic utilities where the
8
- * standard `Extract` can widen or collapse unions.
9
- * @template T - The full union or set of types.
10
- * @template U - The type(s) to be kept from `T`.
11
- * @example
12
- * ```ts
13
- * type A = 'a' | 'b' | 'c';
14
- * type B = ExtractStrict<A, 'b' | 'c'>;
15
- * // ➔ 'b' | 'c'
16
- * ```
17
- */
18
- type ExtractStrict<T,U extends T>=T extends unknown?0 extends(U extends T?([T] extends [U]?0:never):never)?T:never:never;
19
- /** --------------------------------------------------
20
- * * ***Utility Type: `OmitStrict`.***
21
- * --------------------------------------------------
22
- * **Strictly omits keys `K` from type `T`, with optional flattening for readability using `Prettify`.**
23
- * - **Behavior:**
24
- * - ✅ Enhances autocomplete and type inspection clarity in editors.
25
- * - ✅ Optionally flattens nested intersections or mapped types into a cleaner shape.
26
- * @template T - The original object type.
27
- * @template K - The keys to omit from `T`.
28
- * @template WithPrettify - Whether to prettify the result (default is `true`).
29
- * @template WithPrettifyRecursive - Whether to prettify nested object properties recursively (default is `true`).
30
- * @example
31
- * ```ts
32
- * type A = { a: number; b: string; c: boolean };
33
- * type B = OmitStrict<A, 'b'>;
34
- * // ➔ { a: number; c: boolean }
35
- *
36
- * type C = OmitStrict<A, 'b', false>;
37
- * // ➔ Omit without prettifying, keeps intersection structure
38
- *
39
- * type D = OmitStrict<A, 'b', true, false>;
40
- * // ➔ Prettifies only top level, does not recurse into nested objects
41
- * ```
42
- */
43
- type OmitStrict<T,K extends keyof T,WithPrettify extends boolean=true,WithPrettifyRecursive extends boolean=true>=WithPrettify extends true?Prettify<Omit<T,K>,{recursive:WithPrettifyRecursive extends boolean?WithPrettifyRecursive:false;}>:WithPrettify extends false?Omit<T,K>:never;
44
- /** --------------------------------------------------
45
- * * ***Utility Type: `OverrideTypes`.***
46
- * --------------------------------------------------
47
- * **Overrides properties in type `T` with properties from type `U`, based on matching keys.**
48
- * - ✅ Ensures the result retains all properties from `T`, but values from `U` override corresponding keys.
49
- * @template T - The base object type to override.
50
- * @template U - The object type containing overriding properties.
51
- * @example
52
- * ```ts
53
- * type A = { a: number; b: string };
54
- * type B = { b: boolean };
55
- * type C = OverrideTypes<A, B>;
56
- * // ➔ { a: number; b: boolean }
57
- * ```
58
- */
59
- type OverrideTypes<T,U extends Partial<Record<keyof T,unknown>>>=OmitStrict<T,Extract<keyof U,keyof T>>& U extends infer U?{[K in keyof U]:U[K];}:never;export type{ExtractStrict as E,OmitStrict as O,OverrideTypes as a};
@@ -1,15 +0,0 @@
1
- /** --------------------------------------------------
2
- * * ***Utility Type: `PickStrict`.***
3
- * --------------------------------------------------
4
- * **Utility type that behaves exactly like the native `Pick<T, K>`,
5
- * but can help with type inference and IDE autocomplete in stricter scenarios.**
6
- * @template T - The base object type.
7
- * @template K - The keys from `T` to be picked.
8
- * @example
9
- * ```ts
10
- * type A = { a: number; b: string; c: boolean };
11
- * type B = PickStrict<A, 'a' | 'c'>;
12
- * // ➔ { a: number; c: boolean }
13
- * ```
14
- */
15
- type PickStrict<T,K extends keyof T>=Pick<T,K>;export type{PickStrict as P};