talira

Generates RFC 9562 UUIDs in JavaScript and TypeScript

open sourceMITfree

uuid is the npm package for creating and handling RFC 9562 (formerly RFC 4122) UUIDs in JavaScript and TypeScript. It generates every version the RFC defines: v1 and v6 timestamps, v3 and v5 namespace UUIDs, random v4 and Unix-time v7, with helpers to parse, stringify, validate and detect a UUID's version and to convert between v1 and v6. It has no dependencies, is tree-shakable, takes its random values from the platform's crypto API, and runs in Node.js and modern browsers; a uuid command generates them from the shell.

Problems it solves

  • generate a random unique id in JavaScript
  • make time-ordered UUIDs I can sort by creation time in Node.js
  • check whether a string is a valid UUID in the browser

Features

  • Generates UUID versions 1, 3, 4, 5, 6 and 7
  • Parses, stringifies and validates UUIDs and detects their version
  • Converts between version 1 and version 6 UUIDs
  • No dependencies and tree-shakable, with TypeScript types
  • A uuid command line tool

Limitations

  • CommonJS isn't supported from uuid 12: the package is ESM only1
  • Needs crypto.getRandomValues(): React Native and other environments without it need a polyfill1

Alternatives

The same job

These do what uuid does.

  1. Nano ID Tiny, secure, URL-friendly unique string ID generator for JavaScript

Compare uuid with the top 3