+1
Daily
15,346
stars
1,000
forks
131
watchers
515
prs
445
issues
17
releases
README
uuid
For the creation of RFC9562 (formerly RFC4122) UUIDs
- Complete - Support for all RFC9562 UUID versions
- Cross-platform - Support for...
- Typescript
- Chrome, Safari, Firefox, and Edge
- NodeJS
- React Native / Expo
- Secure - Uses modern crypto API for random values
- Compact - Zero-dependency, tree-shakable
- CLI - uuid command line utility
[!NOTE]
Starting with uuid@12 CommonJS is no longer supported. See implications and motivation for details.
Quickstart
1. Install
shell
npm install uuid
2. Create a UUID
javascript
import { v4 as uuidv4 } from 'uuid';
uuidv4(); // ⇨ 'b18794e8-5d0d-417c-b361-ba38e78411b4'
For timestamp UUIDs, namespace UUIDs, and other options read on ...
API Summary
| | |
| --- | --- |
| uuid.NIL | The nil UUID string (all zeros) |
| uuid.MAX | The max UUID string (all ones) |
| uuid.parse() | Convert UUID string to array of bytes |
| uuid.stringify() | Convert array of bytes to UUID string |
| uuid.v1() | Generate a version 1 (timestamp) UUID |
| uuid.v1ToV6() | Convert a version 1 UUID to version 6 |
| uuid.v3() | Generate a version 3 (namespace w/ MD5) UUID |
| uuid.v4() | Generate a version 4 (random) UUID |
| uuid.v5() | Generate a version 5 (namespace w/ SHA-1) UUID |
| uuid.v6() | Generate a version 6 (timestamp, reordered) UUID |
| uuid.v6ToV1() | Convert a version 6 UUID to version 1 |
| uuid.v7() | Generate a version 7 (Unix Epoch time-based) UUID |
| ~~uuid.v8()~~ | "Intentionally left blank" |
| uuid.validate() | Test a string to see if it is a valid UUID |
| uuid.version() | Detect RFC version of a UUID |
API
uuid.NIL
The nil UUID string (all zeros).
Example:
javascript
import { NIL as NIL_UUID } from 'uuid';
NIL_UUID; // ⇨ '00000000-0000-0000-0000-000000000000'
uuid.MAX
The max UUID string (all ones).
Example:
javascript
import { MAX as MAX_UUID } from 'uuid';
MAX_UUID; // ⇨ 'ffffffff-ffff-ffff-ffff-ffffffffffff'
uuid.parse(str)
Convert UUID string to array of bytes
| | |
| --------- | ---------------------------------------- |
| str | A valid UUID String |
| _returns_ | Uint8Array[16] |
| _throws_ | TypeError if str is not a valid UUID |
[!NOTE]
Ordering of values in the byte arrays used by parse() and stringify() follows the left ↠ right order of hex-pairs in UUID strings. As shown in the example below.
Example:
javascript
import { parse as uuidParse } from 'uuid';
// Parse a UUID
uuidParse('6ec0bd7f-11c0-43da-975e-2a8ad9ebae0b'); // ⇨
// Uint8Array(16) [
// 110, 192, 189, 127, 17,
// 192, 67, 218, 151, 94,
// 42, 138, 217, 235, 174,
// 11
// ]
uuid.stringify(arr[, offset])
Convert array of bytes to UUID string
| | |
| -------------- | ---------------------------------------------------------------------------- |
| arr | ArrDiscussions
#993Organization membership requirements for uuid contributors0 comments · 2026-11-03#958Help reconciling GitHub General Advisory with Repo Specific Advisory4 comments · 2026-05-19#872Which function do you recommend for generating session auth token?1 comments · 2025-04-25#766bump @types/uuid package1 comments · 2024-06-12#747Validation on the general shape of an uuid string1 comments · 2024-04-20#746What is the status of uuid v7?2 comments · 2024-03-31#735Do we still need the `uuid` library?1 comments · 2023-09-21#717How to check if UUID v5 was generated with a specific namespace?1 comments · 2023-05-21
Latest release
v14.0.3 v14.0.3 2026-10-1014.0.3 (2026-10-09) Bug Fixes fix CITGM 1154 (981) (b44f159)