パッケージの詳細

deepmerge2

JWo1F21MIT1.0.6

A library for deep (recursive) merging of Javascript objects

merge, deep, deepmerge, shallow

readme

deepmerge2

Merge the enumerable attributes of two objects deeply.

What's the difference between deepmerge and deepmerge2?

Reason of creating this fork is inactivity of original deepmerge plugin. This version has several bug fixes.

example

var util = require('util');
var merge = require('deepmerge2');

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

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

output:

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

methods

var merge = require('deepmerge2');

merge(x, y)

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

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

The merge is immutable, so neither x nor y will be modified.

The merge will also merge arrays and array values.

install

With npm do:

npm install deepmerge2

test

With npm do:

npm test

更新履歴

1.0.6

  • Resolve an issue when null is in an array

1.0.5

  • Deepmerge2 now support a variable number of arguments

1.0.2

  • Fix merge of regular expressions

1.0.1

  • Update tests + readme
  • Fix merge of Dates