The `uid` package provides a highly optimized and compact utility for generating fixed-length random unique IDs in JavaScript environments, supporting both Node.js and browsers. The current stable version is 2.0.2, with releases focusing on performance, bug fixes, and TypeScript compatibility, indicating an active maintenance and development cadence. Key differentiators include its extremely small footprint (130B to 205B gzipped) and high performance, with benchmarks showing it to be significantly faster than alternatives like `nanoid` in its default non-secure mode. It offers three distinct modes: `uid` (fast, `Math.random`-based, non-secure), `uid/secure` (cryptographically secure via `crypto.getRandomValues`), and `uid/single` (non-secure, no internal cache, ideal for short-lived environments). This flexibility allows developers to choose the appropriate balance of speed, security, and bundle size for their specific use case.
npm install uidVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to import and use the default, secure, and single-use `uid` generators with custom lengths.
Change `import uid from 'uid';` to `import { uid } from 'uid';`. For CommonJS, `const uid = require('uid');` should become `const { uid } = require('uid');`.For cryptographically secure unique IDs, use `import { uid } from 'uid/secure';`. Ensure the environment (Node.js or browser) supports the Web Crypto API's `crypto.getRandomValues()`.Verify `crypto.getRandomValues` availability in target environments if using `uid/secure`. For universal compatibility or non-security-critical needs, fall back to the default `uid` or `uid/single`.
For applications requiring a very high guarantee of uniqueness, consider using longer ID lengths or cryptographically secure methods (`uid/secure`) and evaluate the probability of collisions based on your specific use case.
Change the import statement to `import { uid } from 'uid';`.Destructure the `uid` function: `const { uid } = require('uid');`.No dependency data recorded yet.