.
This commit is contained in:
parent
1d3501930c
commit
d57d7fffdb
18
coretool.js
18
coretool.js
@ -147,10 +147,7 @@ module.exports = {
|
||||
if (salt && typeof salt === 'string') data = data + salt
|
||||
const inputEncoding = input // my.INPUT_LIST.indexOf(option.input)>=0?option.input:my.INPUT // 'utf8', 'ascii' or 'latin1' for string data, default to utf8 if not specified; ignored for Buffer, TypedArray, or DataView.
|
||||
const outputEncoding = output === 'buf' ? undefined : output // (my.OUTPUT_LIST.indexOf(output)>=0?output:my.OUTPUT) // option.output: 留空=》默认输出hex格式;或者手动指定 'buf', hex', 'latin1' or 'base64'
|
||||
return require('crypto')
|
||||
.createHash(hasher)
|
||||
.update(data, inputEncoding)
|
||||
.digest(outputEncoding)
|
||||
return require('crypto').createHash(hasher).update(data, inputEncoding).digest(outputEncoding)
|
||||
},
|
||||
|
||||
/**
|
||||
@ -240,10 +237,15 @@ module.exports = {
|
||||
let parent = root || globalThis || global || window || {}
|
||||
let keychain = path.split('.')
|
||||
for (let key of keychain) {
|
||||
if (typeof parent === 'object' && key.match(/^\w+\(\)$/) && typeof parent[key.substring(0, key.length - 2)] === 'function') {
|
||||
// 支持 xxx.myfunc().yyy 的函数形式作为一个路径节点。
|
||||
parent = parent[key.substring(0, key.length - 2)]()
|
||||
} else if (typeof parent === 'object' && key.match(/^\w+$/) && typeof parent[key] != 'undefined' && parent[key] != null) {
|
||||
if (typeof parent === 'object' && /^\w+\(.*\)$/.test(key)) {
|
||||
// 支持 myfunc(param) 作为一个路径节点。
|
||||
let [all, func, param] = key.match(/^(\w+)\((.*)\)$/)
|
||||
parent = parent[func](param)
|
||||
} else if (typeof parent === 'object' && /^\w+\[.*\]$/.test(key)) {
|
||||
// 支持 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) {
|
||||
parent = parent[key]
|
||||
} else {
|
||||
return undefined
|
||||
|
Loading…
Reference in New Issue
Block a user