encodeBase64
import { encodeBase64 } from "jsr:@ende/encoding/unstable-base64";function ยท experimental
function encodeBase64(input: string | Uint8Array_ | ArrayBuffer, options: Base64Options = [UNSUPPORTED]): stringencodeBase64 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.
input: string | Uint8Array_ | ArrayBufferThe input source to encode.
options: Base64Options = [UNSUPPORTED]The options to use for encoding.
Returns
The base64 string representation of the input.
Example: Basic Usage
import { assertEquals } from "@ende/assert";
import {
encodeBase64,
type Uint8Array_
} from "@ende/encoding/unstable-base64";
assertEquals(encodeBase64("Hello World"), "SGVsbG8gV29ybGQ=");
assertEquals(
encodeBase64(new TextEncoder().encode("Hello World") as Uint8Array_),
"SGVsbG8gV29ybGQ=",
);
assertEquals(
encodeBase64("Hello World", { alphabet: "base64url" }),
"SGVsbG8gV29ybGQ",
);
assertEquals(
encodeBase64(
new TextEncoder().encode("Hello World") as Uint8Array_,
{ alphabet: "base64url" },
),
"SGVsbG8gV29ybGQ",
);