Skip to content
/ smerge Public

A merge library with support for deep merge or replacement of values at particular paths within the target object

License

Notifications You must be signed in to change notification settings

github1/smerge

Repository files navigation

@github1/smerge

A merge library with support for deep merge or replacement of values at particular paths within the target object

build status npm version npm downloads

Install

npm install @github1/smerge

Usage

smerge(source, target);

Instructions

$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']}
}

License

MIT

About

A merge library with support for deep merge or replacement of values at particular paths within the target object

Resources

License

Stars

Watchers

Forks

Packages

No packages published