js-base64 is a small JavaScript package for RFC 4648 Base64 and URL-safe base64url transcoding in browsers and Node.js.
Overview
js-base64 provides Base64 encoding and decoding for JavaScript environments. It can be installed as an npm package and used in browsers via script tags, ES modules, or CDNs, and in Node.js via CommonJS or ESM imports.
The default alphabet follows RFC 4648 section 4 with standard padding. URL-safe output uses the base64url alphabet from section 5 and omits padding through dedicated encode methods. Decode paths accept both alphabets with or without padding.
APIs distinguish text-oriented decode from byte-oriented atob-style handling and Uint8Array conversion, which matters for binary data such as images. Encoded strings are emitted without MIME-style line wrapping.
Optional extensions can attach helpers to built-in prototypes; the default build leaves prototypes untouched. The implementation targets ES5 for broader browser support.
Key features
- Standard and URL-safe Base64
- Browser and Node.js usage
- ES module and CommonJS
- UTF-8 decode and byte arrays
- encodeURI URL-safe helper
- CDN and npm install
- Optional prototype extensions
- Padding-flexible decode
Use cases
- Encoding API payloads
- Handling binary in the browser
- URL-safe token encoding
- Node.js data transforms
- Replacing ad-hoc btoa usage