版博士V2.0程序
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. "use strict";
  2. var __importDefault = (this && this.__importDefault) || function (mod) {
  3. return (mod && mod.__esModule) ? mod : { "default": mod };
  4. };
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. const DOMException_1 = __importDefault(require("../exception/DOMException"));
  7. const DOMExceptionNameEnum_1 = __importDefault(require("../exception/DOMExceptionNameEnum"));
  8. const BASE64_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  9. /**
  10. * Base64 encoding and decoding.
  11. */
  12. class Base64 {
  13. /**
  14. * Creates a Base64-encoded ASCII string from a binary string (i.e., a string in which each character in the string is treated as a byte of binary data).
  15. *
  16. * @see https://developer.mozilla.org/en-US/docs/Web/API/btoa
  17. * @param data Binay data.
  18. * @returns Base64-encoded string.
  19. */
  20. static btoa(data) {
  21. const str = data.toString();
  22. if (/[^\u0000-\u00ff]/.test(str)) {
  23. throw new DOMException_1.default("Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range.", DOMExceptionNameEnum_1.default.invalidCharacterError);
  24. }
  25. let t = '';
  26. let p = -6;
  27. let a = 0;
  28. let i = 0;
  29. let v = 0;
  30. let c;
  31. while (i < str.length || p > -6) {
  32. if (p < 0) {
  33. if (i < str.length) {
  34. c = str.charCodeAt(i++);
  35. v += 8;
  36. }
  37. else {
  38. c = 0;
  39. }
  40. a = ((a & 255) << 8) | (c & 255);
  41. p += 8;
  42. }
  43. t += BASE64_CHARS.charAt(v > 0 ? (a >> p) & 63 : 64);
  44. p -= 6;
  45. v -= 6;
  46. }
  47. return t;
  48. }
  49. /**
  50. * Decodes a string of data which has been encoded using Base64 encoding.
  51. *
  52. * @see https://developer.mozilla.org/en-US/docs/Web/API/atob
  53. * @see https://infra.spec.whatwg.org/#forgiving-base64-encode.
  54. * @see Https://html.spec.whatwg.org/multipage/webappapis.html#btoa.
  55. * @param data Binay string.
  56. * @returns An ASCII string containing decoded data from encodedData.
  57. */
  58. static atob(data) {
  59. const str = data.toString();
  60. if (/[^\u0000-\u00ff]/.test(str)) {
  61. throw new DOMException_1.default("Failed to execute 'atob' on 'Window': The string to be decoded contains characters outside of the Latin1 range.", DOMExceptionNameEnum_1.default.invalidCharacterError);
  62. }
  63. if (/[^A-Za-z\d+/=]/.test(str) || str.length % 4 == 1) {
  64. throw new DOMException_1.default("Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.", DOMExceptionNameEnum_1.default.invalidCharacterError);
  65. }
  66. let t = '';
  67. let p = -8;
  68. let a = 0;
  69. let c;
  70. let d;
  71. for (let i = 0; i < str.length; i++) {
  72. if ((c = BASE64_CHARS.indexOf(str.charAt(i))) < 0) {
  73. continue;
  74. }
  75. a = (a << 6) | (c & 63);
  76. if ((p += 6) >= 0) {
  77. d = (a >> p) & 255;
  78. if (c !== 64) {
  79. t += String.fromCharCode(d);
  80. }
  81. a &= 63;
  82. p -= 8;
  83. }
  84. }
  85. return t;
  86. }
  87. }
  88. exports.default = Base64;
  89. //# sourceMappingURL=Base64.js.map