mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-12-24 17:47:50 +08:00
23 lines
582 B
TypeScript
23 lines
582 B
TypeScript
|
import { AnyObject } from '../types'
|
||
|
import isObject from './isObject'
|
||
|
|
||
|
export default function mergeDeep(target: AnyObject, source: AnyObject) {
|
||
|
const output = { ...target }
|
||
|
|
||
|
if (isObject(target) && isObject(source)) {
|
||
|
Object.keys(source).forEach(key => {
|
||
|
if (isObject(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
|
||
|
}
|