Socket
Book a DemoInstallSign in
Socket

absorb

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

absorb

A recursive deep object merge utility function

1.0.1
latest
Source
npmnpm
Version published
Weekly downloads
4
-78.95%
Maintainers
1
Weekly downloads
 
Created
Source

Absorb

A recursive deep object merge utility function. ObjectParam1 absorbs properties from ObjectParam2

Installation

npm install absorb

Usage

var absorb = require('absorb');
var obj1, obj2, obj3;

obj1 = { foo: 123, bar: 456 };
obj2 = { bar: 123, key: 'value' }

absorb(obj1, obj2);

console.log(obj1); // Output: { foo: 123, bar: 123, key: 'value' }

You can use the optional third parameter set to true to make a clone.

obj1 = { foo: 123, bar: 456 };
obj3 = absorb(obj1, obj2, true);

console.log(obj1); // Output: { foo: 123, bar: 456 }
console.log(obj3); // Output: { foo: 123, bar: 123, key: 'value' }

You can use the optional fourth parameter set to true to only add properties that are not already set in the destination object. Note: This will not overwrite sub-properties in deep objects, however it will add new ones

obj1 = { person: {name: 'Patrick', lastname: 'Murphy'}, career: 'Software Engineer'};
obj2 = { person: {name: 'Jered', height: '6`1'}, career: 'Investment Banker', hobbies: 'photography'};
absorb(obj1, obj2, false, true);

console.log(obj1); // Output: { person: {name: 'Patrick', lastname: 'Murphy', height: '6`1'}, career: 'Software Engineer', hobbies: 'photography'};

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.

Release History

  • 1.0.1 Fix cloning not functioning correctly Issue reported on github
  • 1.0.0 Add PreserveObject parameter, allowing option to only merge if object 1 does not contain key
  • 0.1.0 Initial release

Keywords

merge

FAQs

Package last updated on 25 Aug 2015

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.