UNPKG

rambdax

Version:

Extended version of Rambda - a lightweight, faster alternative to Ramda

25 lines (20 loc) 605 B
import { clone } from './clone.js' import { type } from './type.js' export function mergeDeepRight(target, source){ if (arguments.length === 1){ return sourceHolder => mergeDeepRight(target, sourceHolder) } const willReturn = clone(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 }