A tiny (130B-205B) and fast utility to generate random IDs of fixed length for Node.js and browsers.
uid is a lightweight JavaScript utility for generating random, fixed-length unique identifiers. It solves the need for fast and small ID generation in both Node.js and browser applications, offering multiple modes to balance speed and security. The library is designed to be extremely performant while maintaining a minimal bundle size.
JavaScript developers who need fast, lightweight unique ID generation for applications, especially those sensitive to bundle size or requiring high-performance operations.
Developers choose uid for its exceptional speed, tiny footprint, and flexibility across different security requirements, outperforming alternatives like nanoid and uuid in benchmarks while being simpler to use.
A tiny (130B to 205B) and fast utility to generate random IDs of fixed length
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Benchmarks in the README show uid outperforms alternatives like nanoid and uuid, with the default mode reaching over 20 million operations per second in Node.js.
The library is incredibly small, ranging from 131 to 205 bytes gzipped across its modes, minimizing footprint in web bundles.
Offers three versions: default (fast, non-secure), secure (cryptographically safe), and single (no cache), allowing developers to balance speed and security needs.
Preconfigured for native ES modules in Node.js with fallbacks to CommonJS and UMD, ensuring easy integration in modern JavaScript setups.
The README explicitly states it does not generate UUID v4 strings, requiring a separate package (@lukeed/uuid) for that format, which adds complexity for standard use cases.
Limited to hexadecimal or alphanumeric characters only, with no option for custom alphabets, restricting flexibility compared to libraries like nanoid.
Default and secure modes preallocate internal buffers (e.g., 4096 bytes for secure), which can be inefficient for short-lived or memory-sensitive environments, though uid/single mitigates this.