uuid is a JavaScript package for creating and parsing RFC 9562 UUIDs. It supports every standard version plus validation, conversion, and a CLI.
Overview
The uuid package generates and manipulates universally unique identifiers according to RFC 9562, formerly RFC 4122. APIs cover versions 1 through 7, including timestamp, random, and namespace-based IDs, along with conversions between versions 1 and 6.
Helper functions parse strings to byte arrays, stringify bytes back to canonical form, validate strings, and detect the RFC version of an existing UUID. NIL and MAX constant strings are provided. Random values use the platform crypto API where available.
Install from npm for use in Node, bundlers, and browsers tested on major desktop browsers; React Native needs a random-values polyfill imported first. A uuid command-line utility generates IDs, defaulting to version 4 with other versions available via flags.
Timestamp UUID methods can rely on internal state for uniqueness when called without options, or honor explicit options without that state. TypeScript releases within roughly the past two years are supported alongside current Node LTS and one prior release.
Key features
- All RFC 9562 UUID versions
- parse and stringify byte conversions
- validate and version detection
- v1, v3, v4, v5, v6, v7 generators
- Cross-platform crypto randomness
- TypeScript-friendly types
- Command-line uuid utility
- Browser and React Native support
Use cases
- Primary keys in applications
- Distributed ID generation
- Namespace-based deterministic IDs
- CLI UUID creation in scripts
- Validating UUID strings in APIs