This commit is contained in:
陆柯 2023-03-05 22:33:09 +08:00
parent 1d3501930c
commit d57d7fffdb

View File

@ -147,10 +147,7 @@ module.exports = {
if (salt && typeof salt === 'string') data = data + salt 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 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' 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') return require('crypto').createHash(hasher).update(data, inputEncoding).digest(outputEncoding)
.createHash(hasher)
.update(data, inputEncoding)
.digest(outputEncoding)
}, },
/** /**
@ -240,10 +237,15 @@ module.exports = {
let parent = root || globalThis || global || window || {} let parent = root || globalThis || global || window || {}
let keychain = path.split('.') let keychain = path.split('.')
for (let key of keychain) { for (let key of keychain) {
if (typeof parent === 'object' && key.match(/^\w+\(\)$/) && typeof parent[key.substring(0, key.length - 2)] === 'function') { if (typeof parent === 'object' && /^\w+\(.*\)$/.test(key)) {
// 支持 xxx.myfunc().yyy 的函数形式作为一个路径节点。 // 支持 myfunc(param) 作为一个路径节点。
parent = parent[key.substring(0, key.length - 2)]() let [all, func, param] = key.match(/^(\w+)\((.*)\)$/)
} else if (typeof parent === 'object' && key.match(/^\w+$/) && typeof parent[key] != 'undefined' && parent[key] != null) { 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] parent = parent[key]
} else { } else {
return undefined return undefined