mergeDeep added

mergeDeep is the same as Object.assign except it works upon multiple layers of an object
build-default-monitor-config-from-definitions
Moe 2020-05-20 15:06:39 -07:00
parent 2ad0cae75f
commit 58df790e97
1 changed files with 20 additions and 0 deletions

View File

@ -48,6 +48,26 @@ switch($user.details.lang){
})
break;
}
function isObject(item) {
return (item && typeof item === 'object' && !Array.isArray(item));
}
window.mergeDeep = function(target, ...sources){
if (!sources.length) return target;
const source = sources.shift();
if (isObject(target) && isObject(source)) {
for (const key in source) {
if (isObject(source[key])) {
if (!target[key]) Object.assign(target, { [key]: {} });
mergeDeep(target[key], source[key]);
} else {
Object.assign(target, { [key]: source[key] });
}
}
}
return mergeDeep(target, ...sources);
}
window.getApiPrefix = function(){
return $.ccio.init('location',$user) + $user.auth_token
}