uuidjs /uuid

Generate RFC-compliant UUIDs in JavaScript

★ 15,346⑂ 1,000👁 131⑃ 515● 445▤ 17
TypeScriptMITCreated 2010-12-28
下载:v14.0.3v14.0.3 ↓14.0.32026-10-10
+1
日增长
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          | Arr

Discussions

Latest release

v14.0.3 v14.0.3 2026-10-10
14.0.3 (2026-10-09)


 Bug Fixes

 fix CITGM 1154 (981) (b44f159)

Snapshot: 2026-11-16T09:23:14Z · Data license Apache-2.0 · JSON