🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

map-merge

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

map-merge

apply a map function to merge a pair of deep data structures

1.1.0
latest
Source
npm
Version published
Weekly downloads
15K
-38.84%
Maintainers
1
Weekly downloads
 
Created
Source

map-merge

deep merge two objects with a rule. A new object is always returned.

I fear this may be a haskelly thing, I suspect it might be an applicative functor.

almost the same module as deep-merge but not quite.

Example


var merge = require('map-merge')

merge(a, b, function (av, bv) {
  //use the value from b if a's corrisponding value is null/undefined
  return bv == null ? av : bv
  // btw, this is the default merge rule.
})

Objects {}

objects are merged by their keys, first all the keys in the left object are added, then any keys in the right object which are not in the left.

This determins the order the keys appear in.

var merge = require('map-merge')

var a = {
  a: 'apple',
  b: 'banana',
  d: 'durian'
}
var b = {
  b: 'banana',
  c: 'cherry'
  e: 'elderberry'
}

var c = merge(a, b)

the order of the keys in c will depend on the order in a and b


{
  a: 'apple',
  b: 'banana',
  d: 'durian',
  c: 'cherry',
  e: 'elderberry'
}

License

MIT

FAQs

Package last updated on 26 Nov 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts