Try it Live
Run Base64 examples in the interactive playground
BrandedBase64
Tree-shakeable functional API for Base64 operations with optimal bundle size.Overview
BrandedBase64 is the functional layer providing base64 encoding/decoding operations. It offers:
- Tree-shakeable individual function exports
- Data-first unopinionated methods
- Bundle optimization through selective imports
- Zero dependencies on Web APIs (
btoa/atob)
Available Functions
All Base64 functionality available as tree-shakeable functions:Standard Encoding/Decoding
URL-Safe Encoding/Decoding
Validation
Utilities
Data-First Pattern
All BrandedBase64 functions follow data-first pattern:Tree-Shaking Benefits
Primary benefit: Selective inclusion of encoding variantsExample 1: Standard Only (Minimal)
Example 2: URL-Safe Only
Example 3: With Validation
Example 4: Complete (All Features)
Function Reference
Encoding Functions
Decoding Functions
Validation Functions
Utility Functions
Usage Patterns
Minimal Bundle (Basic Encoding)
With Validation
URL-Safe for Web APIs
Size Pre-calculation
When to Use BrandedBase64 vs Base64
Use BrandedBase64 When:
- Bundle size critical (mobile, embedded)
- Selective imports desired
- Only using specific variants (standard OR URL-safe)
- Functional style preferred
- Composing functions heavily
Use Base64 Namespace When:
- Using multiple variants
- Ergonomics over bundle size
- Simple namespace imports preferred
- All features needed anyway
Interoperability
BrandedBase64 functions work with Base64 namespace:Types
Implementation Details
All BrandedBase64 functions are implemented using Web APIs:encodeusesbtoa()for encodingdecodeusesatob()for decoding- URL-safe variants apply character substitutions
- No external dependencies
Performance
BrandedBase64 functions have same performance as Base64 namespace (same implementations):- Encoding: O(n) where n is input byte length
- Decoding: O(n) where n is input string length
- Validation: O(n) with early exit on invalid chars
- Size calculation: O(1) pure math
Bundle Size Comparison
Approximate gzipped sizes:
Tree-shaking savings most significant when using only one variant.
Related
- Encoding - Encoding operations
- Decoding - Decoding operations
- Validation - Format validation
- Utilities - Size calculations
- Base64 - Main Base64 namespace documentation
- Branded Types - Type branding pattern

