rwadurian/tools/mnemonic-test/node_modules/@cosmjs/encoding/build/ascii.js

32 lines
1.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.toAscii = toAscii;
exports.fromAscii = fromAscii;
function toAscii(input) {
const toNums = (str) => str.split("").map((x) => {
const charCode = x.charCodeAt(0);
// 0x000x1F control characters
// 0x200x7E printable characters
// 0x7F delete character
// 0x800xFF out of 7 bit ascii range
if (charCode < 0x20 || charCode > 0x7e) {
throw new Error(`Cannot encode character that is out of printable ASCII range: ${charCode}`);
}
return charCode;
});
return Uint8Array.from(toNums(input));
}
function fromAscii(data) {
const fromNums = (listOfNumbers) => listOfNumbers.map((x) => {
// 0x000x1F control characters
// 0x200x7E printable characters
// 0x7F delete character
// 0x800xFF out of 7 bit ascii range
if (x < 0x20 || x > 0x7e) {
throw new Error(`Cannot decode character that is out of printable ASCII range: ${x}`);
}
return String.fromCharCode(x);
});
return fromNums(Array.from(data)).join("");
}
//# sourceMappingURL=ascii.js.map