INNER CODE UNIT · TypeScript
base64
cloudflare/web-bot-auth · packages/web-bot-auth/src/index.ts:126
function base64(bytes: Uint8Array): string {
return btoa(String.fromCharCode(...bytes));
}
function base64Url(bytes: Uint8Array): string {
return base64(bytes)
.replace(/\+/g, "-")
.replace(/\//g, "_")
.replace(/=+$/, "");
}
function decodeBase64(value: string): Uint8Array | undefined {
const normalized = value.replace(/-/g, "+").replace(/_/g, "/");
const remainder = normalized.length % 4;
if (remainder === 1) return undefined;
const padded = normalized + "=".repeat((4 - remainder) % 4);
try {
return Uint8Array.from(atob(padded), (character) =>