Nano Merge
Tiny universal/isomorphic library for intelligently deep-merging objects
var nanomerge = ; var merger = ; //=> { a: [{ a: 1 }, { a: 3 }], b: 'It works!' };
-
Small. Only 800 bytes (minified and gzipped). Only "nano" dependencies. It uses Size Limit to keep the size under control.
-
Easy. Everything works out of the box. Just plug and play.
-
Customizability. But, if you need to, everything can be customized.
The lib supports Node.js and all browsers starting from IE 11.
Install
npm install --save nanomerge
Usage
Default settings
var nanomerge = ; ; //=> { a: 2, b: 5, c: 3, d: 7 }
Custom merge mechanism
If passed only one parameter, it is interpreted as configuration data, and a customized merge function is returned.
var Merge = ; var myCustomMerger = /* options */ ; myCustomMerger //=> { a: 1, b: 2 }
Configuration
var config = /** * The strategy specifies how we should handle a particular type */ strategy: array: 'replace' // string: merge | replace | concat object: 'deep' // string: deep primitive: 'default' // string: default /** * Custom types allow you to create intelligent mechanisms for enterprises */ types: mode: 'add' // string: add | replace list: name: "array" // Type name. The name must be unique. { } // Function checking whether an element is an object of type default: "simple" // The name of the mechanism of merging the default merge: // The object contains all the mechanisms for draining this type {} /* You custom types */ ;