META-INF.resources.bower_components.cldrjs.src.util.json.merge.js Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jwebmp-globalize Show documentation
Show all versions of jwebmp-globalize Show documentation
The JWebSwing implementation for a full Globalization
The newest version!
define([
"../array/for_each",
"../array/is_array"
], function (arrayForEach, arrayIsArray) {
// Returns new deeply merged JSON.
//
// Eg.
// merge( { a: { b: 1, c: 2 } }, { a: { b: 3, d: 4 } } )
// -> { a: { b: 3, c: 2, d: 4 } }
//
// @arguments JSON's
//
var merge = function () {
var destination = {},
sources = [].slice.call(arguments, 0);
arrayForEach(sources, function (source) {
var prop;
for (prop in source) {
if (prop in destination && typeof destination[prop] === "object" && !arrayIsArray(destination[prop])) {
// Merge Objects
destination[prop] = merge(destination[prop], source[prop]);
} else {
// Set new values
destination[prop] = source[prop];
}
}
});
return destination;
};
return merge;
});