3.1.0 • Published 4 years ago
@typemon/merge v3.1.0
Merge -
Installation
$ npm install @typemon/merge
Usage
import { merge } from '@typemon/merge';
Basic
merge(
{ foo: 'bar' },
{ bar: 'foo' },
);
{
foo: 'bar',
bar: 'foo'
}
Advanced
merge(
{
name: 'Adventurer',
level: 7,
items: [
'sword',
],
pet: null,
},
{
items: [
'knife',
'bread',
],
pet: {
name: 'Monster',
level: 3,
eat: (): void => console.log('Yum Yum ...'),
},
},
);
{
name: 'Adventurer',
level: 7,
items: [
'knife',
'bread'
],
pet: {
name: 'Monster',
level: 3,
eat: [Function: eat]
}
}
Logic
- If the previous and current values are objects, but not an array, they are merged.
- If the above conditions are not met, the current value is used.