1.1.0 • Published 6 months ago
base64plus v1.1.0
Base64Plus
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
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!
ES Modules
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
TypeScript Usage
For TypeScript, just import Base64Plus and enjoy the full type support!
import Base64Plus from "base64plus"; const encoded: string = Base64Plus.encode("Hello, TypeScript!"); console.log(encoded); // Base64 string const decoded: string = Base64Plus.decode(encoded); console.log(decoded); // Hello, TypeScript!
2. API Reference
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.isValid(base64String: string): boolean
Checks if a string is a valid Base64 string.Deprecated:
Base64Plus.isValidBase64(base64String: string): boolean
UseBase64Plus.isValid
instead.
3. 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
For more details on contributing, see CONTRIBUTING.```bash npm test ```
Changelog
See CHANGELOG for release details.
License
This package is open-source software licensed under the MIT license.