uuid 8.2.0-beta.0 → 8.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -1
- package/README.md +233 -167
- package/dist/esm-browser/index.js +6 -1
- package/dist/esm-browser/nil.js +1 -0
- package/dist/esm-browser/parse.js +35 -0
- package/dist/esm-browser/regex.js +1 -0
- package/dist/esm-browser/sha1.js +3 -0
- package/dist/esm-browser/stringify.js +30 -0
- package/dist/esm-browser/v1.js +2 -2
- package/dist/esm-browser/v35.js +13 -20
- package/dist/esm-browser/v4.js +2 -2
- package/dist/esm-browser/validate.js +7 -0
- package/dist/esm-browser/version.js +11 -0
- package/dist/esm-node/index.js +6 -1
- package/dist/esm-node/nil.js +1 -0
- package/dist/esm-node/parse.js +35 -0
- package/dist/esm-node/regex.js +1 -0
- package/dist/esm-node/rng.js +9 -2
- package/dist/esm-node/stringify.js +29 -0
- package/dist/esm-node/v1.js +2 -2
- package/dist/esm-node/v35.js +13 -20
- package/dist/esm-node/v4.js +2 -2
- package/dist/esm-node/validate.js +7 -0
- package/dist/esm-node/version.js +11 -0
- package/dist/index.js +40 -0
- package/dist/nil.js +8 -0
- package/dist/parse.js +45 -0
- package/dist/regex.js +8 -0
- package/dist/rng.js +10 -2
- package/dist/sha1-browser.js +3 -0
- package/dist/stringify.js +39 -0
- package/dist/umd/uuid.min.js +1 -1
- package/dist/umd/uuidNIL.min.js +1 -0
- package/dist/umd/uuidParse.min.js +1 -0
- package/dist/umd/uuidStringify.min.js +1 -0
- package/dist/umd/uuidValidate.min.js +1 -0
- package/dist/umd/uuidVersion.min.js +1 -0
- package/dist/umd/uuidv1.min.js +1 -1
- package/dist/umd/uuidv3.min.js +1 -1
- package/dist/umd/uuidv4.min.js +1 -1
- package/dist/umd/uuidv5.min.js +1 -1
- package/dist/v1.js +2 -2
- package/dist/v35.js +14 -20
- package/dist/v4.js +2 -2
- package/dist/validate.js +17 -0
- package/dist/version.js +21 -0
- package/package.json +29 -25
- package/wrapper.mjs +5 -0
- package/dist/bytesToUuid.js +0 -26
- package/dist/esm-browser/bytesToUuid.js +0 -18
- package/dist/esm-node/bytesToUuid.js +0 -18
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,30 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [8.3.1](https://github.com/uuidjs/uuid/compare/v8.3.0...v8.3.1) (2020-10-04)
|
|
6
|
+
|
|
7
|
+
### Bug Fixes
|
|
8
|
+
|
|
9
|
+
- support expo>=39.0.0 ([#515](https://github.com/uuidjs/uuid/issues/515)) ([c65a0f3](https://github.com/uuidjs/uuid/commit/c65a0f3fa73b901959d638d1e3591dfacdbed867)), closes [#375](https://github.com/uuidjs/uuid/issues/375)
|
|
10
|
+
|
|
11
|
+
## [8.3.0](https://github.com/uuidjs/uuid/compare/v8.2.0...v8.3.0) (2020-07-27)
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
|
|
15
|
+
- add parse/stringify/validate/version/NIL APIs ([#479](https://github.com/uuidjs/uuid/issues/479)) ([0e6c10b](https://github.com/uuidjs/uuid/commit/0e6c10ba1bf9517796ff23c052fc0468eedfd5f4)), closes [#475](https://github.com/uuidjs/uuid/issues/475) [#478](https://github.com/uuidjs/uuid/issues/478) [#480](https://github.com/uuidjs/uuid/issues/480) [#481](https://github.com/uuidjs/uuid/issues/481) [#180](https://github.com/uuidjs/uuid/issues/180)
|
|
16
|
+
|
|
17
|
+
## [8.2.0](https://github.com/uuidjs/uuid/compare/v8.1.0...v8.2.0) (2020-06-23)
|
|
18
|
+
|
|
19
|
+
### Features
|
|
20
|
+
|
|
21
|
+
- improve performance of v1 string representation ([#453](https://github.com/uuidjs/uuid/issues/453)) ([0ee0b67](https://github.com/uuidjs/uuid/commit/0ee0b67c37846529c66089880414d29f3ae132d5))
|
|
22
|
+
- remove deprecated v4 string parameter ([#454](https://github.com/uuidjs/uuid/issues/454)) ([88ce3ca](https://github.com/uuidjs/uuid/commit/88ce3ca0ba046f60856de62c7ce03f7ba98ba46c)), closes [#437](https://github.com/uuidjs/uuid/issues/437)
|
|
23
|
+
- support jspm ([#473](https://github.com/uuidjs/uuid/issues/473)) ([e9f2587](https://github.com/uuidjs/uuid/commit/e9f2587a92575cac31bc1d4ae944e17c09756659))
|
|
24
|
+
|
|
25
|
+
### Bug Fixes
|
|
26
|
+
|
|
27
|
+
- prepare package exports for webpack 5 ([#468](https://github.com/uuidjs/uuid/issues/468)) ([8d6e6a5](https://github.com/uuidjs/uuid/commit/8d6e6a5f8965ca9575eb4d92e99a43435f4a58a8))
|
|
28
|
+
|
|
5
29
|
## [8.1.0](https://github.com/uuidjs/uuid/compare/v8.0.0...v8.1.0) (2020-05-20)
|
|
6
30
|
|
|
7
31
|
### Features
|
|
@@ -11,7 +35,7 @@ All notable changes to this project will be documented in this file. See [standa
|
|
|
11
35
|
|
|
12
36
|
### Bug Fixes
|
|
13
37
|
|
|
14
|
-
- export package.json required by react-native and bundlers ([#449](https://github.com/uuidjs/uuid/issues/449)) ([be1c8fe](https://github.com/uuidjs/uuid/commit/be1c8fe9a3206c358e0059b52fafd7213aa48a52)), closes [
|
|
38
|
+
- export package.json required by react-native and bundlers ([#449](https://github.com/uuidjs/uuid/issues/449)) ([be1c8fe](https://github.com/uuidjs/uuid/commit/be1c8fe9a3206c358e0059b52fafd7213aa48a52)), closes [ai/nanoevents#44](https://github.com/ai/nanoevents/issues/44#issuecomment-602010343) [#444](https://github.com/uuidjs/uuid/issues/444)
|
|
15
39
|
|
|
16
40
|
## [8.0.0](https://github.com/uuidjs/uuid/compare/v7.0.3...v8.0.0) (2020-04-29)
|
|
17
41
|
|
package/README.md
CHANGED
|
@@ -2,112 +2,225 @@
|
|
|
2
2
|
-- This file is auto-generated from README_js.md. Changes should be made there.
|
|
3
3
|
-->
|
|
4
4
|
|
|
5
|
-
# uuid [](https://github.com/uuidjs/uuid/actions?query=workflow%3ACI) [](https://github.com/uuidjs/uuid/actions?query=workflow%3ABrowser)
|
|
6
6
|
|
|
7
7
|
For the creation of [RFC4122](http://www.ietf.org/rfc/rfc4122.txt) UUIDs
|
|
8
8
|
|
|
9
9
|
- **Complete** - Support for RFC4122 version 1, 3, 4, and 5 UUIDs
|
|
10
10
|
- **Cross-platform** - Support for ...
|
|
11
|
-
- CommonJS, [ECMAScript Modules](#ecmascript-modules) and [CDN builds
|
|
11
|
+
- CommonJS, [ECMAScript Modules](#ecmascript-modules) and [CDN builds](#cdn-builds)
|
|
12
12
|
- Node 8, 10, 12, 14
|
|
13
13
|
- Chrome, Safari, Firefox, Edge, IE 11 browsers
|
|
14
14
|
- Webpack and rollup.js module bundlers
|
|
15
|
-
- [React Native](#react-native)
|
|
15
|
+
- [React Native / Expo](#react-native-expo)
|
|
16
16
|
- **Secure** - Cryptographically-strong random values
|
|
17
17
|
- **Small** - Zero-dependency, small footprint, plays nice with "tree shaking" packagers
|
|
18
18
|
- **CLI** - Includes the [`uuid` command line](#command-line) utility
|
|
19
19
|
|
|
20
|
-
**Upgrading from uuid
|
|
20
|
+
**Upgrading from `uuid@3.x`?** Your code is probably okay, but check out [Upgrading From `uuid@3.x`](#upgrading-from-uuid3x) for details.
|
|
21
21
|
|
|
22
22
|
## Quickstart
|
|
23
23
|
|
|
24
|
+
To create a random UUID...
|
|
25
|
+
|
|
26
|
+
**1. Install**
|
|
27
|
+
|
|
24
28
|
```shell
|
|
25
29
|
npm install uuid
|
|
26
30
|
```
|
|
27
31
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
- Version 4 (random) - Created from cryptographically-strong random values
|
|
31
|
-
- Version 1 (timestamp) - Created from the system clock (plus random values)
|
|
32
|
-
- Version 5 (namespace, SHA-1) - Created from user-supplied name and namespace strings
|
|
33
|
-
- Version 3 (namespace, MD5) - Like version 5, above, but with a poorer hash algorithm
|
|
34
|
-
|
|
35
|
-
**Unsure which one to use?** Use version 4 (random) unless you have a specific need for one of the other versions. See also [this FAQ](https://github.com/tc39/proposal-uuid#faq).
|
|
36
|
-
|
|
37
|
-
### Create Version 4 (Random) UUIDs
|
|
38
|
-
|
|
39
|
-
ECMAScript Module syntax:
|
|
32
|
+
**2. Create a UUID** (ES6 module syntax)
|
|
40
33
|
|
|
41
34
|
```javascript
|
|
42
35
|
import { v4 as uuidv4 } from 'uuid';
|
|
43
36
|
uuidv4(); // ⇨ '9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d'
|
|
44
37
|
```
|
|
45
38
|
|
|
46
|
-
CommonJS syntax:
|
|
39
|
+
... or using CommonJS syntax:
|
|
47
40
|
|
|
48
41
|
```javascript
|
|
49
42
|
const { v4: uuidv4 } = require('uuid');
|
|
50
43
|
uuidv4(); // ⇨ '1b9d6bcd-bbfd-4b2d-9b5d-ab8dfbbd4bed'
|
|
51
44
|
```
|
|
52
45
|
|
|
53
|
-
|
|
46
|
+
For timestamp UUIDs, namespace UUIDs, and other options read on ...
|
|
47
|
+
|
|
48
|
+
## API Summary
|
|
49
|
+
|
|
50
|
+
| | | |
|
|
51
|
+
| --- | --- | --- |
|
|
52
|
+
| [`uuid.NIL`](#uuidnil) | The nil UUID string (all zeros) | New in `uuid@8.3` |
|
|
53
|
+
| [`uuid.parse()`](#uuidparsestr) | Convert UUID string to array of bytes | New in `uuid@8.3` |
|
|
54
|
+
| [`uuid.stringify()`](#uuidstringifyarr-offset) | Convert array of bytes to UUID string | New in `uuid@8.3` |
|
|
55
|
+
| [`uuid.v1()`](#uuidv1options-buffer-offset) | Create a version 1 (timestamp) UUID | |
|
|
56
|
+
| [`uuid.v3()`](#uuidv3name-namespace-buffer-offset) | Create a version 3 (namespace w/ MD5) UUID | |
|
|
57
|
+
| [`uuid.v4()`](#uuidv4options-buffer-offset) | Create a version 4 (random) UUID | |
|
|
58
|
+
| [`uuid.v5()`](#uuidv5name-namespace-buffer-offset) | Create a version 5 (namespace w/ SHA-1) UUID | |
|
|
59
|
+
| [`uuid.validate()`](#uuidvalidatestr) | Test a string to see if it is a valid UUID | New in `uuid@8.3` |
|
|
60
|
+
| [`uuid.version()`](#uuidversionstr) | Detect RFC version of a UUID | New in `uuid@8.3` |
|
|
61
|
+
|
|
62
|
+
## API
|
|
63
|
+
|
|
64
|
+
### uuid.NIL
|
|
65
|
+
|
|
66
|
+
The nil UUID string (all zeros).
|
|
67
|
+
|
|
68
|
+
Example:
|
|
54
69
|
|
|
55
70
|
```javascript
|
|
56
|
-
import {
|
|
57
|
-
|
|
71
|
+
import { NIL as NIL_UUID } from 'uuid';
|
|
72
|
+
|
|
73
|
+
NIL_UUID; // ⇨ '00000000-0000-0000-0000-000000000000'
|
|
58
74
|
```
|
|
59
75
|
|
|
60
|
-
###
|
|
76
|
+
### uuid.parse(str)
|
|
77
|
+
|
|
78
|
+
Convert UUID string to array of bytes
|
|
79
|
+
|
|
80
|
+
| | |
|
|
81
|
+
| --------- | ---------------------------------------- |
|
|
82
|
+
| `str` | A valid UUID `String` |
|
|
83
|
+
| _returns_ | `Uint8Array[16]` |
|
|
84
|
+
| _throws_ | `TypeError` if `str` is not a valid UUID |
|
|
61
85
|
|
|
62
|
-
|
|
86
|
+
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.
|
|
63
87
|
|
|
64
|
-
|
|
88
|
+
Example:
|
|
65
89
|
|
|
66
90
|
```javascript
|
|
67
|
-
import {
|
|
68
|
-
import { v3 as uuidv3 } from 'uuid'; // For version 3
|
|
91
|
+
import { parse as uuidParse } from 'uuid';
|
|
69
92
|
|
|
70
|
-
//
|
|
71
|
-
|
|
72
|
-
uuidv3('hello.example.com', uuidv3.DNS); // ⇨ '9125a8dc-52ee-365b-a5aa-81b0b3681cf6'
|
|
93
|
+
// Parse a UUID
|
|
94
|
+
const bytes = uuidParse('6ec0bd7f-11c0-43da-975e-2a8ad9ebae0b');
|
|
73
95
|
|
|
74
|
-
//
|
|
75
|
-
|
|
76
|
-
|
|
96
|
+
// Convert to hex strings to show byte order (for documentation purposes)
|
|
97
|
+
[...bytes].map((v) => v.toString(16).padStart(2, '0')); // ⇨
|
|
98
|
+
// [
|
|
99
|
+
// '6e', 'c0', 'bd', '7f',
|
|
100
|
+
// '11', 'c0', '43', 'da',
|
|
101
|
+
// '97', '5e', '2a', '8a',
|
|
102
|
+
// 'd9', 'eb', 'ae', '0b'
|
|
103
|
+
// ]
|
|
104
|
+
```
|
|
77
105
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
106
|
+
### uuid.stringify(arr[, offset])
|
|
107
|
+
|
|
108
|
+
Convert array of bytes to UUID string
|
|
109
|
+
|
|
110
|
+
| | |
|
|
111
|
+
| -------------- | ---------------------------------------------------------------------------- |
|
|
112
|
+
| `arr` | `Array`-like collection of 16 values (starting from `offset`) between 0-255. |
|
|
113
|
+
| [`offset` = 0] | `Number` Starting index in the Array |
|
|
114
|
+
| _returns_ | `String` |
|
|
115
|
+
| _throws_ | `TypeError` if a valid UUID string cannot be generated |
|
|
116
|
+
|
|
117
|
+
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.
|
|
118
|
+
|
|
119
|
+
Example:
|
|
120
|
+
|
|
121
|
+
```javascript
|
|
122
|
+
import { stringify as uuidStringify } from 'uuid';
|
|
123
|
+
|
|
124
|
+
const uuidBytes = [
|
|
125
|
+
0x6e,
|
|
126
|
+
0xc0,
|
|
127
|
+
0xbd,
|
|
128
|
+
0x7f,
|
|
129
|
+
0x11,
|
|
130
|
+
0xc0,
|
|
131
|
+
0x43,
|
|
132
|
+
0xda,
|
|
133
|
+
0x97,
|
|
134
|
+
0x5e,
|
|
135
|
+
0x2a,
|
|
136
|
+
0x8a,
|
|
137
|
+
0xd9,
|
|
138
|
+
0xeb,
|
|
139
|
+
0xae,
|
|
140
|
+
0x0b,
|
|
141
|
+
];
|
|
142
|
+
|
|
143
|
+
uuidStringify(uuidBytes); // ⇨ '6ec0bd7f-11c0-43da-975e-2a8ad9ebae0b'
|
|
83
144
|
```
|
|
84
145
|
|
|
85
|
-
|
|
146
|
+
### uuid.v1([options[, buffer[, offset]]])
|
|
147
|
+
|
|
148
|
+
Create an RFC version 1 (timestamp) UUID
|
|
86
149
|
|
|
87
|
-
|
|
150
|
+
| | |
|
|
151
|
+
| --- | --- |
|
|
152
|
+
| [`options`] | `Object` with one or more of the following properties: |
|
|
153
|
+
| [`options.node` ] | RFC "node" field as an `Array[6]` of byte values (per 4.1.6) |
|
|
154
|
+
| [`options.clockseq`] | RFC "clock sequence" as a `Number` between 0 - 0x3fff |
|
|
155
|
+
| [`options.msecs`] | RFC "timestamp" field (`Number` of milliseconds, unix epoch) |
|
|
156
|
+
| [`options.nsecs`] | RFC "timestamp" field (`Number` of nanseconds to add to `msecs`, should be 0-10,000) |
|
|
157
|
+
| [`options.random`] | `Array` of 16 random bytes (0-255) |
|
|
158
|
+
| [`options.rng`] | Alternative to `options.random`, a `Function` that returns an `Array` of 16 random bytes (0-255) |
|
|
159
|
+
| [`buffer`] | `Array \| Buffer` If specified, uuid will be written here in byte-form, starting at `offset` |
|
|
160
|
+
| [`offset` = 0] | `Number` Index to start writing UUID bytes in `buffer` |
|
|
161
|
+
| _returns_ | UUID `String` if no `buffer` is specified, otherwise returns `buffer` |
|
|
162
|
+
| _throws_ | `Error` if more than 10M UUIDs/sec are requested |
|
|
163
|
+
|
|
164
|
+
Note: The default [node id](https://tools.ietf.org/html/rfc4122#section-4.1.6) (the last 12 digits in the UUID) is generated once, randomly, on process startup, and then remains unchanged for the duration of the process.
|
|
165
|
+
|
|
166
|
+
Note: `options.random` and `options.rng` are only meaningful on the very first call to `v1()`, where they may be passed to initialize the internal `node` and `clockseq` fields.
|
|
167
|
+
|
|
168
|
+
Example:
|
|
88
169
|
|
|
89
170
|
```javascript
|
|
90
|
-
import {
|
|
171
|
+
import { v1 as uuidv1 } from 'uuid';
|
|
91
172
|
|
|
92
|
-
//
|
|
93
|
-
uuidv4();
|
|
94
|
-
uuidv4(options);
|
|
95
|
-
uuidv4(options, buffer, offset);
|
|
173
|
+
uuidv1(); // ⇨ '2c5ea4c0-4067-11e9-8bad-9b1deb4d3b7d'
|
|
96
174
|
```
|
|
97
175
|
|
|
98
|
-
|
|
176
|
+
Example using `options`:
|
|
99
177
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
178
|
+
```javascript
|
|
179
|
+
import { v1 as uuidv1 } from 'uuid';
|
|
180
|
+
|
|
181
|
+
const v1options = {
|
|
182
|
+
node: [0x01, 0x23, 0x45, 0x67, 0x89, 0xab],
|
|
183
|
+
clockseq: 0x1234,
|
|
184
|
+
msecs: new Date('2011-11-01').getTime(),
|
|
185
|
+
nsecs: 5678,
|
|
186
|
+
};
|
|
187
|
+
uuidv1(v1options); // ⇨ '710b962e-041c-11e1-9234-0123456789ab'
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### uuid.v3(name, namespace[, buffer[, offset]])
|
|
191
|
+
|
|
192
|
+
Create an RFC version 3 (namespace w/ MD5) UUID
|
|
193
|
+
|
|
194
|
+
API is identical to `v5()`, but uses "v3" instead.
|
|
195
|
+
|
|
196
|
+
⚠️ Note: Per the RFC, "_If backward compatibility is not an issue, SHA-1 [Version 5] is preferred_."
|
|
105
197
|
|
|
106
|
-
|
|
198
|
+
### uuid.v4([options[, buffer[, offset]]])
|
|
107
199
|
|
|
108
|
-
|
|
200
|
+
Create an RFC version 4 (random) UUID
|
|
201
|
+
|
|
202
|
+
| | |
|
|
203
|
+
| --- | --- |
|
|
204
|
+
| [`options`] | `Object` with one or more of the following properties: |
|
|
205
|
+
| [`options.random`] | `Array` of 16 random bytes (0-255) |
|
|
206
|
+
| [`options.rng`] | Alternative to `options.random`, a `Function` that returns an `Array` of 16 random bytes (0-255) |
|
|
207
|
+
| [`buffer`] | `Array \| Buffer` If specified, uuid will be written here in byte-form, starting at `offset` |
|
|
208
|
+
| [`offset` = 0] | `Number` Index to start writing UUID bytes in `buffer` |
|
|
209
|
+
| _returns_ | UUID `String` if no `buffer` is specified, otherwise returns `buffer` |
|
|
210
|
+
|
|
211
|
+
Example:
|
|
109
212
|
|
|
110
213
|
```javascript
|
|
214
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
215
|
+
|
|
216
|
+
uuidv4(); // ⇨ '1b9d6bcd-bbfd-4b2d-9b5d-ab8dfbbd4bed'
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
Example using predefined `random` values:
|
|
220
|
+
|
|
221
|
+
```javascript
|
|
222
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
223
|
+
|
|
111
224
|
const v4options = {
|
|
112
225
|
random: [
|
|
113
226
|
0x10,
|
|
@@ -131,137 +244,75 @@ const v4options = {
|
|
|
131
244
|
uuidv4(v4options); // ⇨ '109156be-c4fb-41ea-b1b4-efe1671c5836'
|
|
132
245
|
```
|
|
133
246
|
|
|
134
|
-
|
|
247
|
+
### uuid.v5(name, namespace[, buffer[, offset]])
|
|
135
248
|
|
|
136
|
-
|
|
137
|
-
const buffer = new Array();
|
|
138
|
-
uuidv4(null, buffer, 0); // ⇨
|
|
139
|
-
// [
|
|
140
|
-
// 27, 157, 107, 205, 187,
|
|
141
|
-
// 253, 75, 45, 155, 93,
|
|
142
|
-
// 171, 141, 251, 189, 75,
|
|
143
|
-
// 237
|
|
144
|
-
// ]
|
|
145
|
-
uuidv4(null, buffer, 16); // ⇨
|
|
146
|
-
// [
|
|
147
|
-
// 27, 157, 107, 205, 187, 253, 75, 45,
|
|
148
|
-
// 155, 93, 171, 141, 251, 189, 75, 237,
|
|
149
|
-
// 155, 29, 235, 77, 59, 125, 75, 173,
|
|
150
|
-
// 155, 221, 43, 13, 123, 61, 203, 109
|
|
151
|
-
// ]
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
### Version 1 (Timestamp)
|
|
155
|
-
|
|
156
|
-
```javascript
|
|
157
|
-
import { v1 as uuidv1 } from 'uuid';
|
|
249
|
+
Createa an RFC version 5 (namespace w/ SHA-1) UUID
|
|
158
250
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
251
|
+
| | |
|
|
252
|
+
| --- | --- |
|
|
253
|
+
| `name` | `String \| Array` |
|
|
254
|
+
| `namespace` | `String \| Array[16]` Namespace UUID |
|
|
255
|
+
| [`buffer`] | `Array \| Buffer` If specified, uuid will be written here in byte-form, starting at `offset` |
|
|
256
|
+
| [`offset` = 0] | `Number` Index to start writing UUID bytes in `buffer` |
|
|
257
|
+
| _returns_ | UUID `String` if no `buffer` is specified, otherwise returns `buffer` |
|
|
166
258
|
|
|
167
|
-
|
|
168
|
-
- `node` - (Array) Node id as Array of 6 bytes (per 4.1.6). Default: Randomly generated ID. See note 1.
|
|
169
|
-
- `clockseq` - (Number between 0 - 0x3fff) RFC clock sequence. Default: An internally maintained clockseq is used.
|
|
170
|
-
- `msecs` - (Number) Time in milliseconds since unix Epoch. Default: The current time is used.
|
|
171
|
-
- `nsecs` - (Number between 0-9999) additional time, in 100-nanosecond units. Ignored if `msecs` is unspecified. Default: internal uuid counter is used, as per 4.2.1.2.
|
|
172
|
-
- `random` - (Number[16]) Array of 16 numbers (0-255) to use for initialization of `node` and `clockseq` as described above. Takes precedence over `options.rng`.
|
|
173
|
-
- `rng` - (Function) Random # generator function that returns an Array[16] of byte values (0-255). Alternative to `options.random`.
|
|
174
|
-
- `buffer` - (Array | Buffer) Array or buffer where UUID bytes are to be written.
|
|
175
|
-
- `offset` - (Number) Starting index in `buffer` at which to begin writing.
|
|
259
|
+
Note: The RFC `DNS` and `URL` namespaces are available as `v5.DNS` and `v5.URL`.
|
|
176
260
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
Note: The default [node id](https://tools.ietf.org/html/rfc4122#section-4.1.6) (the last 12 digits in the UUID) is generated once, randomly, on process startup, and then remains unchanged for the duration of the process.
|
|
180
|
-
|
|
181
|
-
Example: Generate string UUID with fully-specified options
|
|
261
|
+
Example with custom namespace:
|
|
182
262
|
|
|
183
263
|
```javascript
|
|
184
|
-
|
|
185
|
-
node: [0x01, 0x23, 0x45, 0x67, 0x89, 0xab],
|
|
186
|
-
clockseq: 0x1234,
|
|
187
|
-
msecs: new Date('2011-11-01').getTime(),
|
|
188
|
-
nsecs: 5678,
|
|
189
|
-
};
|
|
190
|
-
uuidv1(v1options); // ⇨ '710b962e-041c-11e1-9234-0123456789ab'
|
|
191
|
-
```
|
|
264
|
+
import { v5 as uuidv5 } from 'uuid';
|
|
192
265
|
|
|
193
|
-
|
|
266
|
+
// Define a custom namespace. Readers, create your own using something like
|
|
267
|
+
// https://www.uuidgenerator.net/
|
|
268
|
+
const MY_NAMESPACE = '1b671a64-40d5-491e-99b0-da01ff1f3341';
|
|
194
269
|
|
|
195
|
-
|
|
196
|
-
// Generate two ids in an array
|
|
197
|
-
const arr = new Array();
|
|
198
|
-
uuidv1(null, arr, 0); // ⇨
|
|
199
|
-
// [
|
|
200
|
-
// 44, 94, 164, 192, 64, 103,
|
|
201
|
-
// 17, 233, 146, 52, 155, 29,
|
|
202
|
-
// 235, 77, 59, 125
|
|
203
|
-
// ]
|
|
204
|
-
uuidv1(null, arr, 16); // ⇨
|
|
205
|
-
// [
|
|
206
|
-
// 44, 94, 164, 192, 64, 103, 17, 233,
|
|
207
|
-
// 146, 52, 155, 29, 235, 77, 59, 125,
|
|
208
|
-
// 44, 94, 164, 193, 64, 103, 17, 233,
|
|
209
|
-
// 146, 52, 155, 29, 235, 77, 59, 125
|
|
210
|
-
// ]
|
|
270
|
+
uuidv5('Hello, World!', MY_NAMESPACE); // ⇨ '630eb68f-e0fa-5ecc-887a-7c7a62614681'
|
|
211
271
|
```
|
|
212
272
|
|
|
213
|
-
|
|
273
|
+
Example with RFC `URL` namespace:
|
|
214
274
|
|
|
215
275
|
```javascript
|
|
216
276
|
import { v5 as uuidv5 } from 'uuid';
|
|
217
277
|
|
|
218
|
-
//
|
|
219
|
-
uuidv5(name, namespace);
|
|
220
|
-
uuidv5(name, namespace, buffer);
|
|
221
|
-
uuidv5(name, namespace, buffer, offset);
|
|
278
|
+
uuidv5('https://www.w3.org/', uuidv5.URL); // ⇨ 'c106a26a-21bb-5538-8bf2-57095d1976c1'
|
|
222
279
|
```
|
|
223
280
|
|
|
224
|
-
|
|
281
|
+
### uuid.validate(str)
|
|
225
282
|
|
|
226
|
-
|
|
227
|
-
- `namespace` - (String | Array[]) "namespace" UUID either as a String or Array[16] of byte values
|
|
228
|
-
- `buffer` - (Array | Buffer) Array or buffer where UUID bytes are to be written.
|
|
229
|
-
- `offset` - (Number) Starting index in `buffer` at which to begin writing. Default = 0
|
|
283
|
+
Test a string to see if it is a valid UUID
|
|
230
284
|
|
|
231
|
-
|
|
285
|
+
| | |
|
|
286
|
+
| --------- | --------------------------------------------------- |
|
|
287
|
+
| `str` | `String` to validate |
|
|
288
|
+
| _returns_ | `true` if string is a valid UUID, `false` otherwise |
|
|
232
289
|
|
|
233
290
|
Example:
|
|
234
291
|
|
|
235
292
|
```javascript
|
|
236
|
-
|
|
237
|
-
```
|
|
293
|
+
import { validate as uuidValidate } from 'uuid';
|
|
238
294
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
⚠️ Note: Per the RFC, "_If backward compatibility is not an issue, SHA-1 [Version 5] is preferred_."
|
|
242
|
-
|
|
243
|
-
```javascript
|
|
244
|
-
import { v3 as uuidv3 } from 'uuid';
|
|
245
|
-
|
|
246
|
-
// Incantations
|
|
247
|
-
uuidv3(name, namespace);
|
|
248
|
-
uuidv3(name, namespace, buffer);
|
|
249
|
-
uuidv3(name, namespace, buffer, offset);
|
|
295
|
+
uuidValidate('not a UUID'); // ⇨ false
|
|
296
|
+
uuidValidate('6ec0bd7f-11c0-43da-975e-2a8ad9ebae0b'); // ⇨ true
|
|
250
297
|
```
|
|
251
298
|
|
|
252
|
-
|
|
299
|
+
### uuid.version(str)
|
|
253
300
|
|
|
254
|
-
|
|
255
|
-
- `namespace` - (String | Array[]) "namespace" UUID either as a String or Array[16] of byte values
|
|
256
|
-
- `buffer` - (Array | Buffer) Array or buffer where UUID bytes are to be written.
|
|
257
|
-
- `offset` - (Number) Starting index in `buffer` at which to begin writing. Default = 0
|
|
301
|
+
Detect RFC version of a UUID
|
|
258
302
|
|
|
259
|
-
|
|
303
|
+
| | |
|
|
304
|
+
| --------- | ---------------------------------------- |
|
|
305
|
+
| `str` | A valid UUID `String` |
|
|
306
|
+
| _returns_ | `Number` The RFC version of the UUID |
|
|
307
|
+
| _throws_ | `TypeError` if `str` is not a valid UUID |
|
|
260
308
|
|
|
261
309
|
Example:
|
|
262
310
|
|
|
263
311
|
```javascript
|
|
264
|
-
|
|
312
|
+
import { version as uuidVersion } from 'uuid';
|
|
313
|
+
|
|
314
|
+
uuidVersion('45637ec4-c85f-11ea-87d0-0242ac130003'); // ⇨ 1
|
|
315
|
+
uuidVersion('6ec0bd7f-11c0-43da-975e-2a8ad9ebae0b'); // ⇨ 4
|
|
265
316
|
```
|
|
266
317
|
|
|
267
318
|
## Command Line
|
|
@@ -305,9 +356,22 @@ To run the examples you must first create a dist build of this library in the mo
|
|
|
305
356
|
npm run build
|
|
306
357
|
```
|
|
307
358
|
|
|
308
|
-
## CDN Builds
|
|
359
|
+
## CDN Builds
|
|
360
|
+
|
|
361
|
+
### ECMAScript Modules
|
|
362
|
+
|
|
363
|
+
To load this module directly into modern browsers that [support loading ECMAScript Modules](https://caniuse.com/#feat=es6-module) you can make use of [jspm](https://jspm.org/):
|
|
364
|
+
|
|
365
|
+
```html
|
|
366
|
+
<script type="module">
|
|
367
|
+
import { v4 as uuidv4 } from 'https://jspm.dev/uuid';
|
|
368
|
+
console.log(uuidv4()); // ⇨ '1b9d6bcd-bbfd-4b2d-9b5d-ab8dfbbd4bed'
|
|
369
|
+
</script>
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
### UMD
|
|
309
373
|
|
|
310
|
-
|
|
374
|
+
To load this module directly into older browsers you can use the [UMD (Universal Module Definition)](https://github.com/umdjs/umd) builds from any of the following CDNs:
|
|
311
375
|
|
|
312
376
|
**Using [UNPKG](https://unpkg.com/uuid@latest/dist/umd/)**:
|
|
313
377
|
|
|
@@ -327,7 +391,7 @@ This module may be loaded directly into a browser from any of the following CDNs
|
|
|
327
391
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/uuid/8.1.0/uuidv4.min.js"></script>
|
|
328
392
|
```
|
|
329
393
|
|
|
330
|
-
These CDNs all provide the same [`uuidv4()`](#
|
|
394
|
+
These CDNs all provide the same [`uuidv4()`](#uuidv4options-buffer-offset) method:
|
|
331
395
|
|
|
332
396
|
```html
|
|
333
397
|
<script>
|
|
@@ -335,31 +399,33 @@ These CDNs all provide the same [`uuidv4()`](#version-4-random) method:
|
|
|
335
399
|
</script>
|
|
336
400
|
```
|
|
337
401
|
|
|
338
|
-
Methods for the other algorithms ([`uuidv1()`](#
|
|
402
|
+
Methods for the other algorithms ([`uuidv1()`](#uuidv1options-buffer-offset), [`uuidv3()`](#uuidv3name-namespace-buffer-offset) and [`uuidv5()`](#uuidv5name-namespace-buffer-offset)) are available from the files `uuidv1.min.js`, `uuidv3.min.js` and `uuidv5.min.js` respectively.
|
|
339
403
|
|
|
340
404
|
## "getRandomValues() not supported"
|
|
341
405
|
|
|
342
406
|
This error occurs in environments where the standard [`crypto.getRandomValues()`](https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues) API is not supported. This issue can be resolved by adding an appropriate polyfill:
|
|
343
407
|
|
|
344
|
-
### React Native
|
|
408
|
+
### React Native / Expo
|
|
345
409
|
|
|
346
410
|
1. Install [`react-native-get-random-values`](https://github.com/LinusU/react-native-get-random-values#readme)
|
|
347
|
-
1. Import it
|
|
411
|
+
1. Import it _before_ `uuid`. Since `uuid` might also appear as a transitive dependency of some other imports it's safest to just import `react-native-get-random-values` as the very first thing in your entry point:
|
|
348
412
|
|
|
349
413
|
```javascript
|
|
350
414
|
import 'react-native-get-random-values';
|
|
351
415
|
import { v4 as uuidv4 } from 'uuid';
|
|
352
416
|
```
|
|
353
417
|
|
|
418
|
+
Note: If you are using Expo, you must be using at least `react-native-get-random-values@1.5.0` and `expo@39.0.0`.
|
|
419
|
+
|
|
354
420
|
### Web Workers / Service Workers (Edge <= 18)
|
|
355
421
|
|
|
356
422
|
[In Edge <= 18, Web Crypto is not supported in Web Workers or Service Workers](https://caniuse.com/#feat=cryptography) and we are not aware of a polyfill (let us know if you find one, please).
|
|
357
423
|
|
|
358
|
-
## Upgrading From uuid
|
|
424
|
+
## Upgrading From `uuid@7.x`
|
|
359
425
|
|
|
360
426
|
### Only Named Exports Supported When Using with Node.js ESM
|
|
361
427
|
|
|
362
|
-
uuid
|
|
428
|
+
`uuid@7.x` did not come with native ECMAScript Module (ESM) support for Node.js. Importing it in Node.js ESM consequently imported the CommonJS source with a default export. This library now comes with true Node.js ESM support and only provides named exports.
|
|
363
429
|
|
|
364
430
|
Instead of doing:
|
|
365
431
|
|
|
@@ -377,24 +443,24 @@ uuidv4();
|
|
|
377
443
|
|
|
378
444
|
### Deep Requires No Longer Supported
|
|
379
445
|
|
|
380
|
-
Deep requires like `require('uuid/v4')` [which have been deprecated in uuid
|
|
446
|
+
Deep requires like `require('uuid/v4')` [which have been deprecated in `uuid@7.x`](#deep-requires-now-deprecated) are no longer supported.
|
|
381
447
|
|
|
382
|
-
## Upgrading From uuid
|
|
448
|
+
## Upgrading From `uuid@3.x`
|
|
383
449
|
|
|
384
|
-
"_Wait... what happened to uuid
|
|
450
|
+
"_Wait... what happened to `uuid@4.x` - `uuid@6.x`?!?_"
|
|
385
451
|
|
|
386
|
-
In order to avoid confusion with RFC [version 4](#
|
|
452
|
+
In order to avoid confusion with RFC [version 4](#uuidv4options-buffer-offset) and [version 5](#uuidv5name-namespace-buffer-offset) UUIDs, and a possible [version 6](http://gh.peabody.io/uuidv6/), releases 4 thru 6 of this module have been skipped.
|
|
387
453
|
|
|
388
454
|
### Deep Requires Now Deprecated
|
|
389
455
|
|
|
390
|
-
uuid
|
|
456
|
+
`uuid@3.x` encouraged the use of deep requires to minimize the bundle size of browser builds:
|
|
391
457
|
|
|
392
458
|
```javascript
|
|
393
459
|
const uuidv4 = require('uuid/v4'); // <== NOW DEPRECATED!
|
|
394
460
|
uuidv4();
|
|
395
461
|
```
|
|
396
462
|
|
|
397
|
-
As of uuid
|
|
463
|
+
As of `uuid@7.x` this library now provides ECMAScript modules builds, which allow packagers like Webpack and Rollup to do "tree-shaking" to remove dead code. Instead, use the `import` syntax:
|
|
398
464
|
|
|
399
465
|
```javascript
|
|
400
466
|
import { v4 as uuidv4 } from 'uuid';
|
|
@@ -410,13 +476,13 @@ uuidv4();
|
|
|
410
476
|
|
|
411
477
|
### Default Export Removed
|
|
412
478
|
|
|
413
|
-
uuid
|
|
479
|
+
`uuid@3.x` was exporting the Version 4 UUID method as a default export:
|
|
414
480
|
|
|
415
481
|
```javascript
|
|
416
482
|
const uuid = require('uuid'); // <== REMOVED!
|
|
417
483
|
```
|
|
418
484
|
|
|
419
|
-
This usage pattern was already discouraged in uuid
|
|
485
|
+
This usage pattern was already discouraged in `uuid@3.x` and has been removed in `uuid@7.x`.
|
|
420
486
|
|
|
421
487
|
----
|
|
422
488
|
Markdown generated from [README_js.md](README_js.md) by [](https://github.com/broofa/runmd)
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
export { default as v1 } from './v1.js';
|
|
2
2
|
export { default as v3 } from './v3.js';
|
|
3
3
|
export { default as v4 } from './v4.js';
|
|
4
|
-
export { default as v5 } from './v5.js';
|
|
4
|
+
export { default as v5 } from './v5.js';
|
|
5
|
+
export { default as NIL } from './nil.js';
|
|
6
|
+
export { default as version } from './version.js';
|
|
7
|
+
export { default as validate } from './validate.js';
|
|
8
|
+
export { default as stringify } from './stringify.js';
|
|
9
|
+
export { default as parse } from './parse.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default '00000000-0000-0000-0000-000000000000';
|