New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

assignment

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

assignment

Assign property objects onto other objects, recursively

  • 2.2.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
20K
decreased by-30.63%
Maintainers
1
Weekly downloads
 
Created
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

Package last updated on 30 Dec 2016

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc