@empathyco/x-deep-merge
Version:
Utility for deep cloning objects.
38 lines (37 loc) • 1.37 kB
TypeScript
/**
* Clones deeply all of the sources objects values into the target, except the arrays,
* which only generates a new one, but keeping the references of the sources one.
*
* TODO Make it work with circular references.
*
* @param target - The object which will be used as the base to clone all the sources into.
* @param sources - One or more objects to clone to the target.
*
* @returns The target modified.
*/
export declare function deepMerge(target: any, ...sources: any[]): any;
/**
* When setting replace behaviour to an object, target properties will not be used,
* only the source ones.
*
* @param obj - The object to set its merge behavior.
* @example
* ```ts
* const target = { children: { a: 1, b: 2, c: 3 } };
* const firstSource = { children: replaceBehaviour({ c: 4, d: 5 }) };
* deepMerge(target, firstSource);
* // `target` is now { children: { c: 4, d: 5 } }
* ```
*
* @returns The same object with the new behaviour.
*/
export declare function replaceBehaviour<T extends Record<string, unknown>>(obj: T): T;
/**
* When setting deep merge behaviour, target and source properties will be used. This is the default
* behavior.
*
* @param obj - The object to set its merge behavior.
*
* @returns The same object with the new behaviour.
*/
export declare function deepMergeBehaviour<T extends Record<string, unknown>>(obj: T): T;