Socket
Book a DemoInstallSign in
Socket

deepmerge-alt

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

deepmerge-alt

A library for deep (recursive) merging of Javascript objects

latest
Source
npmnpm
Version
0.3.0
Version published
Maintainers
1
Created
Source

deepmerge

Merge the enumerable attributes of two objects deeply.

The alt version allows for array concat as an option.

https://github.com/theogravity/deepmerge/pull/1

example

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

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(x, y, opts)

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.

options

arrays

  • merge (default) - Replace array values at index. e.g. [1, 2] + [3] => [3, 2]
  • concat - Push value to the bottom of the array. e.g. [1, 2] + [3] => [1, 2, 3]

install

With npm do:

npm install deepmerge-alt

For the browser, you can install with bower:

bower install deepmerge-alt

test

With npm do:

npm test

FAQs

Package last updated on 26 Aug 2016

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