12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- "use strict";
- function btoa(s) {
- let i;
-
- s = `${s}`;
-
-
- for (i = 0; i < s.length; i++) {
- if (s.charCodeAt(i) > 255) {
- return null;
- }
- }
- let out = "";
- for (i = 0; i < s.length; i += 3) {
- const groupsOfSix = [undefined, undefined, undefined, undefined];
- groupsOfSix[0] = s.charCodeAt(i) >> 2;
- groupsOfSix[1] = (s.charCodeAt(i) & 0x03) << 4;
- if (s.length > i + 1) {
- groupsOfSix[1] |= s.charCodeAt(i + 1) >> 4;
- groupsOfSix[2] = (s.charCodeAt(i + 1) & 0x0f) << 2;
- }
- if (s.length > i + 2) {
- groupsOfSix[2] |= s.charCodeAt(i + 2) >> 6;
- groupsOfSix[3] = s.charCodeAt(i + 2) & 0x3f;
- }
- for (let j = 0; j < groupsOfSix.length; j++) {
- if (typeof groupsOfSix[j] === "undefined") {
- out += "=";
- } else {
- out += btoaLookup(groupsOfSix[j]);
- }
- }
- }
- return out;
- }
- const keystr =
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
- function btoaLookup(index) {
- if (index >= 0 && index < 64) {
- return keystr[index];
- }
-
- return undefined;
- }
- module.exports = btoa;
|