Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
object-assign-deep
Advanced tools
Allows deep cloning of plain objects that contain primitives, nested plain objects, or nested plain arrays.
Like Object.assign() but deeper. This module is the holy grail of simple object manipulation in JavaScript and it does not resort to using the JSON functions. If you need more power or fine-grained control please take a look at the Object-Extender module.
objectAssignDeep()
now mutates the first argument in the same way Object.assign()
does.This module is to be used with PLAIN objects that contain primitive values ONLY. Every time you misuse this module a kitten dies.. yes you're a kitten killer.
Do not use this module if:
If you need to do something fancy like the above you'll need to write a custom solution for your use case.
You can merge plain objects or clone them:
const objectAssignDeep = require(`object-assign-deep`);
const mergedObjects = objectAssignDeep(target, object1, object2, ...objectN);
const clonedObject = objectAssignDeep({}, originalObject);
Simples!
See the ./examples
directory for a few examples, including one example case that demonstrates why you can't get clever with object cloning.
const objectAssignDeep = require(`object-assign-deep`);
const objectA = {
prop1: `Hello`,
prop2: `World`,
nested: {
bool: true,
super: 123,
still: `here!`,
},
array1: [1, 2, 3],
array2: [4, 5, 6],
};
const objectB = {
prop2: `Universe`,
name: `Josh`,
nested: {
bool: false,
},
array1: null,
};
const objectC = {
location: `United Kingdom`,
name: `Bob`,
nested: {
super: 999,
},
array2: [100, 101, 102],
};
const result = objectAssignDeep(objectA, objectB, objectC);
console.log(`Result:`, result);
/*
* {
* prop1: 'Hello',
* prop2: 'Universe',
* nested: { bool: false, super: 999, still: 'here!' },
* array1: null,
* array2: [100, 101, 102],
* name: 'Bob',
* location: 'United Kingdom'
* }
*/
Merges all the objects together mutating the target
in the process and returning the result.
Merges all the objects together without mutating any of them and returning the entirely new object.
Takes a target, an array of objects to merge in, and an options object which can be used to change the behaviour of the function. The available options are:
Option | Default Value | Description |
---|---|---|
arrayBehaviour | "replace" | By default arrays in later objects will overwrite earlier values, but you can set this to "merge" if you want to concatenate the arrays instead. |
If you need more customisation options please take a look at the Object-Extender module which builds upon Object-Assign-Deep.
FAQs
Allows deep cloning of plain objects that contain primitives, nested plain objects, or nested plain arrays.
The npm package object-assign-deep receives a total of 38,871 weekly downloads. As such, object-assign-deep popularity was classified as popular.
We found that object-assign-deep demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.