MCPcopy Create free account
hub / github.com/chhoumann/quickadd / encodeToBase64

Function encodeToBase64

src/utils/base64.ts:23–39  ·  view source on GitHub ↗
(value: string)

Source from the content-addressed store, hash-verified

21}
22
23export function encodeToBase64(value: string): string {
24 if (textEncoder && hasWindowFunction("btoa")) {
25 const bytes = textEncoder.encode(value);
26 let binary = "";
27 for (let i = 0; i < bytes.length; i++) {
28 binary += String.fromCharCode(bytes[i]);
29 }
30 return window.btoa(binary);
31 }
32
33 const buffer = getGlobalBuffer();
34 if (buffer) {
35 return buffer.from(value, "utf8").toString("base64");
36 }
37
38 throw new Error("Base64 encoding is not supported in this environment.");
39}
40
41export function decodeFromBase64(value: string): string {
42 if (textDecoder && hasWindowFunction("atob")) {

Callers 8

assetFunction · 0.90
encodeAssetsFunction · 0.90
makePackageFunction · 0.90
criticalPackageFunction · 0.90

Calls 2

hasWindowFunctionFunction · 0.85
getGlobalBufferFunction · 0.85

Tested by 3

assetFunction · 0.72
makePackageFunction · 0.72
criticalPackageFunction · 0.72