Socket
Socket
Sign inDemoInstall

simple-object-mixin

Package Overview
Dependencies
1
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    simple-object-mixin

Simple mixin is the simplest implementation for a mixin, copying an object's properties onto another


Version published
Weekly downloads
1
decreased by-50%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

Simple object mixin

Simple mixin is the simplest implementation for a mixin, copying an object's properties onto another. It has an option for specifying if duplicated properties can be replaced or not in the target object. Use https://github.com/WebReflection/object-mixin instead of this module if you can, it's better to use built-in features or their polyfills. It will not copy the properties from the prototype chain.

Installation

npm install simple-object-mixin

How to use

Require simple-mixin:

var mixin = require("simple-object-mixin");

Use it with an array:

var objectSource = {
  "b": 30,
  "c": 40
};

var objectDestination = {
  "a": 10,
  "b": 20
};

var returnedObject = mixin(objectSource, objectDestination);

returnedObject === objectDestination;
JSON.stringify(objectDestination); //{"a":10,"b":"30", "c":40}

By default, the properties from source are copied onto destination. If there's a duplicated property, it will be replaced. If you don't want the new value to override the existing value, you can use the dontOverride option:

var returnedObject = mixin(objectSource, objectDestination, true /* don't override */);

returnedObject === objectDestination;
JSON.stringify(objectDestination); //{"a":10,"b":"20", "c":40} the value for "b" will be preserved

LICENSE

MIT

Keywords

FAQs

Last updated on 31 Mar 2014

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc