1 |
|
2 |
|
3 |
|
4 | export function encodeUTF8(str) {
|
5 | const bytes = new Uint8Array(str.length);
|
6 | for (let i = 0; i < str.length; i++) {
|
7 | bytes[i] = str.charCodeAt(i);
|
8 | }
|
9 | return bytes;
|
10 | }
|
11 | export function encodeBase64(value) {
|
12 | if ("function" !== typeof btoa) {
|
13 | throw new Error("Your browser environment is missing the global `btoa` function");
|
14 | }
|
15 | let binary = "";
|
16 | const bytes = new Uint8Array(value);
|
17 | const len = bytes.byteLength;
|
18 | for (let i = 0; i < len; i++) {
|
19 | binary += String.fromCharCode(bytes[i]);
|
20 | }
|
21 | return btoa(binary);
|
22 | }
|
23 |
|
\ | No newline at end of file |