rambdax
Version:
Extended version of Rambda - a lightweight, faster alternative to Ramda
24 lines (19 loc) • 588 B
JavaScript
import { type } from './type'
export function mergeDeepRight(target, source){
if (arguments.length === 1){
return sourceHolder => mergeDeepRight(target, sourceHolder)
}
const willReturn = JSON.parse(JSON.stringify(target))
Object.keys(source).forEach(key => {
if (type(source[ key ]) === 'Object'){
if (type(target[ key ]) === 'Object'){
willReturn[ key ] = mergeDeepRight(target[ key ], source[ key ])
} else {
willReturn[ key ] = source[ key ]
}
} else {
willReturn[ key ] = source[ key ]
}
})
return willReturn
}