object-assign-deep
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -75,7 +75,5 @@ 'use strict'; | ||
/* | ||
* Merge all the supplied objects into a single new object, breaking all references, including those of nested objects | ||
* and arrays, and even objects nested inside arrays. The first parameter is not mutated unlike Object.assign(). | ||
* Properties in later objects will always overwrite. | ||
* Does the actual deep merging. | ||
*/ | ||
module.exports = function objectAssignDeep (..._objects) { | ||
function executeDeepMerge (target, _objects = []) { | ||
@@ -85,3 +83,3 @@ // Ensure we have actual objects for each. | ||
const output = {}; | ||
const output = target || {}; | ||
@@ -101,3 +99,4 @@ // Enumerate the objects and their keys. | ||
if (existingValueType !== `undefined`) { | ||
output[key] = objectAssignDeep((existingValueType === `object` ? output[key] : {}), quickCloneObject(value)); | ||
const existingValue = (existingValueType === `object` ? output[key] : {}); | ||
output[key] = executeDeepMerge(null, [existingValue, quickCloneObject(value)]); | ||
} | ||
@@ -128,2 +127,18 @@ else { | ||
} | ||
/* | ||
* Merge all the supplied objects into a single new object, breaking all references, including those of nested objects | ||
* and arrays, and even objects nested inside arrays. The first parameter is not mutated unlike Object.assign(). | ||
* Properties in later objects will always overwrite. | ||
*/ | ||
module.exports = function objectAssignDeep (...objects) { | ||
return executeDeepMerge(null, objects); | ||
}; | ||
/* | ||
* Same as objectAssignDeep() except it mutates the target object by merging everything else into it. | ||
*/ | ||
module.exports.into = function objectAssignDeepInto (target, ...objects) { | ||
return executeDeepMerge(target, objects); | ||
}; |
@@ -10,3 +10,3 @@ { | ||
"name": "object-assign-deep", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Allows deep cloning of plain objects that contain primitives, nested plain objects, or nested plain arrays.", | ||
@@ -20,2 +20,3 @@ "keywords": [ | ||
"copy", | ||
"merge", | ||
"object", | ||
@@ -22,0 +23,0 @@ "array" |
@@ -16,3 +16,3 @@ # Object-Assign-Deep | ||
## Differences to Object.Assign() | ||
This module does NOT mutate the first parameter like Object.assign(), instead it always returns a new object with all the properties copied across and the parameters left intact. | ||
By default this module does NOT mutate the first parameter like Object.assign(), instead it always returns a new object with all the properties copied across and the parameters left intact. You can use the objectAssignDeep.into() function to make the first parameter the target and mutate it. | ||
@@ -30,2 +30,10 @@ ## Quick Start | ||
To make the first parameter the target and mutate it like Object.assign(): | ||
```javascript | ||
const objectAssignDeep = require(`object-assign-deep`); | ||
objectAssignDeep.into(target, object1, object2, ...objectN); | ||
``` | ||
Simples! | ||
@@ -32,0 +40,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
44428
11
278
90
0
5