/**
 * Util to merge two objects deeply. Will merge the source object into the target object.
 *
 * Note: This does not merge two arrays, it only replaces them (i.e. [1, 2] and [3, 4] would become [3, 4]).
 * Objects will be deeply merged instead of immediately replaced.
 *
 * NOTE: This will be replacing `mergeDeep` that exists in hub-components utils.
 *
 * adapted from https://gist.github.com/ahtcx/0cd94e62691f539160b32ecda18af3d6?permalink_comment_id=3120712#gistcomment-3120712
 * @param target - the object to merge into
 * @param source - the object to merge from
 * @returns the merged object
 */
export function deepMerge(target, source) {
    const isObject = (obj) => obj && typeof obj === "object" && !Array.isArray(obj);
    if (!isObject(target) || !isObject(source)) {
        return source;
    }
    Object.keys(source).forEach((key) => {
        const targetValue = target[key];
        const sourceValue = source[key];
        // if object, recursive check
        if (isObject(targetValue) && isObject(sourceValue)) {
            target[key] = deepMerge(Object.assign({}, targetValue), sourceValue);
        }
        // if anything else, set value if we should
        // this includes arrays -- we do not merge arrays, we replace them
        else {
            target[key] = sourceValue;
        }
    });
    return target;
}
//# sourceMappingURL=deepMerge.js.map