{"id":11034,"library":"hexoid","title":"Hexoid ID Generator","description":"Hexoid is a minimalist (190B) and high-performance utility designed for generating fixed-length, randomized hexadecimal IDs in JavaScript environments, including Node.js and browsers. The current stable version is 2.0.0, which introduced significant changes for improved module interoperability. It is primarily used when a quick, unique string identifier is needed, but cryptographic security is not a requirement. Key differentiators include its extreme speed, small footprint, and focus on simple hexadecimal output, contrasting with larger, more feature-rich UUID libraries. While it provides good collision resistance for common use cases, users must be aware it is not cryptographically secure and the risk of collisions increases with shorter lengths, as detailed by the Birthday Problem.","status":"active","version":"2.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/lukeed/hexoid","tags":["javascript","id","uid","uuid","random","generate","typescript"],"install":[{"cmd":"npm install hexoid","lang":"bash","label":"npm"},{"cmd":"yarn add hexoid","lang":"bash","label":"yarn"},{"cmd":"pnpm add hexoid","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Since v2.0.0, hexoid is a named export for both ESM and CommonJS to standardize import patterns and improve TypeScript compatibility.","wrong":"import hexoid from 'hexoid';","symbol":"hexoid","correct":"import { hexoid } from 'hexoid';"},{"note":"For CommonJS, use destructuring assignment to access the named 'hexoid' export, aligning with ESM usage since v2.0.0.","wrong":"const hexoid = require('hexoid');","symbol":"hexoid (CommonJS)","correct":"const { hexoid } = require('hexoid');"},{"note":"The library ships with TypeScript types, and the generator function's type is exported as HexoidFn.","symbol":"hexoid (TypeScript type)","correct":"import type { HexoidFn } from 'hexoid';"}],"quickstart":{"code":"import { hexoid } from 'hexoid';\n\n// Create a generator for default length (16 characters)\nconst generateDefaultId = hexoid();\nconsole.log('Default ID:', generateDefaultId());\n// Example output: '52032fedb951da00'\n\n// Create a generator for a custom length (e.g., 25 characters)\nconst generateCustomId = hexoid(25);\nconsole.log('Custom length ID:', generateCustomId());\n// Example output: '065359875047c63a037200e00'\n\n// Create multiple IDs from the same generator\nconst toID = hexoid();\nconsole.log('ID 1:', toID());\nconsole.log('ID 2:', toID());\nconsole.log('ID 3:', toID());","lang":"typescript","description":"Demonstrates how to import the `hexoid` function and generate IDs with default and custom lengths."},"warnings":[{"fix":"Update your imports from `import hexoid from 'hexoid';` to `import { hexoid } from 'hexoid';` for ESM, and from `const hexoid = require('hexoid');` to `const { hexoid } = require('hexoid');` for CommonJS.","message":"The default export has been replaced with a named `hexoid` export. Direct default imports will no longer work.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Ensure your project's `tsconfig.json` (if using TypeScript) or bundler configuration supports `node16` or `nodenext` module resolution if experiencing module resolution issues.","message":"The package now uses an `exports` map for native ESM support, which may affect bundlers or older Node.js versions not configured for `node16` or `nodenext` module resolution.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"For security-sensitive ID generation (e.g., session tokens, password resets), use a CSPRNG-backed library like `crypto.randomUUID()` in Node.js or `window.crypto.getRandomValues()` in browsers.","message":"Hexoid is not a cryptographically secure random number generator (CSPRNG). It should not be used for security-sensitive applications where unpredictable uniqueness is paramount.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Always consider the required number of unique IDs and choose a sufficiently long ID length. The README provides a formula `256 ** (len/2)` for calculating maximum combinations to assess collision risk.","message":"Collision risk (Birthday Problem): Shorter ID lengths significantly increase the probability of generating duplicate IDs. While hexoid is fast, its internal counter can eventually wrap around.","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":"Change your import statement from `import hexoid from 'hexoid';` to `import { hexoid } from 'hexoid';`.","cause":"Attempting to use a default import for `hexoid` after v2.0.0 when it is now a named export in an ESM context.","error":"TypeError: (0 , hexoid__WEBPACK_IMPORTED_MODULE_0__.default) is not a function"},{"fix":"Change your CommonJS import from `const hexoid = require('hexoid');` to `const { hexoid } = require('hexoid');`.","cause":"Attempting to use `require('hexoid')` directly as a function call after v2.0.0 when `hexoid` is now a named export in CommonJS.","error":"TypeError: hexoid is not a function (when using CommonJS require)"}],"ecosystem":"npm"}