encodeBase64()function
Encode a string or binary data to a Base64 string.
encodeBase64(input: PossibleBytes, pad = true): string
Encode and decode data to and from standard Base64 and URL-safe Base64 (Base64URL). Useful for binary payloads, JWTs, cryptographic keys, and any context that needs ASCII-safe binary representation.
+/ or URL-safe -_), so you can call any decode function on either variant.=) for standard Base64 and no padding for Base64URL, matching common conventions.import { encodeBase64, decodeBase64String, decodeBase64Bytes } from "shelving/util";
encodeBase64("hello"); // "aGVsbG8="
encodeBase64("hello", false); // "aGVsbG8" (no padding)
decodeBase64String("aGVsbG8="); // "hello"
decodeBase64Bytes("aGVsbG8="); // Uint8Arrayimport { encodeBase64URL, decodeBase64URLString, decodeBase64URLBytes } from "shelving/util";
encodeBase64URL("hello"); // "aGVsbG8" (no padding by default)
encodeBase64URL("hello", true); // "aGVsbG8="
decodeBase64URLString("aGVsbG8"); // "hello"
decodeBase64URLBytes("aGVsbG8"); // Uint8ArrayAll encode functions accept a string, ArrayBuffer, or Uint8Array (PossibleBytes):
import { encodeBase64URL } from "shelving/util";
const key = crypto.getRandomValues(new Uint8Array(32));
const token = encodeBase64URL(key);Encode a string or binary data to a Base64 string.
encodeBase64(input: PossibleBytes, pad = true): string
Decode a Base64 string to a string (decodes Base64URL too).
decodeBase64String(base64: string): string
Decode a Base64 string to a byte sequence (decodes Base64URL too).
decodeBase64Bytes(base64: string): Bytes
Encode a string or binary data to a URL-safe Base64 string.
encodeBase64URL(input: PossibleBytes, pad = false): string
Decode a string from a URL-safe Base64 string (decodes Base64 too).
decodeBase64URLString(base64: string): string
Decode a URL-safe Base64 string to a byte sequence (decodes Base64 too).
decodeBase64URLBytes(base64: string): Bytes