effect-io-ai

Package: effect
Module: Encoding

Encoding.encodeBase64Url

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

When to use

Use to encode text or bytes as an unpadded Base64Url string for contexts that require the URL-safe alphabet.

Details

String inputs are encoded as UTF-8 bytes before Base64Url encoding. Uint8Array inputs are encoded directly. The output removes = padding and replaces + with - and / with _.

Example (Encoding URL-safe Base64)

import { Encoding } from "effect"

// URL-safe base64 encoding (uses - and _ instead of + and /)
console.log(Encoding.encodeBase64Url("hello?")) // "aGVsbG8_"

const bytes = new Uint8Array([72, 101, 108, 108, 111, 63])
console.log(Encoding.encodeBase64Url(bytes)) // "SGVsbG8_"

See

Signature

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

Source

Since v2.0.0