Registry / serialization / thirty-two

thirty-two

JSON →
library1.0.2jsnpmunverified

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.

npm install thirty-two
INSTALL
IMPORT
SIG · THIRTY-TWO
T
thirty-two
serializationjavascriptv1.0.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

base32
const base32 = require('thirty-two');
const { encode, decode } = require('thirty-two');
The package exports an object with `encode` and `decode` methods as its default. Destructuring directly will result in an error as it's not a CommonJS named export.
base32 (ESM)
import base32 from 'thirty-two';
import { encode, decode } from 'thirty-two';
This package is primarily CommonJS. While Node.js's interoperability allows `import base32 from 'thirty-two';` for default exports, directly named imports will fail. For optimal compatibility in modern ESM projects, consider a more contemporary Base32 library or a wrapper.
encode
const base32 = require('thirty-two'); base32.encode('data');
import { encode } from 'thirty-two'; encode('data');
The `encode` function is a method on the `base32` object. It is not a top-level named export. Access it via the imported `base32` object.

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')}`);
Debug
Known issues
gotchaThe `thirty-two` package is a CommonJS module and was last published 10 years ago. While Node.js provides interoperability for importing CommonJS modules into ESM projects, this package does not offer native ESM support. Projects built with modern ESM standards might experience unexpected behavior or require specific configuration for compatibility.
fix
Use `const base32 = require('thirty-two');` in CommonJS projects. In ESM, use `import base32 from 'thirty-two';`. If encountering issues, consider a more modern Base32 library with explicit ESM support.
affects: 1.0.2
gotchaBy default, `thirty-two.encode()` accepts both strings and Buffers, but `thirty-two.decode()` always returns a Node.js `Buffer`. When decoding data that was originally a string, you must call `.toString()` on the returned Buffer to convert it back to a readable string, ensuring correct character encoding (e.g., UTF-8).
fix
After decoding with `base32.decode(encodedString)`, always append `.toString('utf8')` (or another appropriate encoding) to the result if you expect a string: `base32.decode(encodedString).toString('utf8')`.
affects: 1.0.2
gotchaRFC 3548, which `thirty-two` implements, has been obsoleted by RFC 4648. While the fundamental Base32 encoding it provides is largely compatible, RFC 4648 introduces additional considerations and explicit recommendations for padding and specific alphabets (like Base32hex). Ensure that your usage aligns with the specific Base32 variant required by your application.
fix
Verify that the specific Base32 alphabet and padding rules implemented by `thirty-two` (RFC 3548) are suitable for your target system. If strict RFC 4648 compliance or other Base32 variants (e.g., Crockford's Base32, z-base-32) are needed, you might need a different library.
affects: 1.0.2
Errors
Common errors & fixes
TypeError: thirty-two.encode is not a function
Attempting to destructure `encode` or `decode` directly from the `require` statement (e.g., `const { encode } = require('thirty-two');`) or from an ESM named import (e.g., `import { encode } from 'thirty-two';`). The package exports a single object as its default.
fix
Import the entire object and access its methods: `const base32 = require('thirty-two'); base32.encode(...);` or `import base32 from 'thirty-two'; base32.encode(...);`.
RangeError: Buffer.byteLength(string) is not a positive integer
Passing an invalid or non-string/non-Buffer input to `base32.encode()` or `base32.decode()`. These functions expect either a string or a Node.js Buffer.
fix
Ensure that the input argument to `encode` or `decode` is always a `string` or a `Buffer` instance. For example, `base32.encode(String(yourValue))` or `base32.encode(Buffer.from(yourBinaryData))`.
Upgrade
Version history
1.0.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
5 hits · last 30 days
node
4
OpenAI (training)
1
Resources
thirty-two — npm install thirty-two · libregistry