Skip to content

A library for deep (recursive) merging of Javascript objects

License

Notifications You must be signed in to change notification settings

faressoft/deepmerge

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

deepmerge

Merge the enumerable attributes of two objects deeply.

example

var util = require('util')
var merge = require('deepmerge')

var x = { foo: { bar: 3 },
  array: [ { does: 'work', too: [ 1, 2, 3 ] } ] }
var y = { foo: { baz: 4 },
  quux: 5,
  array: [ { does: 'work', too: [ 4, 5, 6 ] }, { really: 'yes' } ] }

console.log(util.inspect(merge(x, y), false, null))

output:

{ foo: { bar: 3, baz: 4 },
  array: [ { does: 'work', too: [ 1, 2, 3, 4, 5, 6 ] }, { really: 'yes' } ],
  quux: 5 }

methods

var merge = require('deepmerge')

merge(target, source[, options])

Merge two objects target and source deeply, returning a new merged object with the elements from both target and source.

If an element at the same key is present for both target and source, the value from source will appear in the result.

The merge is immutable, so neither target nor source will be modified.

The merge will also merge arrays and array values.

options

options is an optional parameter.

options: {
  array: 'both' // to specify the behavior of array merging, possible values (both, target, source)
}

install

With npm do:

npm install deepmerge

For the browser, you can install with bower:

bower install deepmerge

test

With npm do:

npm test

About

A library for deep (recursive) merging of Javascript objects

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%