decode-owla.js 1.0 KB

12345678910111213141516171819202122232425262728
  1. import { assertArgument } from "../utils/index.js";
  2. import { decodeBits } from "./bit-reader.js";
  3. import { decodeOwl } from "./decode-owl.js";
  4. /**
  5. * @_ignore
  6. */
  7. export function decodeOwlA(data, accents) {
  8. let words = decodeOwl(data).join(",");
  9. // Inject the accents
  10. accents.split(/,/g).forEach((accent) => {
  11. const match = accent.match(/^([a-z]*)([0-9]+)([0-9])(.*)$/);
  12. assertArgument(match !== null, "internal error parsing accents", "accents", accents);
  13. let posOffset = 0;
  14. const positions = decodeBits(parseInt(match[3]), match[4]);
  15. const charCode = parseInt(match[2]);
  16. const regex = new RegExp(`([${match[1]}])`, "g");
  17. words = words.replace(regex, (all, letter) => {
  18. const rem = --positions[posOffset];
  19. if (rem === 0) {
  20. letter = String.fromCharCode(letter.charCodeAt(0), charCode);
  21. posOffset++;
  22. }
  23. return letter;
  24. });
  25. });
  26. return words.split(",");
  27. }
  28. //# sourceMappingURL=decode-owla.js.map