Base64.js 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. var t = require;
  2. var e = module;
  3. var i = exports;
  4. Object.defineProperty(i, "__esModule", {value: !0}),
  5. (i.Base64 = void 0),
  6. (i.Base64 = class {
  7. constructor() {
  8. this._keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
  9. }
  10. encode(t) {
  11. var e,
  12. i,
  13. s,
  14. o,
  15. a,
  16. n,
  17. r = "",
  18. l = 0;
  19. for (t = this._utf8_encode(t); l < t.length; )
  20. (s = (n = t.charCodeAt(l++)) >> 2),
  21. (o = ((3 & n) << 4) | ((e = t.charCodeAt(l++)) >> 4)),
  22. (a = ((15 & e) << 2) | ((i = t.charCodeAt(l++)) >> 6)),
  23. (n = 63 & i),
  24. isNaN(e) ? (a = n = 64) : isNaN(i) && (n = 64),
  25. (r =
  26. r +
  27. this._keyStr.charAt(s) +
  28. this._keyStr.charAt(o) +
  29. this._keyStr.charAt(a) +
  30. this._keyStr.charAt(n));
  31. return r;
  32. }
  33. decode(t) {
  34. var e,
  35. i,
  36. s,
  37. o,
  38. a,
  39. n = "",
  40. r = 0;
  41. for (t = t.replace(/[^A-Za-z0-9\+\/\=]/g, ""); r < t.length; )
  42. (e = (this._keyStr.indexOf(t.charAt(r++)) << 2) | ((s = this._keyStr.indexOf(t.charAt(r++))) >> 4)),
  43. (i = ((15 & s) << 4) | ((o = this._keyStr.indexOf(t.charAt(r++))) >> 2)),
  44. (s = ((3 & o) << 6) | (a = this._keyStr.indexOf(t.charAt(r++)))),
  45. (n += String.fromCharCode(e)),
  46. 64 != o && (n += String.fromCharCode(i)),
  47. 64 != a && (n += String.fromCharCode(s));
  48. return this._utf8_decode(n);
  49. }
  50. _utf8_encode(t) {
  51. t = t.replace(/\r\n/g, "\n");
  52. for (var e = "", i = 0; i < t.length; i++) {
  53. var s = t.charCodeAt(i);
  54. s < 128
  55. ? (e += String.fromCharCode(s))
  56. : (127 < s && s < 2048
  57. ? (e += String.fromCharCode((s >> 6) | 192))
  58. : ((e += String.fromCharCode((s >> 12) | 224)),
  59. (e += String.fromCharCode(((s >> 6) & 63) | 128))),
  60. (e += String.fromCharCode((63 & s) | 128)));
  61. }
  62. return e;
  63. }
  64. _utf8_decode(t) {
  65. for (var e, i, s = "", o = 0, a = 0; o < t.length; )
  66. (e = t.charCodeAt(o)) < 128
  67. ? ((s += String.fromCharCode(e)), o++)
  68. : 191 < e && e < 224
  69. ? ((a = t.charCodeAt(o + 1)), (s += String.fromCharCode(((31 & e) << 6) | (63 & a))), (o += 2))
  70. : ((a = t.charCodeAt(o + 1)),
  71. (i = t.charCodeAt(o + 2)),
  72. (s += String.fromCharCode(((15 & e) << 12) | ((63 & a) << 6) | (63 & i))),
  73. (o += 3));
  74. return s;
  75. }
  76. });