INNER CODE UNIT · TypeScript

base64Url

cloudflare/web-bot-auth · packages/web-bot-auth/src/index.ts:130

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) =>
      character.charCodeAt(0)
    );
  } catch {
    return undefined;

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…