A merge library with support for deep merge or replacement of values at particular paths within the target object
npm install @github1/smergesmerge(source, target);$set
Replaces the value in the owning key.
smerge({
a: 1,
b: {b1: 'a'}
}, {
a: 2,
b: ['$set', {b2: 'a'}]
})Returns
{ a: 2, b: {b2: 'a'} }$push
Adds an element to the equivalent array in the merged result.
smerge({
a: ['a']
}, {
a: ['$push', 'b']
});Returns
{ a: ['a', 'b'] }$unshift
Adds element to the equivalent array in the merged result.
smerge({
a: ['a']
}, {
a: ['$unshift', 'b']
});Returns
{ a: ['b', 'a'] }$concat
Concatenates an array onto the equivalent array in the merged result.
smerge({
a: ['a']
}, {
a: ['$concat', ['b', 'c']]
});Returns
{ a: ['a', 'b', 'c'] }$function
Executes the supplied function to determine how a value or values should be merged.
smerge({
a: ['a']
}, {
a: ['$function', (a) => ({z: a})]
})Returns
{
a: {z: ['a']}
}