fromBase64functionfunction fromBase64(text: string): Result<Uint8Array<ArrayBufferLike>, string>Standard base64 as bytes; white space between the characters is ignored, and anything else that is not base64 refused.
Base64 and base64url (RFC 4648 §4 and §5), both ways, on bytes (commons 0001-formats FR-008): what DSSE envelopes, JWTs, data URLs, PEM and signed URLs carry. Decoding refuses what is not base64 of the alphabet asked for, rather than skipping it; base64url is written without padding and read with or without it. Taken from the helpers Stolos wrote in src/archon/export/intoto.ts and S/MIME.
import { fromBase64, toBase64, toBase64Url } from "./base64.ts";
toBase64(new TextEncoder().encode("foobar")); // "Zm9vYmFy"
toBase64Url(Uint8Array.of(0xfb, 0xff)); // "-_8"
fromBase64("Zm9v"); // { kind: "ok", value: Uint8Array [102, 111, 111] }fromBase64functionfunction fromBase64(text: string): Result<Uint8Array<ArrayBufferLike>, string>Standard base64 as bytes; white space between the characters is ignored, and anything else that is not base64 refused.
fromBase64Urlfunctionfunction fromBase64Url(text: string): Result<Uint8Array<ArrayBufferLike>, string>Base64url (padded or not) as bytes; anything else refused.
toBase64functionfunction toBase64(bytes: Uint8Array<ArrayBufferLike>): stringBytes as standard base64, padded.
toBase64Urlfunctionfunction toBase64Url(bytes: Uint8Array<ArrayBufferLike>): stringBytes as base64url, without padding.