merge objects with custom logic
npm install custom-mergeCustom Merge
============
Create a custom merge function
npm install custom-merge
Usage
-----
``javascript
`
var createMerge = require('custom-merge')
, extend = createMerge({ inPlace:true, deep:true, array:'concat', priority:'right' })
, defaults = createMerge({ inPlace:true, deep:false, array:'replace', priority:'left' })
, defaultOptions = { awesome:true, hidden:false }
extend({ a:1, b:2, c:{ d:[1,2] } }, { a:5, c:{ d:[3,4] } })
// { a:5, b:2, c:{ d:[1,2,3,4] } }
defaults({ hidden:true }, defaultOptions)
// { awesome:true, hidden:true }
true
Options
-------
$3
When (default), merges changes into the first argument. When false, merges changes into a clone of the first argument.
true
$3
When (default) merges additional levels. When false, only merges the top level.
'replace'
$3
- (default): When two arrays are to be merged, replace one with the other
'concat'
- : When two arrays are to be merged, concatenate the arrays
'merge'
- : When two arrays are to be merged, merge their corresponding indexes
'right'
$3
- (default): When replacing values, use the rightmost value
'left'`:When replacing values, use the leftmost value
-