deepmerge
Advanced tools
Comparing version 3.2.1 to 3.3.0
@@ -0,1 +1,5 @@ | ||
# [3.3.0](https://github.com/TehShrike/deepmerge/releases/tag/v3.3.0) | ||
- Enumerable Symbol properties are now copied [#151](https://github.com/TehShrike/deepmerge/pull/151) | ||
# [3.2.1](https://github.com/TehShrike/deepmerge/releases/tag/v3.2.1) | ||
@@ -2,0 +6,0 @@ |
@@ -56,10 +56,22 @@ (function (global, factory) { | ||
function getEnumerableOwnPropertySymbols(target) { | ||
return Object.getOwnPropertySymbols | ||
? Object.getOwnPropertySymbols(target).filter(function(symbol) { | ||
return target.propertyIsEnumerable(symbol) | ||
}) | ||
: [] | ||
} | ||
function getKeys(target) { | ||
return Object.keys(target).concat(getEnumerableOwnPropertySymbols(target)) | ||
} | ||
function mergeObject(target, source, options) { | ||
var destination = {}; | ||
if (options.isMergeableObject(target)) { | ||
Object.keys(target).forEach(function(key) { | ||
getKeys(target).forEach(function(key) { | ||
destination[key] = cloneUnlessOtherwiseSpecified(target[key], options); | ||
}); | ||
} | ||
Object.keys(source).forEach(function(key) { | ||
getKeys(source).forEach(function(key) { | ||
if (!options.isMergeableObject(source[key]) || !target[key]) { | ||
@@ -66,0 +78,0 @@ destination[key] = cloneUnlessOtherwiseSpecified(source[key], options); |
16
index.js
@@ -27,10 +27,22 @@ var defaultIsMergeableObject = require('is-mergeable-object') | ||
function getEnumerableOwnPropertySymbols(target) { | ||
return Object.getOwnPropertySymbols | ||
? Object.getOwnPropertySymbols(target).filter(function(symbol) { | ||
return target.propertyIsEnumerable(symbol) | ||
}) | ||
: [] | ||
} | ||
function getKeys(target) { | ||
return Object.keys(target).concat(getEnumerableOwnPropertySymbols(target)) | ||
} | ||
function mergeObject(target, source, options) { | ||
var destination = {} | ||
if (options.isMergeableObject(target)) { | ||
Object.keys(target).forEach(function(key) { | ||
getKeys(target).forEach(function(key) { | ||
destination[key] = cloneUnlessOtherwiseSpecified(target[key], options) | ||
}) | ||
} | ||
Object.keys(source).forEach(function(key) { | ||
getKeys(source).forEach(function(key) { | ||
if (!options.isMergeableObject(source[key]) || !target[key]) { | ||
@@ -37,0 +49,0 @@ destination[key] = cloneUnlessOtherwiseSpecified(source[key], options) |
The MIT License (MIT) | ||
Copyright (c) 2012 Nicholas Fisher | ||
Copyright (c) 2012 James Halliday, Josh Duff, and other contributors | ||
@@ -5,0 +5,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy |
{ | ||
"author": "Nick Fisher", | ||
"name": "deepmerge", | ||
@@ -13,3 +12,3 @@ "description": "A library for deep (recursive) merging of Javascript objects", | ||
], | ||
"version": "3.2.1", | ||
"version": "3.3.0", | ||
"homepage": "https://github.com/TehShrike/deepmerge", | ||
@@ -16,0 +15,0 @@ "repository": { |
# deepmerge | ||
Merges the enumerable attributes of two or more objects deeply. | ||
Merges the enumerable properties of two or more objects deeply. | ||
> UMD bundle is 587B minified+gzipped | ||
> UMD bundle is 646B minified+gzipped | ||
### Migration from 1.x to 2+ | ||
[***Check out the changes from version 1.x to 2.0.0***](https://github.com/KyleAMathews/deepmerge/blob/master/changelog.md#200) | ||
For the legacy array element-merging algorithm, see [the `arrayMerge` option below](#arraymerge). | ||
## Getting Started | ||
@@ -19,7 +11,7 @@ | ||
<!--js | ||
var merge = require('./') | ||
const merge = require('./') | ||
--> | ||
```js | ||
var x = { | ||
const x = { | ||
foo: { bar: 3 }, | ||
@@ -32,3 +24,3 @@ array: [{ | ||
var y = { | ||
const y = { | ||
foo: { baz: 4 }, | ||
@@ -44,3 +36,3 @@ quux: 5, | ||
var expected = { | ||
const output = { | ||
foo: { | ||
@@ -62,3 +54,3 @@ bar: 3, | ||
merge(x, y) // => expected | ||
merge(x, y) // => output | ||
``` | ||
@@ -108,9 +100,7 @@ | ||
```js | ||
var x = { foo: { bar: 3 } } | ||
var y = { foo: { baz: 4 } } | ||
var z = { bar: 'yay!' } | ||
const foobar = { foo: { bar: 3 } } | ||
const foobaz = { foo: { baz: 4 } } | ||
const bar = { bar: 'yay!' } | ||
var expected = { foo: { bar: 3, baz: 4 }, bar: 'yay!' } | ||
merge.all([x, y, z]) // => expected | ||
merge.all([ foobar, foobaz, bar ]) // => { foo: { bar: 3, baz: 4 }, bar: 'yay!' } | ||
``` | ||
@@ -149,14 +139,14 @@ | ||
function combineMerge(target, source, options) { | ||
const combineMerge = (target, source, options) => { | ||
const destination = target.slice() | ||
source.forEach(function(e, i) { | ||
if (typeof destination[i] === 'undefined') { | ||
source.forEach((item, index) => { | ||
if (typeof destination[index] === 'undefined') { | ||
const cloneRequested = options.clone !== false | ||
const shouldClone = cloneRequested && options.isMergeableObject(e) | ||
destination[i] = shouldClone ? clone(e, options) : e | ||
} else if (options.isMergeableObject(e)) { | ||
destination[i] = merge(target[i], e, options) | ||
} else if (target.indexOf(e) === -1) { | ||
destination.push(e) | ||
const shouldClone = cloneRequested && options.isMergeableObject(item) | ||
destination[index] = shouldClone ? clone(item, options) : item | ||
} else if (options.isMergeableObject(item)) { | ||
destination[index] = merge(target[index], item, options) | ||
} else if (target.indexOf(item) === -1) { | ||
destination.push(item) | ||
} | ||
@@ -163,0 +153,0 @@ }) |
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
22627
197
1
265