UNPKG

710 BJavaScriptView Raw
1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT license.
3/// <reference lib="dom"/>
4export 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}
11export 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//# sourceMappingURL=encode.js.map
\No newline at end of file