@sohanemon/utils 5.2.7 → 5.2.8
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,3 +1,4 @@
|
|
|
1
|
+
import { DeepNullToUndefined } from '../types/utilities';
|
|
1
2
|
/**
|
|
2
3
|
* Deeply cleans any value by converting all `null` values to `undefined`,
|
|
3
4
|
* and merges in a fallback object for default values.
|
|
@@ -38,7 +39,7 @@ export declare function hydrate<T>(data: T, fallback?: Partial<T>, options?: {
|
|
|
38
39
|
maxDepth?: number;
|
|
39
40
|
throwOnCircular?: boolean;
|
|
40
41
|
convertNullToUndefined?: boolean;
|
|
41
|
-
}): T
|
|
42
|
+
}): DeepNullToUndefined<T>;
|
|
42
43
|
/**
|
|
43
44
|
* Type guard utility for checking if a value is an object with a specific shape
|
|
44
45
|
*/
|
|
@@ -45,14 +45,14 @@ export function hydrate(data, fallback, options) {
|
|
|
45
45
|
// Check recursion depth
|
|
46
46
|
if (depth > maxDepth) {
|
|
47
47
|
console.warn(`[hydrate] Maximum recursion depth (${maxDepth}) exceeded. Returning value as-is.`);
|
|
48
|
-
return value ?? fallbackValue;
|
|
48
|
+
return (value ?? fallbackValue);
|
|
49
49
|
}
|
|
50
50
|
if (value === null) {
|
|
51
|
-
return convertNullToUndefined ? undefined : (fallbackValue ?? null);
|
|
51
|
+
return (convertNullToUndefined ? undefined : (fallbackValue ?? null));
|
|
52
52
|
}
|
|
53
53
|
// Handle undefined - use fallback or return undefined
|
|
54
54
|
if (value === undefined) {
|
|
55
|
-
return fallbackValue ?? undefined;
|
|
55
|
+
return (fallbackValue ?? undefined);
|
|
56
56
|
}
|
|
57
57
|
// Handle primitives: string, number, boolean, symbol, bigint
|
|
58
58
|
const type = typeof value;
|
|
@@ -97,7 +97,7 @@ export function hydrate(data, fallback, options) {
|
|
|
97
97
|
return result;
|
|
98
98
|
}
|
|
99
99
|
// For other objects, return as-is (instances, etc.)
|
|
100
|
-
return value ?? fallbackValue;
|
|
100
|
+
return (value ?? fallbackValue);
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
103
|
/**
|
|
@@ -7,6 +7,10 @@ export type SelectivePartial<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T
|
|
|
7
7
|
export type DeepRequired<T> = T extends Function ? T : T extends Array<infer U> ? Array<DeepRequired<U>> : T extends object ? {
|
|
8
8
|
[K in keyof T]-?: DeepRequired<T[K]>;
|
|
9
9
|
} : T;
|
|
10
|
+
export type NullToUndefined<T> = T extends null ? undefined : T;
|
|
11
|
+
export type DeepNullToUndefined<T> = T extends Function ? T : T extends Array<infer U> ? Array<DeepNullToUndefined<U>> : T extends object ? {
|
|
12
|
+
[K in keyof T]: DeepNullToUndefined<NullToUndefined<T[K]>>;
|
|
13
|
+
} : NullToUndefined<T>;
|
|
10
14
|
export type Never<T> = {
|
|
11
15
|
[K in keyof T]: never;
|
|
12
16
|
};
|