merge-concat
Merge an array of objects and concatenate values based on a function
install
$ npm install merge-concat
usage
var merge = var data = a:'red' b:'blue' b:'green' var flat = consoledirflat
This would print
a:'red' b:'green'
concatfn
You can supply a second function that decides on how to handle overwrites
For example - if a value starts with 'b' we can ensure it is never overwritten:
var flat = consoledirflat
This would print
a:'red' b:'blue'
This lets you concatenate previous values based on custom logic:
var flat = consoledirflat
This would print
a:'red' b:'blue,green'
api
merge(arr, function(prev, next, field){})
Get an object that merges the properties of the provided array - later objects take precedence.
If the concatfn is defined, it is called with the previous
, next
and field
variables for each override.
The normal behaviour is to return next
but you can use custom logic to decide how things are joined.
licence
MIT