$ gnpm install merge
(recursive)? merging of (cloned)? objects.
npm i merge
import merge from 'merge'
<script src="https://cdn.jsdelivr.net/gh/yeikos/js.merge/dist/merge.browser.min.js"></script>
window.merge
merge(clone: boolean, ...items: Object[])
merge(...items: Object[])
merge.recursive(clone: boolean, ...items: Object[])
merge.recursive(...items: Object[])
// Merge
{
var objectA = {}
merge(objectA,
{ value: 1 },
{ str: 'hello world' }
)
var objectB = merge(true, objectA,
{ value: 2 }
)
objectA // { value: 1, str: 'hello world' }
objectB // { value: 2, str: 'hello world' }
}
// Recursive merge
{
var objectA = {}
merge.recursive(objectA,
{ level: { value: 1 } },
{ level: { str: 'hello world' } }
)
var objectB = merge.recursive(true, objectA,
{ level: { value: 2 } }
)
objectA.level // { value: 1, str: 'hello world' }
objectB.level // { value: 2, str: 'hello world' }
}
npm test
./dist/merge.browser.test.html
Copyright 2013 - present © cnpmjs.org | Home |