js-base64

Pure-JavaScript Base64 encoder/decoder with full Unicode and URL-safe support

Library
npm
v3.9.4
4,363 stars
BSD 3-Clause License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
68 /100 Good
Development Activity 60
Maintenance 32
Community 80
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
76 /100 Good
Architecture 75
Code Quality 80
Innovation 65
Learning Curve 85

js-base64 is a dependency-free Base64 transcoder for JavaScript and TypeScript that works consistently across browsers, Node.js, Deno, and Bun. Unlike the built-in btoa/atob functions, which only handle Latin1 binary strings and throw on non-ASCII text, js-base64 correctly encodes and decodes arbitrary Unicode strings (including emoji and multi-byte UTF-8 text) by internally using TextEncoder/TextDecoder where available and falling back to hand-written polyfills where they are not.

The library ships as CommonJS, an ES module, and a UMD/browser global, with first-class TypeScript declaration files for both, so it drops into virtually any JavaScript environment without configuration. It also supports the URL-safe Base64 variant (-/_ instead of +//, no padding) out of the box, which is commonly needed for JWTs, URL query parameters, and filenames — one of the most common reasons projects reach for a dedicated Base64 library instead of the platform built-ins.

What You Get

  • Base64.encode/Base64.decode functions that correctly round-trip full Unicode strings, including multi-byte UTF-8 and emoji
  • URL-safe Base64 encoding/decoding (-/_ alphabet, optional padding removal) for use in JWTs, URLs, and filenames
  • Drop-in polyfills for native btoa/atob behavior where the environment lacks them
  • Distribution as CommonJS (base64.js), ES module (base64.mjs), and UMD/browser global, each with matching TypeScript declarations
  • Zero runtime dependencies and a small, auditable single-file implementation

Common Use Cases

  • Encoding/decoding JWT header and payload segments in auth middleware
  • Safely embedding binary data (images, files) as Base64 strings in JSON payloads or data URIs
  • URL-safe encoding of identifiers or tokens passed as query parameters or path segments
  • Cross-runtime utilities that need identical Base64 behavior in both browser and Node.js/Deno code
  • Encoding Unicode strings for storage or transport where native btoa would throw on non-Latin1 characters

Under The Hood

Architecture The library is authored as a single TypeScript source file (base64.ts, ~300 lines) that is compiled to three distribution targets: a CommonJS build (base64.js), an ES module (base64.mjs), and matching .d.ts/.d.mts type declarations, all wired together via package.json exports conditions so bundlers and runtimes resolve the right format automatically. Internally, encode/decode operations branch on feature detection: where TextEncoder/TextDecoder are available (all modern browsers, Node, Deno, Bun) they’re used directly for UTF-8 conversion; where they aren’t, hand-written btoaPolyfill/atobPolyfill functions perform the same conversion byte-by-byte using character-code arithmetic.

Tech Stack Written in TypeScript with zero runtime dependencies, built via a Makefile (not a JS bundler) that invokes tsc to emit the CJS/ESM/type-declaration outputs, and tested with Mocha. The test/ directory includes targeted suites for BOM handling, large-input performance, atob compatibility, and ES5 vs ES6 code paths.

Code Quality Test coverage spans edge cases specific to Base64/Unicode correctness — byte-order-mark handling (bom.js), large payloads (large.js), ES5 fallback behavior (es5.js) — rather than just happy-path encode/decode, reflecting the project’s long history of fixing subtle cross-environment bugs. The single-file implementation keeps the surface area small enough to audit fully, and inline JSDoc comments document each exported function’s parameters and return values.

API Design The API centers on a Base64 namespace object (Base64.encode, Base64.decode, Base64.encodeURI, etc.) plus equivalent named exports (encode, decode) for consumers who prefer tree-shakeable imports over the namespace object — both documented side by side in the README so migrating between styles is a one-line change. noConflict() is provided for browser-global usage to avoid clobbering an existing Base64 global, a detail that shows attention to real-world script-tag consumption alongside modern module usage.

Used by 20 apps in this directory

TypeScript
98%
MPL 2.0

Logto

Authentication

14,769

Open-source auth infrastructure for SaaS and AI apps with OIDC, SAML, and RBAC

View details
92
Repo Health
83
Technical
63
Dependency
Built with
TypeScript 98%
Updated 1 weeks ago
TypeScript
92%
Other

n8n

Automation · No Code Platforms

208,437

Code when you need it, UI when you don't — the workflow automation platform built for technical teams who refuse to choose.

View details
95
Repo Health
87
Technical
62
Dependency
Built with
TypeScript 92%
Updated 1 weeks ago
TypeScript
81%
MIT

OpenCode

AI Code Assistants

220,711

A fully open-source AI coding agent built for the terminal, with a TUI, desktop app, web client, plugin system, and SDK — one of the most-starred AI coding agents on GitHub.

View details
89
Repo Health
76
Technical
66
Dependency
Built with
TypeScript 81%
MDX 16%
Updated 6 days ago
TypeScript
51%
ZLIB

Portainer

Devops

38,707

A lightweight, open-source web UI that puts Docker, Kubernetes, and Podman management within reach of any team—no CLI expertise required.

View details
93
Repo Health
79
Technical
65
Dependency
Built with
TypeScript 51%
Go 38%
Updated 1 weeks ago
TypeScript
99%
MIT

React Cosmos

Developer Tools

8,690

An open-source sandbox for developing and testing React and React Native UI components in isolation, with pluggable bundler support for Vite and Webpack.

View details
76
Repo Health
69
Technical
73
Dependency
Built with
TypeScript 99%
Updated 1 weeks ago
Rust
72%
Apache 2.0

Rivet

AI Agents · Developer Tools

6,326

Stateful actors as a primitive for AI agents, real-time collaboration, and durable execution — with in-memory state, WebSockets, queues, and scheduling built in.

View details
87
Repo Health
81
Technical
64
Dependency
Built with
Rust 72%
TypeScript 25%
Updated 6 days ago
TypeScript
67%
MIT

Scalar

Developer Tools

16,313

Beautiful, interactive OpenAPI documentation with a built-in offline-first API client and multi-language code generation — all in one open-source platform.

View details
90
Repo Health
89
Technical
65
Dependency
Built with
TypeScript 67%
Vue 29%
Updated 6 days ago
TypeScript
50%
Other

SigNoz

Analytics · Monitoring

32,429

Self-host your entire observability stack — logs, metrics, traces, and LLM monitoring — in one OpenTelemetry-native platform, without the Datadog bill.

View details
92
Repo Health
83
Technical
64
Dependency
Built with
TypeScript 50%
Go 38%
Updated 1 weeks ago
TypeScript
98%
Apache 2.0

TinaCMS

CMS

13,845

An open-source, Git-backed headless CMS that gives editors a live visual editing UI over Markdown, MDX, JSON, and YAML content while developers keep everything in version control.

View details
92
Repo Health
74
Technical
59
Dependency
Built with
TypeScript 98%
Updated 1 weeks ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers