Package: effect
Module: Encoding
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
decodeBase64Url for decoding URL-safe Base64 to bytesdecodeBase64UrlString for decoding URL-safe Base64 to UTF-8 textencodeBase64 for standard padded Base64 outputSignature
declare const encodeBase64Url: (input: Uint8Array | string) => string
Since v2.0.0