decode-shared.js 1.3 KB

12345678910111213141516171819202122232425262728293031
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.decodeBase64 = decodeBase64;
  4. /*
  5. * Shared base64 decode helper for generated decode data.
  6. * Assumes global atob is available.
  7. */
  8. function decodeBase64(input) {
  9. const binary =
  10. // eslint-disable-next-line n/no-unsupported-features/node-builtins
  11. typeof atob === "function"
  12. ? // Browser (and Node >=16)
  13. // eslint-disable-next-line n/no-unsupported-features/node-builtins
  14. atob(input)
  15. : // Older Node versions (<16)
  16. // eslint-disable-next-line n/no-unsupported-features/node-builtins
  17. typeof Buffer.from === "function"
  18. ? // eslint-disable-next-line n/no-unsupported-features/node-builtins
  19. Buffer.from(input, "base64").toString("binary")
  20. : // eslint-disable-next-line unicorn/no-new-buffer, n/no-deprecated-api
  21. new Buffer(input, "base64").toString("binary");
  22. const evenLength = binary.length & ~1; // Round down to even length
  23. const out = new Uint16Array(evenLength / 2);
  24. for (let index = 0, outIndex = 0; index < evenLength; index += 2) {
  25. const lo = binary.charCodeAt(index);
  26. const hi = binary.charCodeAt(index + 1);
  27. out[outIndex++] = lo | (hi << 8);
  28. }
  29. return out;
  30. }
  31. //# sourceMappingURL=decode-shared.js.map