* use named exports instead of default exports * fix tests Co-authored-by: Philipp Kühn <philippkuehn@MacBook-Pro-von-Philipp.local>
22 lines
607 B
TypeScript
22 lines
607 B
TypeScript
import { isPlainObject } from './isPlainObject'
|
|
|
|
export function mergeDeep(target: Record<string, any>, source: Record<string, any>): Record<string, any> {
|
|
const output = { ...target }
|
|
|
|
if (isPlainObject(target) && isPlainObject(source)) {
|
|
Object.keys(source).forEach(key => {
|
|
if (isPlainObject(source[key])) {
|
|
if (!(key in target)) {
|
|
Object.assign(output, { [key]: source[key] })
|
|
} else {
|
|
output[key] = mergeDeep(target[key], source[key])
|
|
}
|
|
} else {
|
|
Object.assign(output, { [key]: source[key] })
|
|
}
|
|
})
|
|
}
|
|
|
|
return output
|
|
}
|