decode-owla.js 1.2 KB

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