All Downloads are FREE. Search and download functionalities are using the official Maven repository.

META-INF.resources.bower_components.cldrjs.src.util.json.merge.js Maven / Gradle / Ivy

There is a newer version: 1.2.2.1-jre17
Show 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;

});




© 2015 - 2024 Weber Informatics LLC | Privacy Policy