Socket
Socket
Sign inDemoInstall

object-assign

Package Overview
Dependencies
0
Maintainers
3
Versions
17
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    object-assign

ES2015 `Object.assign()` ponyfill


Version published
Weekly downloads
40M
increased by2.56%
Maintainers
3
Install size
6.30 kB
Created
Weekly downloads
 

Package description

What is object-assign?

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.

What are object-assign's main functionalities?

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);

Other packages similar to object-assign

Readme

Source

object-assign Build Status

ES2015 Object.assign() ponyfill

Use the built-in

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.

Install

$ npm install --save object-assign

Usage

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}

API

objectAssign(target, [source, ...])

Assigns enumerable own properties of source objects to the target object and returns the target object. Additional source objects will overwrite previous ones.

Resources

License

MIT © Sindre Sorhus

Keywords

FAQs

Last updated on 16 Jan 2017

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc