Object merging made simple
npm install merge-strategies


> Object merging made simple.
All functions return a new object -they are not mutated-, and take in objects of any type. If they receive scalars instead of Arrays or objects, data will be returned.
* If both defaults and data are objects, they will be shallow merged.
* Keys with undefined values in a data object will acquire their value at defaults.
* Mutations to the returned object won't have an effect over defaults.
* Arrays won't be merged.
``javascript
import { shallow } from 'merge-strategies';
// Returns: { foo: [3, 4], bar: { foo: 'foo' } }
shallow(
{ foo: [1, 2], bar: { baz: 'baz' } },
{ foo: [3, 4], bar: { foo: 'foo' } }
);
`
* If both defaults and data are objects, they will be deep merged.undefined
* Keys with values in a data object will acquire their value at defaults.defaults
* Mutations to the returned object won't have an effect over .
* Arrays won't be merged.
`javascript
import { merge } from 'merge-strategies';
// Returns: { foo: [3, 4], bar: { baz: 'baz', foo: 'foo' } }
merge(
{ foo: [1, 2], bar: { baz: 'baz' } },
{ foo: [3, 4], bar: { foo: 'foo' } },
);
`
* If both defaults and data are objects, they will be deep merged.undefined
* Keys with values in a data object will acquire their value at defaults.defaults
* Mutations to the returned object won't have an effect over .
* Arrays will be concatenated.
`javascript
import { deep } from 'merge-strategies';
// Returns: { foo: [1, 2, 3, 4], bar: { baz: 'baz', foo: 'foo' } }
deep(
{ foo: [1, 2], bar: { baz: 'baz' } },
{ foo: [3, 4], bar: { foo: 'foo' } },
);
``