@ende/encoding/unstable-base64

ende add jsr:@ende/encoding

Version 2026.10.15 on JSR.

Functions to encode and decode to and from base64 strings.

import { assertEquals } from "@ende/assert";
import { encodeBase64, type Uint8Array_ } from "@ende/encoding/unstable-base64";

assertEquals(encodeBase64("Hello World", { alphabet: "base64" }), "SGVsbG8gV29ybGQ=");
assertEquals(
  encodeBase64(
    new TextEncoder().encode("Hello World") as Uint8Array_,
    { alphabet: "base64" }
  ),
  "SGVsbG8gV29ybGQ=",
);

Exports

  • Base64Alphabet — The base64 alphabets.
  • Base64Options — Options for encoding and decoding base64 strings.
  • calcSizeBase64 — Calculate the output size needed to encode a given input size for encodeIntoBase64.
  • decodeBase64 — `decodeBase64` takes an input source and decodes it into a Uint8Array<ArrayBuffer> using the specified format.
  • encodeBase64 — `encodeBase64` takes an input source and encodes it into a base64 string. If a Uint8Array<ArrayBuffer> or ArrayBuffer is provided, the underlying source will be detached and reused for the encoding. If you need the input source after providing it to this function, call `.slice()` to pass in a copy.
  • encodeIntoBase64 — `encodeIntoBase64` takes an input source and encodes it as base64 into the output buffer.
  • Uint8Array_ — Proxy type of {@code Uint8Array<ArrayBuffer>} or {@code Uint8Array} in TypeScript 5.7 or below respectively.