effect-io-ai

Package: effect
Module: Encoding

Encoding.encodeBase64

Encodes the given value into a base64 (RFC4648) string.

When to use

Use to encode text or bytes as a standard padded Base64 string for storage or transport.

Details

String inputs are encoded as UTF-8 bytes before Base64 encoding. Uint8Array inputs are encoded directly. The output uses the standard RFC4648 alphabet with = padding.

Example (Encoding Base64 strings and bytes)

import { Encoding } from "effect"

// Encode a string
console.log(Encoding.encodeBase64("hello")) // "aGVsbG8="

// Encode binary data
const bytes = new Uint8Array([72, 101, 108, 108, 111])
console.log(Encoding.encodeBase64(bytes)) // "SGVsbG8="

See

Signature

declare const encodeBase64: (input: Uint8Array | string) => string

Source

Since v2.0.0