# ghostkit/3.3.2/gutenberg/utils/merge/index.js

Block Animations, Motion &amp; Scroll Effects – Ghost Kit, version 3.3.2. 41 lines.

- Page: https://pluginprobe.com/plugins/ghostkit/3.3.2/code/gutenberg/utils/merge/index.js
- Raw: https://pluginprobe.com/plugins/ghostkit/3.3.2/raw/gutenberg/utils/merge/index.js
- Modified: 2024-02-18T18:40:24+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/ghostkit/3.3.2/code/gutenberg/utils/merge/index.js#L10-L20`.

```javascript
/**
 * Simple object check.
 *
 * @param  item
 * @return {boolean}
 */
function isObject(item) {
	return item && typeof item === 'object' && !Array.isArray(item);
}

/**
 * Deep merge two objects.
 *
 * @link https://stackoverflow.com/a/34749873
 *
 * @param {...any} sources
 * @param          target
 * @param          ...sources
 */
export default function mergeDeep(target, ...sources) {
	if (!sources.length) {
		return target;
	}
	const source = sources.shift();

	if (isObject(target) && isObject(source)) {
		Object.keys(source).forEach((key) => {
			if (isObject(source[key])) {
				if (!target[key]) {
					Object.assign(target, { [key]: {} });
				}
				mergeDeep(target[key], source[key]);
			} else {
				Object.assign(target, { [key]: source[key] });
			}
		});
	}

	return mergeDeep(target, ...sources);
}

```
