@trenskow/merge v0.1.20
@trenskow/merge
A small library for doing recursive Object.assign
.
Usage
Below is an example of how to use the package.
import merge from '@trenskow/merge';
const myFirstValue = { first: 1, shared: { value: 1 } };
const mySecondValue = { second: 2, shared: { value: 2 } };
const myThirdValue = { third: 3, shared: { value: 3 } };
const myValue = merge(myFirstValue, mySecondValue, myThirdValue);
/*
myValue is {
first: 1,
second: 2,
third: 3,
shared: {
value: 3
}
}
*/
How it works
Input values are compared in pairs, so if more than two values are provided, the first two are compared – then the result is compared to the third – and that result is compared to the fourth, etc...
Rules
The rules for merging the input values is as below.
1) If one of the values is not an object? The second value survives. 2) If both values are an array? An new array is created with the items from the first array and then the values of the second array. The new array survives. 3) Both values are now regarded as objects. An new object with the following keys are created. The properties unique of the first object. The properties which is set on both objects are merged. The keys unique of the second object. The new object survives.
License
See license in LICENSE.
2 months ago
3 months ago
4 months ago
4 months ago
10 months ago
10 months ago
9 months ago
9 months ago
7 months ago
7 months ago
1 year ago
1 year ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago