Registry / serialization / base32.js

base32.js

JSON →
library0.1.0jsnpmunverified

This package provides implementations for various Base32 encoding schemes, including RFC 4648 and Crockford's Base32, tailored for JavaScript environments. Base32 offers distinct advantages over Base64, such as case-insensitivity, suitability for filenames (as it avoids the '/' character), and an alphabet carefully designed to minimize ambiguous characters (e.g., omitting 1, 8, 0 to prevent confusion with I, B, O). However, this comes at the cost of increased data size, with Base32 representations being approximately 20% larger than Base64. The package is currently at version 0.1.0, suggesting it is either an early-stage project or one that has not seen significant updates or active maintenance in a considerable amount of time, lacking a clear release cadence. It differentiates itself by supporting multiple Base32 variants and providing pre-built files for browser compatibility.

npm install base32.js
INSTALL
IMPORT
SIG · BASE32.JS
B
base32.js
serializationjavascriptv0.1.0
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
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 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

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

base32 (module object)
✓ const base32 = require("base32.js");
✗ import base32 from "base32.js";
This package primarily targets CommonJS environments, exporting an object containing `Encoder` and `Decoder` classes. The `import base32 from 'base32.js'` syntax is incorrect for this type of CommonJS export in ESM.
{ Encoder, Decoder } (destructured CommonJS)
✓ const { Encoder, Decoder } = require("base32.js");
✗ const Encoder = require("base32.js").Encoder;
Direct destructuring is the idiomatic and clearer way to access the exported classes within CommonJS modules.
base32 (ESM interop for CJS module)
✓ import * as base32 from 'base32.js';
✗ import base32 from 'base32.js';
When used in an ES Module environment, importing an older CommonJS module that exports an object typically requires a `* as` import to correctly access its named properties like `base32.Encoder`.

This quickstart demonstrates encoding and decoding binary data using Crockford Base32 and the default RFC4648 (no padding) variant, showcasing the streaming API.

const base32 = require("base32.js"); console.log("Encoding a buffer using Crockford Base32 (lowercase)..."); const buf = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; // Extended buffer for a more realistic example const encoder = new base32.Encoder({ type: "crockford", lc: true }); const encodedStr = encoder.write(buf).finalize(); console.log(`Original buffer: [${buf.join(', ')}]`); console.log(`Encoded string: ${encodedStr}`); console.log("\nDecoding the string back..."); const decoder = new base32.Decoder({ type: "crockford" }); const decodedBuf = decoder.write(encodedStr).finalize(); console.log(`Decoded buffer: [${decodedBuf.join(', ')}]`); // Example with default RFC4648 without padding console.log("\nEncoding with default RFC4648 (no padding)..."); const rfc4648Buf = Buffer.from("Hello World"); // Using Buffer for wider compatibility const rfcEncoder = new base32.Encoder(); // Default is rfc4648, no padding const rfcEncodedStr = rfcEncoder.write(rfc4648Buf).finalize(); console.log(`Original string: ${rfc4648Buf.toString()}`); console.log(`Encoded RFC4648: ${rfcEncodedStr}`); const rfcDecoder = new base32.Decoder(); const rfcDecodedBuf = rfcDecoder.write(rfcEncodedStr).finalize(); console.log(`Decoded RFC4648: ${rfcDecodedBuf.toString()});
Debug
Known issues
breakingThis package is at version 0.1.0 and appears to be unmaintained. There is no active development, explicit support for modern JavaScript features like ES Modules, or official TypeScript types. Users should be aware of potential compatibility issues with newer Node.js versions, build tools, or browser environments, and the absence of security patches.
fix
Consider migrating to a more actively maintained Base32 library that supports modern JavaScript environments and provides ongoing security updates. If continued use is necessary, carefully review the source code for vulnerabilities and ensure compatibility with your target environment.
affects: >=0.1.0
gotchaThe library's API uses a streaming encoder/decoder pattern (`.write().finalize()`), which might be unfamiliar to users expecting direct `encode(input)` and `decode(input)` functions. This pattern requires calling `.write()` with the input data, then `.finalize()` to get the result.
fix
Always remember to call both `.write(data)` and `.finalize()` to process data and retrieve the output from `Encoder` and `Decoder` instances.
affects: >=0.1.0
gotchaThe default Base32 variant is RFC 4648 *without* padding, which might differ from other Base32 implementations that commonly use padding by default. Incorrectly handling padding can lead to decoding errors or incompatible output with other systems.
fix
Explicitly configure the `type` and `padding` options in the `Encoder` and `Decoder` constructors to ensure compatibility with your target Base32 standard and padding requirements (e.g., `{ type: 'rfc4648', padding: true }`).
affects: >=0.1.0
Errors
Common errors & fixes
ReferenceError: require is not defined
Attempting to use `require()` in an ES Module (`.mjs` file or `"type": "module"` in `package.json`).
fix
Use `import * as base32 from 'base32.js';` and ensure your bundler or Node.js environment is configured to handle CommonJS interop.
TypeError: base32.Encoder is not a constructor
Incorrect ES Module import of the CommonJS module. You might have tried `import base32 from 'base32.js';` which does not correctly capture the module's object export.
fix
Use `import * as base32 from 'base32.js';` to import the module object containing `Encoder` and `Decoder`.
Error: Missing data at end of buffer
Mismatch in padding settings between the encoder and decoder, or providing an invalid Base32 string to the decoder.
fix
Ensure both `Encoder` and `Decoder` are initialized with the same `type` and `padding` options. If the encoded string was padded, the decoder must be initialized with `{ padding: true }`. Verify the input string is valid Base32 according to the specified type.
Upgrade
Version history
0.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
5 hits · last 30 days
node
4
OpenAI (training)
1
Resources
base32.js — npm install base32.js · libregistry