Comparing version 0.0.13 to 0.0.14
@@ -5,3 +5,3 @@ { | ||
"description": "Core JavaScript library for browser runtime", | ||
"version": "0.0.13", | ||
"version": "0.0.14", | ||
"author": { | ||
@@ -8,0 +8,0 @@ "name": "fish" |
71
utils.js
@@ -75,4 +75,3 @@ /** | ||
function isNeedClone(d){ | ||
function isNeedClone(d) { | ||
if(!d) return false; | ||
@@ -87,12 +86,12 @@ if(root.HTMLElement && d instanceof root.HTMLElement) return false; | ||
var maxDepth = 4; | ||
function deepMerge(dest, src, isDirect, depth) { | ||
var maxDepth = 5; | ||
function deepMerge(dest, src, directs, depth) { | ||
var i, j, len, src, depth = depth || 0; | ||
var result = isDirect ? dest : clone(dest); | ||
if (depth++ >= maxDepth) { | ||
console.log('层数过深, 全部继承'); | ||
return src; | ||
} | ||
var result = dest; | ||
// var result = isDirect ? dest : clone(dest); | ||
if (depth >= maxDepth) { | ||
console.log('层数过深, 全部继承'); | ||
return src; | ||
} | ||
depth++; | ||
// | ||
@@ -106,16 +105,16 @@ for (i in src) { | ||
if (destValue && typeof (destValue) === 'object' && typeof (value) === 'object') { | ||
if(!isNeedClone(value)){ | ||
if (!isNeedClone(value) || (directs && i in directs)) { | ||
result[i] = value; | ||
continue; | ||
} | ||
if(Array.isArray(destValue) !== Array.isArray(value)){ // 继承和被继承的 一个是数组 一个是对象 | ||
if (typeof(value) === 'object' && (!isDirect) && isNeedClone(value)) value = deepClone(value); | ||
if (Array.isArray(destValue) !== Array.isArray(value)) { // 继承和被继承的 一个是数组 一个是对象 | ||
value = deepClone(value); | ||
result[i] = value; | ||
continue; | ||
} | ||
} | ||
result[i] = deepMerge(destValue, value, isDirect, depth); | ||
result[i] = deepMerge(destValue, value, directs, depth); | ||
continue; | ||
} | ||
if (typeof (value) === 'object' && (!isDirect) && isNeedClone(value)) value = deepClone(value); | ||
if (typeof (value) === 'object' && isNeedClone(value)) value = deepClone(value); | ||
result[i] = value; | ||
@@ -127,8 +126,2 @@ } | ||
function deepMergeCopy(dest, src){ | ||
return deepMerge(dest, src, false); | ||
} | ||
function deepMergeDirect(dest, src){ | ||
return deepMerge(dest, src, false); | ||
} | ||
@@ -144,14 +137,38 @@ /** | ||
*/ | ||
function switchValue(f, a, b, c, d){ | ||
if(typeof(f) === 'function') return f(a, b, c, d); | ||
function switchValue(f, a, b, c, d) { | ||
if(typeof (f) === 'function') return f(a, b, c, d); | ||
return f; | ||
} | ||
var root = this; | ||
function getContainer(container) { | ||
if (root.HTMLElement && container instanceof root.HTMLElement) return container; | ||
if (root.HTMLElement && container[0] && container[0] instanceof root.HTMLElement) return container[0]; | ||
if (typeof container === 'string') { | ||
if (container.charAt(0) === '.') { | ||
var className = container.slice(1); | ||
return container = document.getElementsByClassName(className)[0]; | ||
} else { | ||
var id; | ||
if (container.charAt(0) !== '#') { | ||
id = container; | ||
} else { | ||
id = container.slice(1); | ||
} | ||
return container = document.getElementById(id); | ||
} | ||
if (!container) { | ||
throw '没有container '; | ||
} | ||
} | ||
} | ||
module.exports = { | ||
'getContainer': getContainer, | ||
'merge': merge, | ||
'extend': merge, | ||
'isNone': isNone, | ||
'traver': traver, | ||
'deepMerge': deepMerge, | ||
'deepMergeDirect': deepMergeDirect, | ||
'deepMergeCopy': deepMergeCopy, | ||
'clone': clone, | ||
@@ -158,0 +175,0 @@ 'deepClone': deepClone, |
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
22367
718