UNPKG

vcc-ui

Version:

VCC UI is a collection of React UI Components that can be used for developing front-end applications at Volvo Car Corporation.

32 lines (28 loc) 916 B
/*! * Deep merge two or more objects together. * (c) 2019 Chris Ferdinandi, MIT License, https://gomakethings.com * @param {Object} objects The objects to merge together * @returns {Object} Merged values of defaults and options */ export function merge() { // Setup merged object var newObj = {}; // Merge the object into the newObj object var innerMerge = function(obj) { for (var prop in obj) { if (Object.prototype.hasOwnProperty.call(obj, prop)) { // If property is an object, merge properties if (Object.prototype.toString.call(obj[prop]) === '[object Object]') { newObj[prop] = merge(newObj[prop], obj[prop]); } else { newObj[prop] = obj[prop]; } } } }; // Loop through each object and conduct a merge for (var i = 0; i < arguments.length; i++) { innerMerge(arguments[i]); } return newObj; }