Skip to main content

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)
Primary benefit: Import only the encoding/decoding variants you need, reducing bundle size when not using all features.

Available Functions

All Base64 functionality available as tree-shakeable functions:

Standard Encoding/Decoding

See Encoding and Decoding for details.

URL-Safe Encoding/Decoding

See Encoding and Decoding for details.

Validation

See Validation for details.

Utilities

See Utilities for details.

Data-First Pattern

All BrandedBase64 functions follow data-first pattern:
This enables functional composition:

Tree-Shaking Benefits

Primary benefit: Selective inclusion of encoding variants

Example 1: Standard Only (Minimal)

Bundle: Only standard base64 encoding/decoding. No URL-safe variants, no validation, no utilities.

Example 2: URL-Safe Only

Bundle: Only URL-safe encoding/decoding. No standard variants.

Example 3: With Validation

Bundle: Standard encoding/decoding + validation. No URL-safe variants, no utilities.

Example 4: Complete (All Features)

Bundle: All Base64 methods included.

Function Reference

Encoding Functions

Decoding Functions

Validation Functions

Utility Functions

Usage Patterns

Minimal Bundle (Basic Encoding)

Bundle size: ~200 bytes (encode + decode implementations)

With Validation

Bundle size: ~400 bytes (decode + validation)

URL-Safe for Web APIs

Bundle size: ~300 bytes (URL-safe variants only)

Size Pre-calculation

Bundle size: ~400 bytes (encode/decode + size utilities)

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

Source: types.ts

Implementation Details

All BrandedBase64 functions are implemented using Web APIs:
  • encode uses btoa() for encoding
  • decode uses atob() 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.