0.1.20 • Published 2 months ago

@trenskow/merge v0.1.20

Weekly downloads
-
License
BSD-2-Clause
Repository
github
Last release
2 months ago

@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.

0.1.20

2 months ago

0.1.19

3 months ago

0.1.17

4 months ago

0.1.18

4 months ago

0.1.10

10 months ago

0.1.11

10 months ago

0.1.12

9 months ago

0.1.13

9 months ago

0.1.14

7 months ago

0.1.15

7 months ago

0.1.8

1 year ago

0.1.9

1 year ago

0.1.7

1 year ago

0.1.4

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.2

2 years ago

0.1.3

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago