murge

0.1.2 • Public • Published

Murge

A fork of merge. Merge multiple objects into one, optionally creating a new cloned object. Similar to _.extend or jQuery.extend but more flexible. Works in Node.js and the browser.

Credit goes to yeikos for creating this module (github, npm). This one passes all the same tests (at time of the fork), but contains some changes I felt were necessary:

  1. It only merges own properties, ignoring ones from the prototype chain. This would likely break some of the many dependents on the other version and is the main reason for this fork.
  2. It contains perf improvements which have also been submitted to the original module as a pull request, but not yet accepted as of this writing.
  3. It supports RequireJS/AMD, which the other does not as of this writing.

Node.js Usage

$ npm install murge
var murge = require('murge');
 
// merge an object (modifies the first object)
console.log(murge({one:'hello'}, {two: 'world'}));
// -> {"one": "hello", "two": "world"}
 
// merge an object (does not modify the first object)
console.log(murge(null, {one:'hello'}, {two: 'world'}));
// -> {"one": "hello", "two": "world"}
 
// deep clone an object
var original = { x: { y: 1 } };
var cloned = murge(true, original);
cloned.x.y++;
console.log(original.x.y, cloned.x.y);
// -> 1, 2
 
// deep merge an object
var obj1 = { x: { y: 2 } }
var obj2 = { x: { z: 3 } }
var merged = murge(true, obj1, obj2);
console.log(merged);
// -> { x: { y: 2, z: 3 } }

RequireJS/AMD usage

require(['./murge'], function(murge){
  murge(obj1, obj2)
})

Browser Usage

<script src="path/to/murge.js"></script>
<script>
  window.murge(ob1, ob2)
</script> 

Tests

$ npm test

Package Sidebar

Install

npm i murge

Weekly Downloads

0

Version

0.1.2

License

MIT

Last publish

Collaborators

  • greim