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
Advanced tools
The object-assign npm package is a polyfill for the Object.assign() method, which is used to copy the values of all enumerable own properties from one or more source objects to a target object. It will return the target object with properties and values copied from the source objects.
Copying properties
This feature allows you to copy the properties from one or more source objects to a target object. The target object in this example ends up being { a: 1, b: 2 }.
var target = { a: 1 }; var source = { b: 2 }; var returnedTarget = objectAssign(target, source);
Merging multiple sources
object-assign can merge properties from multiple source objects into a single target object. The target object in this example ends up being { a: 1, b: 2, c: 3 }.
var target = { a: 1 }; var source1 = { b: 2 }; var source2 = { c: 3 }; var returnedTarget = objectAssign(target, source1, source2);
Overwriting properties
If the source and target object have the same key, the property in the target object will be overwritten by the property from the source object. The target object in this example ends up being { a: 1, b: 2, c: 2 }.
var target = { a: 1, b: 1 }; var source = { b: 2, c: 2 }; var returnedTarget = objectAssign(target, source);
The 'extend' package is similar to object-assign in that it is used to copy properties from one or more source objects to a target object. However, 'extend' can perform a deep copy where nested objects and arrays are also recursively copied, unlike object-assign which only performs a shallow copy.
lodash.assign is a method from the Lodash library that offers similar functionality to object-assign. It copies own enumerable properties from source objects to a target object. Lodash provides a more extensive set of utilities for working with objects, arrays, and other types, and lodash.assign is part of this larger toolkit.
deep-assign is an npm package that also copies properties from source objects to a target object, similar to object-assign. The key difference is that deep-assign supports deep copying, meaning that it can copy properties at all levels of object nesting, not just the top level.
ES2015
Object.assign()
ponyfill
Node.js 4 and up, as well as every evergreen browser (Chrome, Edge, Firefox, Opera, Safari),
support Object.assign()
:tada:. If you target only those environments, then by all
means, use Object.assign()
instead of this package.
$ npm install --save object-assign
const objectAssign = require('object-assign');
objectAssign({foo: 0}, {bar: 1});
//=> {foo: 0, bar: 1}
// multiple sources
objectAssign({foo: 0}, {bar: 1}, {baz: 2});
//=> {foo: 0, bar: 1, baz: 2}
// overwrites equal keys
objectAssign({foo: 0}, {foo: 1}, {foo: 2});
//=> {foo: 2}
// ignores null and undefined sources
objectAssign({foo: 0}, null, {bar: 1}, undefined);
//=> {foo: 0, bar: 1}
Assigns enumerable own properties of source
objects to the target
object and returns the target
object. Additional source
objects will overwrite previous ones.
Object.assign()
MIT © Sindre Sorhus
FAQs
ES2015 `Object.assign()` ponyfill
The npm package object-assign receives a total of 35,118,191 weekly downloads. As such, object-assign popularity was classified as popular.
We found that object-assign demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers 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.