{"id":10791,"library":"encode32","title":"encode32","description":"encode32 is a utility for Base32 encoding 32-bit unsigned integers, drawing inspiration from Douglas Crockford's Base32 specification. Released as version 1.1.0, its release cadence is effectively abandoned, with the last publish being over 8 years ago and targeting Node.js versions as old as 0.4.7. Key differentiators include its design for human-friendliness and robustness, using 32 digits with case-insensitivity and aliases for easily confused characters (e.g., 'l' and 'I' for '1', 'o' for '0'). It notably excludes the character 'U' to avoid accidental obscenities. Instead of Crockford's suggested 'mod 37 checksum', this implementation incorporates a 3-bit parity checksum into the final character, enabling quick sanity checks without increasing length, but making it incompatible with other standard Base32 implementations. It is specifically designed for 32-bit numbers, though later additions (mentioned in the original README) hinted at support for up to 53-bit numbers with parity.","status":"abandoned","version":"1.1.0","language":"javascript","source_language":"en","source_url":"git://github.com/femto113/node-encode32","tags":["javascript"],"install":[{"cmd":"npm install encode32","lang":"bash","label":"npm"},{"cmd":"yarn add encode32","lang":"bash","label":"yarn"},{"cmd":"pnpm add encode32","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is CommonJS-only and does not support ES modules. The `encode32` and `decode32` functions are exported as named properties of the module.exports object.","wrong":"import { encode32 } from 'encode32';","symbol":"encode32","correct":"const { encode32 } = require('encode32');"},{"note":"For convenience, the module also exports `decode32`. Attempting a default import will fail as there isn't one.","wrong":"import decode32 from 'encode32';","symbol":"decode32","correct":"const { decode32 } = require('encode32');"},{"note":"The module can be imported as a whole object, allowing access to `enc.encode32` and `enc.decode32`. This is the pattern shown in the original documentation.","wrong":"import enc from 'encode32';","symbol":"entire module","correct":"const enc = require('encode32');"}],"quickstart":{"code":"const { encode32, decode32 } = require('encode32');\n\nconst originalNumber = 123456772;\nconst encodedString = encode32(originalNumber);\n\nconsole.log(`Original Number: ${originalNumber}`); // Expected: 123456772\nconsole.log(`Encoded String: ${encodedString}`); // Expected: 0XDWT16\n\n// Decoding various case/alias forms\nconst variations = [\n  \"0xdwt16\", // lower case\n  \"oXDWTi6\", // o for 0 and i for 1\n  \"OxDwtL6\"  // O for 0 and L for 1\n];\n\nconst decodedNumbers = variations.map(s => decode32(s));\nconsole.log(`Decoded variations: ${decodedNumbers}`); // Expected: [123456772, 123456772, 123456772]\n\n// Demonstrating parity check failure\nconst invalidInputs = [\n  \"0XDWT18\", // incorrect final digit\n  \"X0DWT16\", // transposed digits\n  \"0XDT16\"   // missing digit\n];\n\nconst invalidDecodes = invalidInputs.map(s => decode32(s));\nconsole.log(`Invalid decodes (expect NaN): ${invalidDecodes}`); // Expected: [NaN, NaN, NaN]","lang":"javascript","description":"This quickstart demonstrates encoding a 32-bit integer, decoding its case-insensitive and aliased variations, and shows how invalid inputs fail the parity check, resulting in `NaN`."},"warnings":[{"fix":"If interoperability with other Crockford Base32 implementations is required, consider alternatives like `base32-encode` or `ts-base32` which explicitly support the Crockford variant, or implement a compatible checksum/no-checksum logic manually.","message":"The package's custom 3-bit parity checksum makes it incompatible with standard Crockford Base32 implementations, which use an optional 'mod 37 checksum' or no checksum at all. Encoded strings from `encode32` cannot be reliably decoded by other Crockford Base32 libraries, and vice-versa, without custom adaptation.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"For new projects or critical applications, consider using actively maintained Base32 libraries that support the Crockford variant, such as `base32-encode` or `ts-base32`, which offer more robust and up-to-date solutions.","message":"This package is unmaintained, with its last update over 8 years ago and targeting very old Node.js versions (0.4.7). The 'TODO' list in the README indicates critical features like performance improvements and compatibility modes were never implemented, suggesting a lack of ongoing development and potential for unaddressed bugs or performance issues.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Validate input numbers to ensure they fit within a 32-bit unsigned integer range (0 to 4,294,967,295). For larger integers (e.g., 64-bit IDs), use libraries designed for arbitrary-precision integers or those that explicitly support `BigInt` for encoding.","message":"The library explicitly states it's for 32-bit numbers, encoding into 7 base-32 digits. While the README mentions fixed-length encoders for 32 and 41-bit numbers, and generators up to 53 bits, the primary exported functions (encode32/decode32) are likely optimized or limited to 32-bit unsigned integers. Attempting to encode larger numbers may lead to incorrect results, silent truncation, or unexpected errors due to JavaScript's number representation.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure the package is imported using `require()` syntax. If your project is pure ESM, you may need to wrap `require()` or use a different Base32 library that provides ESM support.","message":"The library is CommonJS-only (`require`). Attempting to import it using ES module syntax (`import`) in a modern Node.js or browser environment configured for ESM will result in an error.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"If in an ESM file, convert `import { encode32, decode32 } from 'encode32';` to `const { encode32, decode32 } = await import('encode32');` or, preferably, switch to a modern library that officially supports ESM. If in a CJS file, ensure `require()` is used correctly.","cause":"Attempting to use `require()` in an ES module context, or vice-versa, attempting `import` for a CommonJS-only package.","error":"TypeError: require is not a function"},{"fix":"Ensure the input string is a correctly formatted 7-character Base32 string that was originally encoded by this library, and verify no characters are transposed or missing. The library's parity check is strict.","cause":"The input string to `decode32` is not a valid `encode32` string (e.g., incorrect format, invalid characters, or failed parity check).","error":"NaN (Not a Number) returned from decode32"},{"fix":"Pre-validate numbers to ensure they are within the 32-bit unsigned integer range (0 to 4,294,967,295) before passing them to `encode32`. For larger numbers, use a `BigInt`-compatible or 64-bit encoding library.","cause":"While not explicitly documented, attempting to encode a number larger than 2^32 - 1 (the maximum for a 32-bit unsigned integer) into `encode32` might lead to incorrect encoding or a runtime error, as the library is designed for 32-bit numbers.","error":"RangeError: Value out of range for uint32"}],"ecosystem":"npm"}