function inArray(arr, key, val) { if (!arr || !arr.length || typeof arr != 'object' || !Array.isArray(arr)) { return -1 } for (let i = 0; i < arr.length; i++) { if (!key) { if (arr[i] == val) { return i } } else if (arr[i][key] === val) { return i } } return -1; } // ArrayBuffer转16进度字符串示例 function ab2hex(buffer, split) { var hexArr = Array.prototype.map.call( new Uint8Array(buffer), function (bit) { return ('00' + bit.toString(16)).slice(-2) } ) return hexArr.join(split); } const {TextDecoder, TextEncoder} = require('./encoding') function hex2str(arr) { let decoder = new TextDecoder('utf8') let uint8 = new Uint8Array(arr) let res = decoder.decode(uint8) return res } function str2hex(str) { let encoder = new TextEncoder('utf8') return encoder.encode(str) } module.exports = { inArray, ab2hex, hex2str, str2hex, }