Encode and decode base64
import { atob, btoa } from "@antithrow/std";
const encoded = btoa("hello"); // Ok("aGVsbG8=")
const decoded = atob("aGVsbG8="); // Ok("hello")
const bad = atob("not-base64!!"); // Err(DOMException)
When the globals throw
btoa(data)throwsDOMException("InvalidCharacterError") ifdatacontains characters outside the Latin-1 range.atob(data)throwsDOMExceptionfor any input that isn't valid base64.
Both wrappers capture these as Err(DOMException).
Binary data
Neither global works directly on raw bytes. If you have a Uint8Array:
import { btoa } from "@antithrow/std";
const binary = String.fromCharCode(...bytes);
const b64 = btoa(binary);
See also
- Reference:
atob/btoa