Skip to content

nassiry/base64plus

Repository files navigation

Base64Plus

Build Status npm version Total Downloads Latest Release License

Base64Plus is a modern, Unicode-safe Base64 encoding and decoding library. It supports Node.js, ES Modules, Browsers, and TypeScript with a built-in polyfill for Node.js environments.

  • Handles Unicode strings properly: Native atob/btoa fail with multi-byte characters like emojis or non-Latin scripts.
  • Works in both Node.js & Browsers: Node.js lacks atob/btoa, but Base64Plus provides a seamless polyfill.
  • Supports ES Modules & TypeScript: Fully typed for modern JavaScript projects.
  • Encodes and decodes Buffers: Unlike atob, which only works with plain strings.
  • No dependencies & lightweight: Small package size with no external dependencies.

Table Of Contents

  1. Installation
  2. Usage
  3. API Reference
  4. Development & Contribution
  5. Changelog
  6. License

1. Installation

  • Option 1: Install via NPM

    npm install base64plus
  • Option 2: Use via CDN

Include the UMD version directly in your HTML file:

<script src="https://github.com/nassiry/base64plus/releases/latest/download/base64Plus.umd.js"></script>
<script>
  console.log(Base64Plus.encode("Hello, World!"));
</script>
  • Option 3: Download Manually

Get the latest release from GitHub Releases.

2. Usage

  • Node.js (CommonJS)

    const Base64Plus = require("base64plus");
    
    const encoded = Base64Plus.encode("Hello, World!");
    console.log(encoded); // Base64 string
    
    const decoded = Base64Plus.decode(encoded);
    console.log(decoded); // Hello, World!
    
    const encodedUrl = Base64Plus.encodeUrl("Hello, World!");
    console.log(encodedUrl); // Base64 string  
    
    const decodedUrl = Base64Plus.decodeUrl(encodedUrl);
    console.log(decodedUrl); // Hello, World!
  • ES Modules / TypeScript

    import Base64Plus from "base64plus";
    
    const encoded = Base64Plus.encode("Base64 Encoding");
    console.log(encoded); // Base64 string
    
    const decoded = Base64Plus.decode(encoded);
    console.log(decoded); // Base64 Encoding

3. API Reference

Encoding and Decoding

  • Base64Plus.encode(input: string): string
    • Encodes a string to Base64 while supporting full Unicode characters.
  • Base64Plus.decode(base64String: string): string
    • Decodes a Base64 string back to a Unicode string.
  • Base64Plus.encodeUrl(input: string): string
    • Encodes a string to URL-safe Base64.
  • Base64Plus.decodeUrl(Base64String: string): string
    • Decodes a URL-safe Base64 string back to a Unicode string.

Validation

  • Base64Plus.isValid(base64String: string): boolean
    • Checks if a string is a valid Base64 string.

Deprecated: Base64Plus.isValidBase64(base64String: string): boolean Use Base64Plus.isValid instead.

4. Development & Contribution

Clone the Repository & install the dependencies.

git clone https://github.com/nassiry/base64plus.git
cd base64plus
npm install
  • Build the Project

    npm run build
  • Run Tests

    npm test

For more details on contributing, see CONTRIBUTING.

Changelog

See CHANGELOG for release details.

License

This package is open-source software licensed under the MIT license.