Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
object-assign | 4.1.1 | 2.61 kB | MIT | prod |
The "object-assign" is a popular npm package that works as an ES2015 Object.assign()
ponyfill. This JavaScript utility function assigns enumerable own properties of the source objects to the target object and returns the target object. If multiple source objects are provided, later ones will overwrite those of earlier ones. The function also ignores null and undefined source objects.
The "object-assign" package can be utilized by first installing the package using npm using the command npm install --save object-assign
. After successful installation, you can then require the function in your JavaScript code. Here's an example:
const objectAssign = require('object-assign');
// single source
let result = objectAssign({foo: 0}, {bar: 1});
console.log(result); // Outputs: {foo: 0, bar: 1}
// multiple sources
result = objectAssign({foo: 0}, {bar: 1}, {baz: 2});
console.log(result); // Outputs: {foo: 0, bar: 1, baz: 2}
// overwriting equal keys
result = objectAssign({foo: 0}, {foo: 1}, {foo: 2});
console.log(result); // Outputs: {foo: 2}
// ignores null and undefined sources
result = objectAssign({foo: 0}, null, {bar: 1}, undefined);
console.log(result); // Outputs: {foo: 0, bar: 1}
The documentation for the "object-assign" npm package can be found within its README file on its official GitHub repository, accessible via the following URL: https://github.com/sindresorhus/object-assign
. The documentation includes details about the package such as how to install and use it, its application programming interface (API), related resources, and its license information.