u
This commit is contained in:
parent
b038ff8058
commit
35862f8a69
11
coretool.js
11
coretool.js
@ -246,7 +246,7 @@ module.exports = {
|
||||
: t // 可以是 undefined, boolean, number, string
|
||||
},
|
||||
|
||||
read_varchain (path, root) {
|
||||
read_varchain (path, root, emptyValue) {
|
||||
let parent = root || globalThis || global || window || {}
|
||||
let keychain = path.split('.')
|
||||
for (let key of keychain) {
|
||||
@ -258,13 +258,13 @@ module.exports = {
|
||||
// 支持 myarr[index] 作为一个路径节点
|
||||
let [all, arr, index] = key.match(/^(\w+)\[(.*)\]$/)
|
||||
parent = parent[arr][parseInt(index)]
|
||||
} else if (typeof parent === 'object' && /^\w+$/.test(key) && typeof parent[key] != 'undefined' && parent[key] != null) {
|
||||
} else if (typeof parent === 'object' && /^\w+$/.test(key) && typeof parent[key] != 'undefined') {
|
||||
parent = parent[key]
|
||||
} else {
|
||||
return undefined
|
||||
return emptyValue
|
||||
}
|
||||
}
|
||||
return parent
|
||||
return typeof parent !== 'undefined' ? parent : emptyValue
|
||||
},
|
||||
|
||||
set_varchain (path, root, value) {
|
||||
@ -298,6 +298,9 @@ module.exports = {
|
||||
},
|
||||
|
||||
number_precision (number, precision = 4) {
|
||||
if (isFinite(number)) // null, '', '0', []
|
||||
return Number(Number(number).toFixed(precision))
|
||||
else // undefined, NaN, Infinity, {}
|
||||
return 0
|
||||
},
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user