Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

putil-merge

Package Overview
Dependencies
Maintainers
1
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

putil-merge

Lightweight solution for merging multiple objects into one. Also it supports deep merge and deep clone

  • 1.1.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
53K
decreased by-11.58%
Maintainers
1
Weekly downloads
 
Created
Source

putil-merge

NPM Version NPM Downloads Build Status Test Coverage Dependencies DevDependencies

A 'swiss army knife' solution for merging multiple objects into one. It supports deep merge, cloning objects, copying descriptors and filtering.

Installation

$ npm install putil-merge --save

Usage

merge([config], target, [source])

  • config [Object]
    • deep [Boolean]: If true, it performs deep merge operation.
    • clone [Boolean]: If true, it clones objects except setting references
    • descriptor [Boolean]: If true, it copies descriptors
    • filter [Function(obj, key, value)]
  • target [Object]
  • source [Object|Array<Object>]

Sequential calling

It supports sequential calling style.

merge.(option).(option)...(target, source)

Etc:

merge(target, source)

merge.deep(target, source)

merge.deep.clone(target, source)

merge.clone.deep(target, source)

merge.descriptor(target, source)

merge.deep.descriptor(target, [source1, source2])

merge.clone.descriptor(target, source)

merge.deep.clone.descriptor(target, [source1, source2])

merge.deep.clone.descriptor(target, source)

merge.clone.deep.descriptor(target, source)

merge.descriptor.clone.deep(target, source)

merge.descriptor.filter(filterfn)(target, source)

Examples

Merge source object over target object:

const a = {prm1: 1, prm2: 2};
const b = {prm1: 11, prm3: [1, 2, 3, 4]};
var merged = merge(a, b);

Clone any object:

const a = {prm1: 1, prm2: { prm3: 3}};
var cloned = merge.clone(a);
var deepCloned = merge.deep.clone(a);

Merge source object over target object with custom filtering:

var a = {id: 1};
var b = {name: 'John', surname: 'Wick'};
var merged = merge.deep.filter(function(o,k,v){
  return k === 'name';  
})(target, source);

Node Compatibility

  • node >= 0.10;

License

MIT

Keywords

FAQs

Package last updated on 23 Sep 2017

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