@neuronet.io/vido
Advanced tools
Comparing version 4.2.3 to 4.2.4
@@ -33,47 +33,48 @@ /** | ||
} | ||
/** | ||
* Merge deep - helper function which will merge objects recursively - creating brand new one - like clone | ||
* | ||
* @param {object} target | ||
* @params {[object]} sources | ||
* @returns {object} | ||
*/ | ||
function getEmpty(value, targetValue) { | ||
if (targetValue) | ||
return targetValue; | ||
if (Array.isArray(value)) | ||
return new Array(value.length); | ||
if (isObject(value)) | ||
return {}; | ||
return value; | ||
} | ||
export function mergeDeep(target, ...sources) { | ||
const source = sources.shift(); | ||
if (isObject(target) && isObject(source)) { | ||
if (source && typeof source.clone === 'function') { | ||
target = source.clone(); | ||
} | ||
else if (isObject(source)) { | ||
if (!target) { | ||
target = {}; | ||
} | ||
for (const key in source) { | ||
if (isObject(source[key])) { | ||
if (typeof source[key].clone === 'function') { | ||
target[key] = source[key].clone(); | ||
} | ||
else { | ||
if (typeof target[key] === 'undefined') { | ||
target[key] = {}; | ||
} | ||
target[key] = mergeDeep(target[key], source[key]); | ||
} | ||
const value = source[key]; | ||
target[key] = mergeDeep(getEmpty(value, target[key]), value); | ||
} | ||
} | ||
else if (Array.isArray(source)) { | ||
if (!target) { | ||
target = new Array(source.length); | ||
} | ||
let index = 0; | ||
for (const value of source) { | ||
target[index] = mergeDeep(getEmpty(value, target[index]), value); | ||
index++; | ||
} | ||
// array has properties too | ||
const arrayKeys = Object.keys(source); | ||
if (arrayKeys.length > index) { | ||
const arrayKeysLen = arrayKeys.length; | ||
for (let i = index; i < arrayKeysLen; i++) { | ||
const propName = arrayKeys[i]; | ||
const value = source[propName]; | ||
target[propName] = mergeDeep(getEmpty(value, target[propName]), value); | ||
} | ||
else if (Array.isArray(source[key])) { | ||
target[key] = new Array(source[key].length); | ||
let index = 0; | ||
for (let item of source[key]) { | ||
if (isObject(item)) { | ||
if (typeof item.clone === 'function') { | ||
target[key][index] = item.clone(); | ||
} | ||
else { | ||
target[key][index] = mergeDeep({}, item); | ||
} | ||
} | ||
else { | ||
target[key][index] = item; | ||
} | ||
index++; | ||
} | ||
} | ||
else { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
else { | ||
target = source; | ||
} | ||
if (!sources.length) { | ||
@@ -80,0 +81,0 @@ return target; |
@@ -797,9 +797,2 @@ /** | ||
} | ||
/** | ||
* Merge deep - helper function which will merge objects recursively - creating brand new one - like clone | ||
* | ||
* @param {object} target | ||
* @params {[object]} sources | ||
* @returns {object} | ||
*/ | ||
function mergeDeep(target, ...sources) { | ||
@@ -806,0 +799,0 @@ const source = sources.shift(); |
{ | ||
"name": "@neuronet.io/vido", | ||
"version": "4.2.3", | ||
"version": "4.2.4", | ||
"description": "Compilation-less and eval free frontend framework for fast scalable apps.", | ||
@@ -5,0 +5,0 @@ "main": "dist/vido.js", |
@@ -11,9 +11,2 @@ /** | ||
} | ||
/** | ||
* Merge deep - helper function which will merge objects recursively - creating brand new one - like clone | ||
* | ||
* @param {object} target | ||
* @params {[object]} sources | ||
* @returns {object} | ||
*/ | ||
export declare function mergeDeep<T>(target: any, ...sources: any[]): T; | ||
@@ -20,0 +13,0 @@ /** |
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 too big to display
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
807103
56
4432