object-merge
Advanced tools
Comparing version 2.3.0 to 2.4.0
@@ -63,9 +63,37 @@ (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
*/ | ||
function ObjectMergeOptions(opts) { | ||
'use strict'; | ||
opts = opts || {}; | ||
this.depth = opts.depth || false; | ||
// circular ref check is true unless explicitly set to false | ||
// ignore the jslint warning here, it's pointless. | ||
this.throwOnCircularRef = 'throwOnCircularRef' in opts && opts.throwOnCircularRef === false ? false : true; | ||
} | ||
/*jslint unparam:true*/ | ||
/** | ||
* Creates a new options object suitable for use with objectMerge. | ||
* @param {Object} [opts] An object specifying the options. | ||
* @returns {ObjectMergeOptions} Returns an instance of ObjectMergeOptions | ||
* to be used with objectMerge. | ||
*/ | ||
function createOptions(opts) { | ||
'use strict'; | ||
var argz = Array.prototype.slice.call(arguments, 0); | ||
argz.unshift(null); | ||
var F = ObjectMergeOptions.bind.apply(ObjectMergeOptions, argz); | ||
return new F(); | ||
} | ||
/*jslint unparam:false*/ | ||
/** | ||
* Merges JavaScript objects recursively without altering the objects merged. | ||
* @author <a href="mailto:matthewkastor@gmail.com">Matthew Kastor</a> | ||
* @param {ObjectMergeOptions} [opts] An options object created by | ||
* objectMerge.createOptions. Options must be specified as the first argument | ||
* and must be an object created with createOptions or else the object will | ||
* not be recognized as an options object and will be merged instead. | ||
* @param {Object} shadows [[shadows]...] One or more objects to merge. Each | ||
* argument given will be treated as an object to merge. Each object overwrites | ||
* the previous objects descendant properties if the property name matches. If | ||
* objects properties are objects they will be merged recursively as well. | ||
* argument given will be treated as an object to merge. Each object | ||
* overwrites the previous objects descendant properties if the property name | ||
* matches. If objects properties are objects they will be merged recursively | ||
* as well. | ||
* @returns {Object} Returns a single merged object composed from clones of the | ||
@@ -121,3 +149,6 @@ * input objects. | ||
var cloneFunction = require('clone-function'); | ||
shadows = Array.prototype.slice.call(arguments, 0); | ||
// this is the queue of visited objects / properties. | ||
var visited = []; | ||
// various merge options | ||
var options = {}; | ||
// gets the sequential trailing objects from array. | ||
@@ -155,5 +186,4 @@ function getShadowObjects(shadows) { | ||
} | ||
// this is the queue of visited objects / properties. | ||
var visited = []; | ||
function objectMergeRecursor(shadows) { | ||
// checks for circular references | ||
function circularReferenceCheck(shadows) { | ||
// if any of the current objects to process exist in the queue | ||
@@ -166,40 +196,60 @@ // then throw an error. | ||
}); | ||
// if none of the current objects were in the queue then add references | ||
// to the queue. | ||
// if none of the current objects were in the queue | ||
// then add references to the queue. | ||
visited = visited.concat(shadows); | ||
function main(shadows) { | ||
var out = getOutputObject(shadows); | ||
/*jslint unparam:true */ | ||
function shadowHandler(val, prop, shadow) { | ||
if (out[prop]) { | ||
out[prop] = objectMergeRecursor([ | ||
out[prop], | ||
shadow[prop] | ||
]); | ||
} else { | ||
out[prop] = objectMergeRecursor([shadow[prop]]); | ||
} | ||
} | ||
function main(shadows) { | ||
var out = getOutputObject(shadows); | ||
/*jslint unparam: true */ | ||
// recursor defined below. Dougie removed the intelligent suppression of | ||
// this warning, probably because of functions that reference each other. | ||
// So, you're stuck with making sure this isn't a mistake every time you | ||
// use his linter. | ||
function shadowHandler(val, prop, shadow) { | ||
if (out[prop]) { | ||
out[prop] = objectMergeRecursor([ | ||
out[prop], | ||
shadow[prop] | ||
]); | ||
} else { | ||
out[prop] = objectMergeRecursor([shadow[prop]]); | ||
} | ||
/*jslint unparam:false */ | ||
function shadowMerger(shadow) { | ||
objectForeach(shadow, shadowHandler); | ||
} | ||
// short circuits case where output would be a primitive value | ||
// anyway. | ||
if (out instanceof Object) { | ||
// only merges trailing objects since primitives would wipe out | ||
// previous objects, as in merging {a:'a'}, 'a', and {b:'b'} | ||
// would result in {b:'b'} so the first two arguments | ||
// can be ignored completely. | ||
var relevantShadows = getShadowObjects(shadows); | ||
relevantShadows.forEach(shadowMerger); | ||
} | ||
return out; | ||
} | ||
/*jslint unparam:false */ | ||
function shadowMerger(shadow) { | ||
objectForeach(shadow, shadowHandler); | ||
} | ||
// short circuits case where output would be a primitive value | ||
// anyway. | ||
if (out instanceof Object) { | ||
// only merges trailing objects since primitives would wipe out | ||
// previous objects, as in merging {a:'a'}, 'a', and {b:'b'} | ||
// would result in {b:'b'} so the first two arguments | ||
// can be ignored completely. | ||
var relevantShadows = getShadowObjects(shadows); | ||
relevantShadows.forEach(shadowMerger); | ||
} | ||
return out; | ||
} | ||
function objectMergeRecursor(shadows) { | ||
if (options.throwOnCircularRef === true) { | ||
circularReferenceCheck(shadows); | ||
} | ||
return main(shadows); | ||
} | ||
// determines whether an options object was passed in and | ||
// uses it if present | ||
// ignore the jslint warning here too. | ||
if (arguments[0] instanceof ObjectMergeOptions) { | ||
options = arguments[0]; | ||
shadows = Array.prototype.slice.call(arguments, 1); | ||
} else { | ||
options = createOptions(); | ||
shadows = Array.prototype.slice.call(arguments, 0); | ||
} | ||
return objectMergeRecursor(shadows); | ||
} | ||
objectMerge.createOptions = createOptions; | ||
module.exports = objectMerge; | ||
},{"clone-function":2,"object-foreach":3}]},{},[1]) | ||
//@ sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZ2VuZXJhdGVkLmpzIiwic291cmNlcyI6WyJDOi9Vc2Vycy9rYXN0b3IvRG9jdW1lbnRzL0dpdEh1Yi9vYmplY3QtbWVyZ2UvZGV2L2Jyb3dzZXJNYWluLmpzIiwiQzovVXNlcnMva2FzdG9yL0RvY3VtZW50cy9HaXRIdWIvb2JqZWN0LW1lcmdlL25vZGVfbW9kdWxlcy9jbG9uZS1mdW5jdGlvbi9zcmMvY2xvbmUtZnVuY3Rpb24uanMiLCJDOi9Vc2Vycy9rYXN0b3IvR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2BiJyxcclxuICogICAgICBjIDoge1xyXG4gKiAgICAgICAgICBkIDogJ2BkJ1xyXG4gKiAgICAgIH1cclxuICogIH07XHJcbiAqICB2YXIgeiA9IHtcclxuICogICAgICBhIDoge1xyXG4gKiAgICAgICAgICBiIDogJ2BgYidcclxuICogICAgICB9LFxyXG4gKiAgICAgIGZ1biA6IGZ1bmN0aW9uIGZvbyAoKSB7XHJcbiAqICAgICAgICAgIHJldHVybiAnZm9vJztcclxuICogICAgICB9LFxyXG4gKiAgICAgIGFwcyA6IEFycmF5LnByb3RvdHlwZS5zbGljZVxyXG4gKiAgfTtcclxuICogIHZhciBvdXQgPSBvYmplY3RNZXJnZSh4LCB5LCB6KTtcclxuICogIC8vIG91dC5hIHdpbGwgYmUge1xyXG4gKiAgLy8gICAgICAgICBiIDogJ2BgYidcclxuICogIC8vICAgICB9XHJcbiAqICAvLyBvdXQuYiB3aWxsIGJlICdgYidcclxuICogIC8vIG91dC5jIHdpbGwgYmUge1xyXG4gKiAgLy8gICAgICAgICBkIDogJ2BkJyxcclxuICogIC8vICAgICAgICAgZSA6ICdlJyxcclxuICogIC8vICAgICAgICAgZiA6IHtcclxuICogIC8vICAgICAgICAgICAgIGcgOiAnZydcclxuICogIC8vICAgICAgICAgfVxyXG4gKiAgLy8gICAgIH1cclxuICogIC8vIG91dC5mdW4gd2lsbCBiZSBhIGNsb25lIG9mIHouZnVuXHJcbiAqICAvLyBvdXQuYXBzIHdpbGwgYmUgZXF1YWwgdG8gei5hcHNcclxuICovXHJcbmZ1bmN0aW9uIG9iamVjdE1lcmdlKHNoYWRvd3MpIHtcclxuICAgICd1c2Ugc3RyaWN0JztcclxuICAgIHZhciBvYmplY3RGb3JlYWNoID0gcmVxdWlyZSgnb2JqZWN0LWZvcmVhY2gnKTtcclxuICAgIHZhciBjbG9uZUZ1bmN0aW9uID0gcmVxdWlyZSgnY2xvbmUtZnVuY3Rpb24nKTtcclxuICAgIHNoYWRvd3MgPSBBcnJheS5wcm90b3R5cGUuc2xpY2UuY2FsbChhcmd1bWVudHMsIDApO1xyXG4gICAgLy8gZ2V0cyB0aGUgc2VxdWVudGlhbCB0cmFpbGluZyBvYmplY3RzIGZyb20gYXJyYXkuXHJcbiAgICBmdW5jdGlvbiBnZXRTaGFkb3dPYmplY3RzKHNoYWRvd3MpIHtcclxuICAgICAgICB2YXIgb3V0ID0gc2hhZG93cy5yZWR1Y2UoZnVuY3Rpb24gKGNvbGxlY3Rvciwgc2hhZG93KSB7XHJcbiAgICAgICAgICAgICAgICBpZiAoc2hhZG93IGluc3RhbmNlb2YgT2JqZWN0KSB7XHJcbiAgICAgICAgICAgICAgICAgICAgY29sbGVjdG9yLnB1c2goc2hhZG93KTtcclxuICAgICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICAgICAgY29sbGVjdG9yID0gW107XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICByZXR1cm4gY29sbGVjdG9yO1xyXG4gICAgICAgICAgICB9LCBbXSk7XHJcbiAgICAgICAgcmV0dXJuIG91dDtcclxuICAgIH1cclxuICAgIC8vIGdldHMgZWl0aGVyIGEgbmV3IG9iamVjdCBvZiB0aGUgcHJvcGVyIHR5cGUgb3IgdGhlIGxhc3QgcHJpbWl0aXZlIHZhbHVlXHJcbiAgICBmdW5jdGlvbiBnZXRPdXRwdXRPYmplY3Qoc2hhZG93cykge1xyXG4gICAgICAgIHZhciBvdXQ7XHJcbiAgICAgICAgdmFyIGxhc3RTaGFkb3cgPSBzaGFkb3dzW3NoYWRvd3MubGVuZ3RoIC0gMV07XHJcbiAgICAgICAgaWYgKGxhc3RTaGFkb3cgaW5zdGFuY2VvZiBBcnJheSkge1xyXG4gICAgICAgICAgICBvdXQgPSBbXTtcclxuICAgICAgICB9IGVsc2UgaWYgKGxhc3RTaGFkb3cgaW5zdGFuY2VvZiBGdW5jdGlvbikge1xyXG4gICAgICAgICAgICB0cnkge1xyXG4gICAgICAgICAgICAgICAg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GN1cnJlbnQgb2JqZWN0cyB3ZXJlIGluIHRoZSBxdWV1ZSB0aGVuIGFkZCByZWZlcmVuY2VzXHJcbiAgICAgICAgLy8gdG8gdGhlIHF1ZXVlLlxyXG4gICAgICAgIHZpc2l0ZWQgPSB2aXNpdGVkLmNvbmNhdChzaGFkb3dzKTtcclxuICAgICAgICBmdW5jdGlvbiBtYWluKHNoYWRvd3MpIHtcclxuICAgICAgICAgICAgdmFyIG91dCA9IGdldE91dHB1dE9iamVjdChzaGFkb3dzKTtcclxuICAgICAgICAgICAgLypqc2xpbnQgdW5wYXJhbTp0cnVlICovXHJcbiAgICAgICAgICAgIGZ1bmN0aW9uIHNoYWRvd0hhbmRsZXIodmFsLCBwcm9wLCBzaGFkb3cpIHtcclxuICAgICAgICAgICAgICAgIGlmIChvdXRbcHJvcF0pIHtcclxuICAgICAgICAgICAgICAgICAgICBvdXRbcHJvcF0gPSBvYmplY3RNZXJnZVJlY3Vyc29yKFtcclxuICAgICAgICAgICAgICAgICAgICAgICAgb3V0W3Byb3BdLFxyXG4gICAgICAgICAgICAgICAgICAgICAgICBzaGFkb3dbcHJvcF1cclxuICAgICAgICAgICAgICAgICAgICBdKTtcclxuICAgICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICAgICAgb3V0W3Byb3BdID0gb2JqZWN0TWVyZ2VSZWN1cnNvcihbc2hhZG93W3Byb3BdXSk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgLypqc2xpbnQgdW5wYXJhbTpmYWxzZSAqL1xyXG4gICAgICAgICAgICBmdW5jdGlvbiBzaGFkb3dNZXJnZXIoc2hhZG93KSB7XHJcbiAgICAgICAgICAgICAgICBvYmplY3RGb3JlYWNoKHNoYWRvdywgc2hhZG93SGFuZGxlcik7XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgLy8gc2hvcnQgY2lyY3VpdHMgY2FzZSB3aGVyZSBvdXRwdXQgd291bGQgYmUgYSBwcmltaXRpdmUgdmFsdWVcclxuICAgICAgICAgICAgLy8gYW55d2F5LlxyXG4gICAgICAgICAgICBpZiAob3V0IGluc3RhbmNlb2YgT2JqZWN0KSB7XHJcbiAgICAgICAgICAgICAgICAvLyBvbmx5IG1lcmdlcyB0cmFpbGluZyBvYmplY3RzIHNpbmNlIHByaW1pdGl2ZXMgd291bGQgd2lwZSBvdXRcclxuICAgICAgICAgICAgICAgIC8vIHByZXZpb3VzIG9iamVjdHMsIGFzIGluIG1lcmdpbmcge2E6J2EnfSwgJ2EnLCBhbmQge2I6J2InfVxyXG4gICAgICAgICAgICAgICAgLy8gd291bGQgcmVzdWx0IGluIHtiOidiJ30gc28gdGhlIGZpcnN0IHR3byBhcmd1bWVudHNcclxuICAgICAgICAgICAgICAgIC8vIGNhbiBiZSBpZ25vcmVkIGNvbXBsZXRlbHkuXHJcbiAgICAgICAgICAgICAgICB2YXIgcmVsZXZhbnRTaGFkb3dzID0gZ2V0U2hhZG93T2JqZWN0cyhzaGFkb3dzKTtcclxuICAgICAgICAgICAgICAgIHJlbGV2YW50U2hhZG93cy5mb3JFYWNoKHNoYWRvd01lcmdlcik7XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgcmV0dXJuIG91dDtcclxuICAgICAgICB9XHJcbiAgICAgICAgcmV0dXJuIG1haW4oc2hhZG93cyk7XHJcbiAgICB9XHJcbiAgICByZXR1cm4gb2JqZWN0TWVyZ2VSZWN1cnNvcihzaGFkb3dzKTtcclxufVxyXG5tb2R1bGUuZXhwb3J0cyA9IG9iamVjdE1lcmdlOyJdfQ== | ||
//@ sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZ2VuZXJhdGVkLmpzIiwic291cmNlcyI6WyJDOi9Vc2Vycy9rYXN0b3IvRG9jdW1lbnRzL0dpdEh1Yi9vYmplY3QtbWVyZ2UvZGV2L2Jyb3dzZXJNYWluLmpzIiwiQzovVXNl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G93W3Byb3BdXHJcbiAgICAgICAgICAgICAgICBdKTtcclxuICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgIG91dFtwcm9wXSA9IG9iamVjdE1lcmdlUmVjdXJzb3IoW3NoYWRvd1twcm9wXV0pO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgfVxyXG4gICAgICAgIC8qanNsaW50IHVucGFyYW06ZmFsc2UgKi9cclxuICAgICAgICBmdW5jdGlvbiBzaGFkb3dNZXJnZXIoc2hhZG93KSB7XHJcbiAgICAgICAgICAgIG9iamVjdEZvcmVhY2goc2hhZG93LCBzaGFkb3dIYW5kbGVyKTtcclxuICAgICAgICB9XHJcbiAgICAgICAgLy8gc2hvcnQgY2lyY3VpdHMgY2FzZSB3aGVyZSBvdXRwdXQgd291bGQgYmUgYSBwcmltaXRpdmUgdmFsdWVcclxuICAgICAgICAvLyBhbnl3YXkuXHJcbiAgICAgICAgaWYgKG91dCBpbnN0YW5jZW9mIE9iamVjdCkge1xyXG4gICAgICAgICAgICAvLyBvbmx5IG1lcmdlcyB0cmFpbGluZyBvYmplY3RzIHNpbmNlIHByaW1pdGl2ZXMgd291bGQgd2lwZSBvdXRcclxuICAgICAgICAgICAgLy8gcHJldmlvdXMgb2JqZWN0cywgYXMgaW4gbWVyZ2luZyB7YTonYSd9LCAnYScsIGFuZCB7YjonYid9XHJcbiAgICAgICAgICAgIC8vIHdvdWxkIHJlc3VsdCBpbiB7YjonYid9IHNvIHRoZSBmaXJzdCB0d28gYXJndW1lbnRzXHJcbiAgICAgICAgICAgIC8vIGNhbiBiZSBpZ25vcmVkIGNvbXBsZXRlbHkuXHJcbiAgICAgICAgICAgIHZhciByZWxldmFudFNoYWRvd3MgPSBnZXRTaGFkb3dPYmplY3RzKHNoYWRvd3MpO1xyXG4gICAgICAgICAgICByZWxldmFudFNoYWRvd3MuZm9yRWFjaChzaGFkb3dNZXJnZXIpO1xyXG4gICAgICAgIH1cclxuICAgICAgICByZXR1c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describe('createOptions', function () { | ||
it('creates an options object with defaults for unspecified values', | ||
function () { | ||
var opts = objectMerge.createOptions(); | ||
expect(opts).toEqual({ | ||
depth : false, | ||
throwOnCircularRef : true | ||
}); | ||
} | ||
); | ||
it('creates an options object with user specified values', | ||
function () { | ||
var opts = objectMerge.createOptions({ | ||
depth : 9, | ||
throwOnCircularRef : false | ||
}); | ||
expect(opts).toEqual({ | ||
depth : 9, | ||
throwOnCircularRef : false | ||
}); | ||
} | ||
); | ||
}); | ||
describe('object-merge', function () { | ||
@@ -234,2 +257,58 @@ var w = { | ||
); | ||
it('allows circular reference check to be disabled', function () { | ||
var x = { | ||
'a' : {} | ||
}; | ||
x.b = x.a; | ||
function thrower () { | ||
var opts = objectMerge.createOptions({throwOnCircularRef : false}); | ||
return objectMerge(opts, x); | ||
} | ||
expect(thrower).not.toThrow(); | ||
}); | ||
it('only considers ObjectMergeOptions obj @ arg[0] to be valid options', | ||
function () { | ||
var x = { | ||
'a' : {} | ||
}; | ||
x.b = x.a; | ||
function thrower () { | ||
var opts = objectMerge.createOptions({throwOnCircularRef : false}); | ||
return objectMerge(x, opts); | ||
} | ||
function thrower2 () { | ||
return objectMerge({throwOnCircularRef : false}, x); | ||
} | ||
expect(thrower).toThrow(); | ||
expect(thrower2).toThrow(); | ||
} | ||
); | ||
it('considers depth of false to mean no limit', function () { | ||
var a = { | ||
'a1' : { | ||
'a2' : { | ||
'a3' : {} | ||
} | ||
} | ||
}; | ||
var opts = objectMerge.createOptions({depth : false}); | ||
var res = objectMerge(opts, a); | ||
expect(res).toEqual(a); | ||
}); | ||
it('allows specifying depth of traversal', function () { | ||
var a = { | ||
'a1' : { | ||
'a2' : { | ||
'a3' : {} | ||
} | ||
} | ||
}; | ||
var opts = objectMerge.createOptions({depth : 2}); | ||
var res = objectMerge(opts, a); | ||
expect(res).toEqual({ | ||
'a1' : { | ||
'a2' : {} | ||
} | ||
}); | ||
}); | ||
}); |
{ | ||
"name": "object-merge", | ||
"version": "2.3.0", | ||
"version": "2.4.0", | ||
"description": "Merges JavaScript objects recursively without altering the objects merged.", | ||
@@ -5,0 +5,0 @@ "main": "./src/object-merge.js", |
@@ -9,9 +9,37 @@ /* | ||
*/ | ||
function ObjectMergeOptions(opts) { | ||
'use strict'; | ||
opts = opts || {}; | ||
this.depth = opts.depth || false; | ||
// circular ref check is true unless explicitly set to false | ||
// ignore the jslint warning here, it's pointless. | ||
this.throwOnCircularRef = 'throwOnCircularRef' in opts && opts.throwOnCircularRef === false ? false : true; | ||
} | ||
/*jslint unparam:true*/ | ||
/** | ||
* Creates a new options object suitable for use with objectMerge. | ||
* @param {Object} [opts] An object specifying the options. | ||
* @returns {ObjectMergeOptions} Returns an instance of ObjectMergeOptions | ||
* to be used with objectMerge. | ||
*/ | ||
function createOptions(opts) { | ||
'use strict'; | ||
var argz = Array.prototype.slice.call(arguments, 0); | ||
argz.unshift(null); | ||
var F = ObjectMergeOptions.bind.apply(ObjectMergeOptions, argz); | ||
return new F(); | ||
} | ||
/*jslint unparam:false*/ | ||
/** | ||
* Merges JavaScript objects recursively without altering the objects merged. | ||
* @author <a href="mailto:matthewkastor@gmail.com">Matthew Kastor</a> | ||
* @param {ObjectMergeOptions} [opts] An options object created by | ||
* objectMerge.createOptions. Options must be specified as the first argument | ||
* and must be an object created with createOptions or else the object will | ||
* not be recognized as an options object and will be merged instead. | ||
* @param {Object} shadows [[shadows]...] One or more objects to merge. Each | ||
* argument given will be treated as an object to merge. Each object overwrites | ||
* the previous objects descendant properties if the property name matches. If | ||
* objects properties are objects they will be merged recursively as well. | ||
* argument given will be treated as an object to merge. Each object | ||
* overwrites the previous objects descendant properties if the property name | ||
* matches. If objects properties are objects they will be merged recursively | ||
* as well. | ||
* @returns {Object} Returns a single merged object composed from clones of the | ||
@@ -67,3 +95,6 @@ * input objects. | ||
var cloneFunction = require('clone-function'); | ||
shadows = Array.prototype.slice.call(arguments, 0); | ||
// this is the queue of visited objects / properties. | ||
var visited = []; | ||
// various merge options | ||
var options = {}; | ||
// gets the sequential trailing objects from array. | ||
@@ -101,5 +132,4 @@ function getShadowObjects(shadows) { | ||
} | ||
// this is the queue of visited objects / properties. | ||
var visited = []; | ||
function objectMergeRecursor(shadows) { | ||
// checks for circular references | ||
function circularReferenceCheck(shadows) { | ||
// if any of the current objects to process exist in the queue | ||
@@ -112,38 +142,58 @@ // then throw an error. | ||
}); | ||
// if none of the current objects were in the queue then add references | ||
// to the queue. | ||
// if none of the current objects were in the queue | ||
// then add references to the queue. | ||
visited = visited.concat(shadows); | ||
function main(shadows) { | ||
var out = getOutputObject(shadows); | ||
/*jslint unparam:true */ | ||
function shadowHandler(val, prop, shadow) { | ||
if (out[prop]) { | ||
out[prop] = objectMergeRecursor([ | ||
out[prop], | ||
shadow[prop] | ||
]); | ||
} else { | ||
out[prop] = objectMergeRecursor([shadow[prop]]); | ||
} | ||
} | ||
function main(shadows) { | ||
var out = getOutputObject(shadows); | ||
/*jslint unparam: true */ | ||
// recursor defined below. Dougie removed the intelligent suppression of | ||
// this warning, probably because of functions that reference each other. | ||
// So, you're stuck with making sure this isn't a mistake every time you | ||
// use his linter. | ||
function shadowHandler(val, prop, shadow) { | ||
if (out[prop]) { | ||
out[prop] = objectMergeRecursor([ | ||
out[prop], | ||
shadow[prop] | ||
]); | ||
} else { | ||
out[prop] = objectMergeRecursor([shadow[prop]]); | ||
} | ||
/*jslint unparam:false */ | ||
function shadowMerger(shadow) { | ||
objectForeach(shadow, shadowHandler); | ||
} | ||
// short circuits case where output would be a primitive value | ||
// anyway. | ||
if (out instanceof Object) { | ||
// only merges trailing objects since primitives would wipe out | ||
// previous objects, as in merging {a:'a'}, 'a', and {b:'b'} | ||
// would result in {b:'b'} so the first two arguments | ||
// can be ignored completely. | ||
var relevantShadows = getShadowObjects(shadows); | ||
relevantShadows.forEach(shadowMerger); | ||
} | ||
return out; | ||
} | ||
/*jslint unparam:false */ | ||
function shadowMerger(shadow) { | ||
objectForeach(shadow, shadowHandler); | ||
} | ||
// short circuits case where output would be a primitive value | ||
// anyway. | ||
if (out instanceof Object) { | ||
// only merges trailing objects since primitives would wipe out | ||
// previous objects, as in merging {a:'a'}, 'a', and {b:'b'} | ||
// would result in {b:'b'} so the first two arguments | ||
// can be ignored completely. | ||
var relevantShadows = getShadowObjects(shadows); | ||
relevantShadows.forEach(shadowMerger); | ||
} | ||
return out; | ||
} | ||
function objectMergeRecursor(shadows) { | ||
if (options.throwOnCircularRef === true) { | ||
circularReferenceCheck(shadows); | ||
} | ||
return main(shadows); | ||
} | ||
// determines whether an options object was passed in and | ||
// uses it if present | ||
// ignore the jslint warning here too. | ||
if (arguments[0] instanceof ObjectMergeOptions) { | ||
options = arguments[0]; | ||
shadows = Array.prototype.slice.call(arguments, 1); | ||
} else { | ||
options = createOptions(); | ||
shadows = Array.prototype.slice.call(arguments, 0); | ||
} | ||
return objectMergeRecursor(shadows); | ||
} | ||
objectMerge.createOptions = createOptions; | ||
module.exports = objectMerge; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
237042
3749