base-64

A lightweight, RFC 4648-compliant base64 encoder and decoder for JavaScript, fully compatible with atob() and btoa().

Library
npm
v1.0.0
521stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
31/100Needs Attention
Development Activity0
Maintenance0
Community44
Maturity60
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
63/100Good
Architecture68
Code Quality68
Innovation72
Learning Curve45

base-64 is a compact, dependency-free base64 encoder and decoder for JavaScript, published to npm as base-64. It implements the exact algorithm described in RFC 4648 and is designed to be a drop-in substitute for the browser’s native atob() and btoa() functions in environments where they aren’t available, such as older versions of Node.js, Narwhal, RingoJS, and Rhino.

The library exposes just two functions, encode and decode, operating on binary strings where each character represents a single byte from 0x00 to 0xFF. For encoding arbitrary Unicode text, the README recommends pairing it with a UTF-8 encoding step (such as the author’s companion utf8.js library) before calling base64.encode. Despite its age, the package remains widely used, seeing millions of weekly downloads on npm, thanks to its small footprint, zero dependencies, and strict spec compliance.

What You Get

  • A single-purpose encode(input) function that mirrors native btoa() behavior for byte strings.
  • A single-purpose decode(input) function that mirrors native atob() behavior, including matching error messages.
  • Zero runtime dependencies and a tiny (~5KB unminified) source file with no build step required to consume it.
  • Support across a wide range of JavaScript environments: Node.js, Narwhal, RingoJS, Rhino, AMD loaders, and all major browsers.

Common Use Cases

  • Polyfilling atob()/btoa() in JavaScript engines that predate or omit those globals.
  • Encoding binary payloads such as images, files, or tokens to safely embed in JSON, URLs, or text-based protocols.
  • Decoding base64-encoded API responses or configuration values in server-side Node.js code.
  • Pairing with a UTF-8 encoder to safely base64-encode arbitrary Unicode strings.

Under The Hood

Architecture base-64 ships as a single UMD-wrapped module (base64.js) generated at build time from a template source file (src/base64.js) via Grunt’s grunt-template task, which injects computed values, namely the whitespace-character regex and the package version, from scripts/export-data.js before publishing. At runtime the module detects its environment (CommonJS/Node exports/module, AMD via define, or a global root) and attaches the same {encode, decode, version} object accordingly, so there is no branching public API across environments, only the export mechanism differs. encode and decode are pure, side-effect-free functions operating over a fixed lookup TABLE string, with a single shared error() helper that throws a custom InvalidCharacterError to match Chromium’s native atob/btoa messages. There is no internal layering beyond this because the problem domain doesn’t call for one; the notable design choice is pushing environment detection to build/load time rather than scattering environment checks through the codec logic itself.

Tech Stack Written in plain ES5 JavaScript with no runtime dependencies. Development tooling is entirely Grunt-based: grunt with grunt-shell (for running istanbul coverage and uploading to coveralls) and grunt-template (for the src-to-base64.js build step described above), configured in Gruntfile.js. Tests run under mocha using Node’s built-in assert module, in a single tests/tests.js file of over a thousand lines. Code coverage is measured with istanbul and reported to Coveralls. regenerate is used only inside scripts/export-data.js to programmatically construct the whitespace-character regex consumed by the codec. Continuous integration runs on Travis CI against multiple Node.js versions, executing a combined build-and-test task followed by a coverage upload step.

Code Quality Testing is thorough for the codec’s surface area: the test suite covers RFC 4648 test vectors, full-byte-range round-tripping, all padding cases, and explicit InvalidCharacterError assertions for malformed input, but there are no TypeScript types, no linter configuration, and no linting step in continuous integration, so style consistency relies on an editorconfig file rather than enforced tooling. Error handling is deliberate rather than incidental: invalid input paths funnel through a single error() helper that throws a typed InvalidCharacterError, mirroring native browser behavior instead of returning null or silently swallowing the failure. Naming is consistent camelCase throughout the compact core file, and the code favors explicit bitwise operations with inline comments explaining each shift, which aids readability given the low-level nature of the algorithm.

