base-64

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

Library
npm
v1.0.0
519 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
31 /100 Needs Attention
Development Activity 0
Maintenance 0
Community 44
Maturity 60
Momentum 20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
63 /100 Good
Architecture 68
Code Quality 68
Innovation 72
Learning Curve 45

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

AI Code Assistants · Automation · Developer Tools

16,015

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
58
Repo Health
84
Technical
60
Dependency
Built with
TypeScript 96%
Updated 3 months ago
JavaScript
99%
Other

ChartBrew

Analytics · Databases

4,063

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
JavaScript 99%
Updated 1 weeks ago
JavaScript
83%
Other

Countly

Analytics · Marketing

5,908

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
96
Repo Health
82
Technical
65
Dependency
Built with
JavaScript 83%
Updated 5 days ago
TypeScript
93%
AGPL 3.0

CourseLit

Blogging · Ecommerce

1,268

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

View details
77
Repo Health
74
Technical
68
Dependency
Built with
TypeScript 93%
Updated 6 days ago
TypeScript
79%
Other

Directus

CMS · Low Code Platforms

37,987

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
TypeScript 79%
Vue 19%
Updated 1 weeks ago
TypeScript
77%
Other

Joplin

Note Taking

56,513

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
60
Dependency
Built with
TypeScript 77%
JavaScript 14%
Updated 6 days ago
Python
58%
MIT

LibrePhotos

File Storage

8,083

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

View details
83
Repo Health
78
Technical
65
Dependency
Built with
Python 58%
TypeScript 40%
Updated 6 days ago
TypeScript
96%
Apache 2.0

Next AI Draw.io

AI Design Tools · Design Tools · Developer Tools

36,063

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

View details
78
Repo Health
80
Technical
68
Dependency
Built with
TypeScript 96%
Updated 6 days ago
JavaScript
57%
AGPL 3.0

ToolJet

AI Agents · Low Code Platforms · No Code Platforms

41,007

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
JavaScript 57%
TypeScript 36%
Updated 5 days 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