Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
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
Ponyfill: A polyfill that doesn't overwrite the native method
$ 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 33,399,544 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.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.