A native path via Uint8Array.prototype.toBase64({ alphabet: "base64url", omitPadding: true }) and
Uint8Array.fromBase64(..., { alphabet: "base64url" }) covers this use case in one step and has been
Baseline
across evergreen browsers since September 2025 (Chrome 140, Firefox 133, Safari 18.2). On Node.js, however,
V8 still gates it behind the experimental --js-base-64 flag. This module will switch to the native path once
Node exposes it unflagged; until then, it keeps delegating to btoa / atob for portable server-side support.
Provides a symmetric encoder/decoder pair (encodeBase64, decodeBase64) for safely carrying arbitrary
Unicode text in URLs and application/x-www-form-urlencoded payloads. Wraps the standard
btoa /
atob primitives, addressing two limitations that
make them unsuitable on their own for URL-bound text:
btoa / atob accept only binary (Latin-1) strings and throw on any code point above 0xFF. The codec routes
input through TextEncoder /
TextDecoder to convert between JavaScript strings
and UTF-8 byte sequences before delegating to the standard primitives, making multi-byte characters such as
"日" transparently encodable.
The standard base64 alphabet uses +, /, and =, all of which carry special meaning in URLs and
application/x-www-form-urlencoded payloads (+ is interpreted as space, / as a path separator, = as the
key/value separator). The codec adopts the URL-safe variant of RFC 4648 § 5, mapping + / / to - / _ on
encode (and back on decode) and stripping the trailing = padding. Decoding accepts both padded and unpadded
input.
URL-safe base64 string codec.
A native path via
Uint8Array.prototype.toBase64({ alphabet: "base64url", omitPadding: true })andUint8Array.fromBase64(..., { alphabet: "base64url" })covers this use case in one step and has been Baseline across evergreen browsers since September 2025 (Chrome 140, Firefox 133, Safari 18.2). On Node.js, however, V8 still gates it behind the experimental--js-base-64flag. This module will switch to the native path once Node exposes it unflagged; until then, it keeps delegating tobtoa/atobfor portable server-side support.Provides a symmetric encoder/decoder pair (encodeBase64, decodeBase64) for safely carrying arbitrary Unicode text in URLs and
application/x-www-form-urlencodedpayloads. Wraps the standardbtoa/atobprimitives, addressing two limitations that make them unsuitable on their own for URL-bound text:btoa/atobaccept only binary (Latin-1) strings and throw on any code point above0xFF. The codec routes input throughTextEncoder/TextDecoderto convert between JavaScript strings and UTF-8 byte sequences before delegating to the standard primitives, making multi-byte characters such as"日"transparently encodable.The standard base64 alphabet uses
+,/, and=, all of which carry special meaning in URLs andapplication/x-www-form-urlencodedpayloads (+is interpreted as space,/as a path separator,=as the key/value separator). The codec adopts the URL-safe variant of RFC 4648 § 5, mapping+//to-/_on encode (and back on decode) and stripping the trailing=padding. Decoding accepts both padded and unpadded input.Usage
See