This package has been deprecated

Author message:

Instead, you should use 'npmjs.com/deepmerge'

nanomerge

0.2.0 • Public • Published

Nano Merge

Build status License Maintenance intention for this crate GitHub package version Code style: prettier

Tiny universal/isomorphic library for intelligently deep-merging objects

var nanomerge = require('nanomerge');
 
var merger = nanomerge({
  strategy: { array: 'merge' }
});
 
//=> { a: [{ a: 1 }, { a: 3 }], b: 'It works!' }
merger({ a: [{ a: 2 }, { a: 3 }] }, { a: [{ a: 1 }] }, { 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 = require('nanomerge');
 
nanomerge({ a: 1, b: 2 }, { a: 2, c: 3 }, { b: 5, d: 7 }); //=> { 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 = require('nanomerge/merge');
 
var myCustomMerger = new Merge({ /* options */ });
 
myCustomMerger.merge({ a: 1 }, { b: 2 }) //=> { 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.
 
         is: function(el) {  }, // 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
           simple: function(merger, a, b) {},
         }
       },
       /* You custom types */
     ],
   },
};

Readme

Keywords

none

Package Sidebar

Install

npm i nanomerge

Weekly Downloads

52

Version

0.2.0

License

MIT

Unpacked Size

43.7 kB

Total Files

17

Last publish

Collaborators

  • nikolay_govorov