API Design The public surface is deliberately minimal: two functions, encode and decode, plus a version string, mirroring the exact signatures of btoa()/atob() so it can be dropped in as a polyfill with essentially no API-learning cost for anyone who already knows the DOM globals. Error messages are copied verbatim from Chromium’s native implementation, an unusually careful developer-experience touch, since code that already handles InvalidCharacterError from the browser API needs no changes to also handle this library’s errors. Documentation in the README is example-driven and directly addresses the one real gotcha, that encoding Unicode requires a UTF-8 pre-encoding step, with a companion utf8.js library recommended. Nothing here is technically novel, it’s a standard base64 algorithm with no new capability over native APIs, but as a polyfill/utility its ergonomics are close to ideal for its narrow scope.

Used by 9 apps in this directory

TypeScript
96%
Other

Amplication

Developer Tools · AI Code Assistants · Automation

16,011

Create production-ready backend services with your organization's standards baked in — generating NestJS, Prisma, and GraphQL code that you own and control.

View details
60
Repo Health
84
Technical
60
Dependency
Built with
TypeScript96%
Updated 2 months ago
JavaScript
99%
Other

ChartBrew

Analytics · Databases

4,054

Open-source reporting platform to build live dashboards from SQL, NoSQL, APIs, and SaaS tools with an AI assistant that creates charts from natural language.

View details
90
Repo Health
83
Technical
64
Dependency
Built with
JavaScript99%
Updated 4 days ago
JavaScript
83%
Other

Countly

Analytics · Marketing

5,896

Privacy-first, self-hosted analytics and customer engagement platform with full data ownership, GDPR compliance, and AI-powered insights across mobile, web, desktop, and IoT.

View details
95
Repo Health
82
Technical
65
Dependency
Built with
JavaScript83%
Updated 3 days ago
TypeScript
93%
AGPL 3.0

CourseLit

Ecommerce · Blogging

1,262

Open-source, self-hosted LMS for selling online courses, digital downloads, and building communities on your own branded website.

View details
75
Repo Health
74
Technical
71
Dependency
Built with
TypeScript93%
Updated 1 months ago
TypeScript
81%
Other

Directus

CMS · Low Code Platforms

37,783

Connect any SQL database and get instant REST and GraphQL APIs, a visual management Studio, and a native MCP server for AI agents — free for most organizations.

View details
92
Repo Health
82
Technical
76
Dependency
Built with
TypeScript81%
Vue18%
Updated 3 days ago
TypeScript
76%
Other

Joplin

Note Taking

56,257

The privacy-first, open-source note-taking app with end-to-end encrypted sync, AI assistance, and a powerful plugin ecosystem across every platform.

View details
93
Repo Health
87
Technical
61
Dependency
Built with
TypeScript76%
JavaScript14%
Updated yesterday
Python
65%
MIT

LibrePhotos

File Storage

8,061

Self-hosted photo library with AI-powered face recognition, semantic search, and automatic event albums — no cloud required.

View details
82
Repo Health
78
Technical
66
Dependency
Built with
Python65%
TypeScript32%
Updated 2 days ago
TypeScript
96%
Apache 2.0

Next AI Draw.io

Developer Tools · AI Design Tools · Design Tools

35,652

Turn natural language into professional draw.io diagrams with AI, cloud icons, and an MCP server for your IDE.

View details
83
Repo Health
80
Technical
72
Dependency
Built with
TypeScript96%
Updated yesterday
JavaScript
55%
AGPL 3.0

ToolJet

Low Code Platforms · No Code Platforms · AI Agents

40,857

Open-source AI-native platform to build and deploy internal tools, workflows, and AI agents with a visual drag-and-drop builder and 80+ data source integrations.

View details
94
Repo Health
81
Technical
63
Dependency
Built with
JavaScript55%
TypeScript38%
Updated today

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

Search