1.0.3 • Published 5 years ago

mergify v1.0.3

Weekly downloads
5
License
ISC
Repository
github
Last release
5 years ago

Mergify

npm version build status coverage status

const merge = require('mergify');

class D { constructor(o) { Object.assign(this, o); } }

merge(
	{a: {x: 1}, b: [2, 4], c: ['x'], d: new D({x: 5}), e: new Set([1, 3])}, 
	{a: {y: 1}, b: {1: 3}, c: ['y'], d: new D({y: 5}), e: new Set([2, 3])}
) 

// { a: {x: 1, y: 1}, b: [ 2, 3 ], c: ['x', 'y'], d: new D({y: 5}), e: new Set([1, 3, 2]) }
  • merges plain objects deeply
  • handles Sets and Maps (native ones or immutablesjs, with duck-typing)
  • concatenates arrays
  • works well with configurations, like webpack ones

Similar to lodash's mergeWith, but with some nuances (search for 'lodash')

const {mergeWith} = require('lodash');
const merge = (...o) => o.reduce((a, b) => 
	mergeWith(a, b, (a, b) => Array.isArray(a) && Array.isArray(b) ? [...a, ...b] : undefined)
);