Base32 Encoding/Decoding for Node.js

1.0.2 · maintenance · verified Sun Apr 19

The `thirty-two` package provides an implementation of the Base32 encoding and decoding algorithms as specified in RFC 3548 for Node.js environments. Base32 is a binary-to-text encoding scheme that uses a 32-character alphabet, commonly employed for situations where human readability or case-insensitivity is desired, and URL-safety is important (as it avoids common punctuation characters). While RFC 3548 has been obsoleted by RFC 4648, the core Base32 encoding defined within it remains a standard and widely used method. This package, currently at version 1.0.2 and last updated approximately 10 years ago, is a mature and stable utility that fulfills its specific function without active feature development, operating effectively in maintenance mode. It's a foundational library for basic binary data transformation.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to encode and decode both regular strings and binary data (Buffers) using the `thirty-two` library, illustrating basic usage.

import base32 from 'thirty-two';
import { Buffer } from 'buffer';

// Encode a string
const originalString = 'Hello, Base32!';
const encodedString = base32.encode(originalString);
console.log(`Original string: '${originalString}'`);
console.log(`Encoded string:  '${encodedString}'`);

// Decode a Base32 string back to a string
const decodedString = base32.decode(encodedString).toString();
console.log(`Decoded string:  '${decodedString}'`);

// Encode a Buffer for binary-safe handling
const originalBuffer = Buffer.from([0xDE, 0xAD, 0xBE, 0xEF]);
const encodedBufferString = base32.encode(originalBuffer);
console.log(`\nOriginal buffer: ${originalBuffer.toString('hex')}`);
console.log(`Encoded buffer:  '${encodedBufferString}'`);

// Decode a Base32 string back to a Buffer
const decodedBuffer = base32.decode(encodedBufferString);
console.log(`Decoded buffer:  ${decodedBuffer.toString('hex')}`);

view raw JSON →