Socket
Socket
Sign inDemoInstall

assignment

Package Overview
Dependencies
0
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    assignment

Assign property objects onto other objects, recursively


Version published
Weekly downloads
21K
decreased by-6.53%
Maintainers
1
Install size
7.24 kB
Created
Weekly downloads
 

Readme

Source

assignment

Assign property objects onto other objects, recursively

Footprint for assignment sits at around 400 bytes browserified, minified, and gzipped.

Install

npm install assignment --save

assignment(a, b, c, ...)

Assigns every property of b onto a. If the an object already exists on a that has one of b's properties, then assignment(a.prop, b.prop) will assign all child properties of b.prop onto a.prop. This happens recursively.

Returns a.

Examples

It doesn't matter how many objects you hand to assignment, they will all be collapsed into the first one.

assignment(
  { name: 'mordecai' },
  { name: 'eileen' },
  { name: 'rigby' }
);
// <- { name: 'rigby' }

Object's get replaced recursively, property by property. Note that for any given property prop, you'll get back whatever the prototype was for the first prop that existed in a.

assignment(
  { character: { name: 'mordecai' } },
  { character: { color: 'red' } },
  { character: { name: 'margaret' } }
);
// <- { character: { name: 'margaret', color: 'red' } }

Note that arrays don't receive any special treatment. Typically, you want arrays to be replaced.

assignment(
  { characters: ['mordecai', 'margaret'] },
  { characters: ['rigby', 'eileen'] }
);
// <- { characters: ['rigby', 'eileen'] }

License

MIT

FAQs

Last updated on 30 Dec 2016

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