@react-typed-forms/schemas 15.1.2 → 15.2.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/lib/index.cjs +12 -0
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +10 -1
- package/lib/index.js.map +1 -1
- package/lib/util.d.ts +1 -0
- package/package.json +1 -1
- package/src/util.ts +11 -0
package/lib/util.d.ts
CHANGED
|
@@ -224,6 +224,7 @@ export declare function findFieldPath(fields: SchemaField[], fieldPath: string |
|
|
|
224
224
|
* @returns {A} - The merged object.
|
|
225
225
|
*/
|
|
226
226
|
export declare function mergeObjects<A extends Record<string, any> | undefined>(o1: A, o2: A, doMerge?: (k: keyof NonNullable<A>, v1: unknown, v2: unknown) => unknown): A;
|
|
227
|
+
export declare function deepMerge<A>(value: A, fallback: A): A;
|
|
227
228
|
/**
|
|
228
229
|
* Coerces a value to a string.
|
|
229
230
|
* @param {unknown} v - The value to coerce.
|
package/package.json
CHANGED
package/src/util.ts
CHANGED
|
@@ -785,6 +785,17 @@ export function mergeObjects<A extends Record<string, any> | undefined>(
|
|
|
785
785
|
return result;
|
|
786
786
|
}
|
|
787
787
|
|
|
788
|
+
export function deepMerge<A>(value: A, fallback: A): A {
|
|
789
|
+
if (value == null) return fallback;
|
|
790
|
+
if (typeof value !== "object") return value;
|
|
791
|
+
// concat arrays
|
|
792
|
+
if (Array.isArray(value)) {
|
|
793
|
+
return (value as any[]).concat(fallback as any) as A;
|
|
794
|
+
}
|
|
795
|
+
return mergeObjects(value as A, fallback as any, (_, v1, fv) =>
|
|
796
|
+
deepMerge(v1, fv),
|
|
797
|
+
) as A;
|
|
798
|
+
}
|
|
788
799
|
/**
|
|
789
800
|
* Coerces a value to a string.
|
|
790
801
|
* @param {unknown} v - The value to coerce.
|