@fruitsjs/util
Version:
Useful utilities and tools for building Fruits Eco-Blockchain applications
26 lines • 1.07 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.convertByteArrayToString = void 0;
const convertByteArrayToString = (byteArray, startIndex = 0, length = null) => {
if (length === 0) {
return '';
}
let bytes = byteArray;
if (startIndex !== 0) {
const len = length === null ? byteArray.length - startIndex : length;
checkBytesToIntInput(bytes, len, startIndex);
bytes = byteArray.slice(startIndex, startIndex + len);
}
return decodeURIComponent(escape(String.fromCharCode.apply(null, Array.from(bytes))));
};
exports.convertByteArrayToString = convertByteArrayToString;
function checkBytesToIntInput(bytes, numBytes, startIndex = 0) {
if (startIndex < 0) {
throw new Error('Start index should not be negative');
}
if (bytes.length < startIndex + numBytes) {
throw new Error('Need at least ' + (numBytes) + ' bytes to convert to an integer');
}
return startIndex;
}
//# sourceMappingURL=convertByteArrayToString.js.map