ethers.js/lib.commonjs/wordlists/decode-owla.js

32 lines
1.2 KiB
JavaScript
Raw Normal View History

2022-09-05 23:57:11 +03:00
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.decodeOwlA = void 0;
2022-09-16 05:58:45 +03:00
const index_js_1 = require("../utils/index.js");
2022-09-05 23:57:11 +03:00
const bit_reader_js_1 = require("./bit-reader.js");
const decode_owl_js_1 = require("./decode-owl.js");
2022-11-30 23:44:23 +03:00
/**
* @_ignore
*/
2022-09-05 23:57:11 +03:00
function decodeOwlA(data, accents) {
let words = (0, decode_owl_js_1.decodeOwl)(data).join(",");
// Inject the accents
accents.split(/,/g).forEach((accent) => {
const match = accent.match(/^([a-z]*)([0-9]+)([0-9])(.*)$/);
2022-09-16 05:58:45 +03:00
(0, index_js_1.assertArgument)(match !== null, "internal error parsing accents", "accents", accents);
2022-09-05 23:57:11 +03:00
let posOffset = 0;
const positions = (0, bit_reader_js_1.decodeBits)(parseInt(match[3]), match[4]);
const charCode = parseInt(match[2]);
const regex = new RegExp(`([${match[1]}])`, "g");
words = words.replace(regex, (all, letter) => {
const rem = --positions[posOffset];
if (rem === 0) {
letter = String.fromCharCode(letter.charCodeAt(0), charCode);
posOffset++;
}
return letter;
});
});
return words.split(",");
}
exports.decodeOwlA = decodeOwlA;
//# sourceMappingURL=decode-owla.js.map