{"id":12140,"library":"thirty-two","title":"Base32 Encoding/Decoding for Node.js","description":"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.","status":"maintenance","version":"1.0.2","language":"javascript","source_language":"en","source_url":"git://github.com/chrisumbel/thirty-two","tags":["javascript","base32","encoding"],"install":[{"cmd":"npm install thirty-two","lang":"bash","label":"npm"},{"cmd":"yarn add thirty-two","lang":"bash","label":"yarn"},{"cmd":"pnpm add thirty-two","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"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.","wrong":"const { encode, decode } = require('thirty-two');","symbol":"base32","correct":"const base32 = require('thirty-two');"},{"note":"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.","wrong":"import { encode, decode } from 'thirty-two';","symbol":"base32 (ESM)","correct":"import base32 from 'thirty-two';"},{"note":"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.","wrong":"import { encode } from 'thirty-two'; encode('data');","symbol":"encode","correct":"const base32 = require('thirty-two');\nbase32.encode('data');"}],"quickstart":{"code":"import base32 from 'thirty-two';\nimport { Buffer } from 'buffer';\n\n// Encode a string\nconst originalString = 'Hello, Base32!';\nconst encodedString = base32.encode(originalString);\nconsole.log(`Original string: '${originalString}'`);\nconsole.log(`Encoded string:  '${encodedString}'`);\n\n// Decode a Base32 string back to a string\nconst decodedString = base32.decode(encodedString).toString();\nconsole.log(`Decoded string:  '${decodedString}'`);\n\n// Encode a Buffer for binary-safe handling\nconst originalBuffer = Buffer.from([0xDE, 0xAD, 0xBE, 0xEF]);\nconst encodedBufferString = base32.encode(originalBuffer);\nconsole.log(`\\nOriginal buffer: ${originalBuffer.toString('hex')}`);\nconsole.log(`Encoded buffer:  '${encodedBufferString}'`);\n\n// Decode a Base32 string back to a Buffer\nconst decodedBuffer = base32.decode(encodedBufferString);\nconsole.log(`Decoded buffer:  ${decodedBuffer.toString('hex')}`);\n","lang":"javascript","description":"Demonstrates how to encode and decode both regular strings and binary data (Buffers) using the `thirty-two` library, illustrating basic usage."},"warnings":[{"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.","message":"The `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.","severity":"gotcha","affected_versions":"1.0.2"},{"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')`.","message":"By 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).","severity":"gotcha","affected_versions":"1.0.2"},{"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.","message":"RFC 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.","severity":"gotcha","affected_versions":"1.0.2"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Import the entire object and access its methods: `const base32 = require('thirty-two'); base32.encode(...);` or `import base32 from 'thirty-two'; base32.encode(...);`.","cause":"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.","error":"TypeError: thirty-two.encode is not a function"},{"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))`.","cause":"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.","error":"RangeError: Buffer.byteLength(string) is not a positive integer"}],"ecosystem":"npm"}