Unicode-safe Base64 Encoding and Decoding Library – Base64Plus

Category: Javascript | March 19, 2025
Authornassiry
Last UpdateMarch 19, 2025
LicenseMIT
Tags
Views26 views
Unicode-safe Base64 Encoding and Decoding Library – Base64Plus

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

Base64Plus employs a dual-layer architecture with Base64Utils and Base64Plus classes. The Base64Utils class manages environment detection and provides appropriate encoding/decoding functions based on the runtime context. The Base64Plus class serves as the main interface, handling input validation and Unicode conversion through the TextEncoder and TextDecoder APIs.

The library uses Universal Module Definition (UMD) for broad compatibility across different module systems. It automatically detects the execution environment and adapts its functionality accordingly, using Node.js Buffer API in Node.js environments and native browser functions in web browsers.

How to use it:

1. Install and import the Base64Plus library.

# NPM
$ npm install base64plus
// ES Modules
import Base64Plus from "base64plus";
// Node.js (CommonJS)
const Base64Plus = require("base64plus");
// Browser
<script src="/base64Plus.umd.js"></script>

2. Decode & encode strings.

// => Q1NTU2NyaXB0LkNvbQ==
Base64Plus.encode("CSSScript.Com")
// => CSSScript.Com
Base64Plus.decode("Q1NTU2NyaXB0LkNvbQ==")
// => True
Base64Plus.isValid("Q1NTU2NyaXB0LkNvbQ==")
// => False
Base64Plus.isValid("CSSScript.Com")

3. Decode and encode URLs.

Base64Plus.encodeUrl("https://CSSScript.Com")
Base64Plus.decodeUrl("URL-safe Base64 string")

Changelog:

v1.2.0 (03/19/2025)

  • Added encodeUrl and decodeUrl methods
  • Improved performance and proper error handling

v1.1.0 (02/24/2025)

  • deprecate isValidBase64 in favor of isValid

v1.0.28 (02/23/2025)

  • Improved performance and proper error handling

You Might Be Interested In:


Leave a Reply