Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

object-assign-deep

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

object-assign-deep - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

examples/mergeIntoTest.js

27

objectAssignDeep.js

@@ -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 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc