Skip to content

Commit c4ed13e

Browse files
authored
feat: support v6 uuids (#754)
1 parent 8c3ed07 commit c4ed13e

37 files changed

+9850
-15438
lines changed

.gitignore

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
node_modules/
2-
dist/
3-
# Browserstack
1+
*.tgz
42
browserstack.err
3+
dist/
54
local.log
6-
*.tgz
5+
node_modules/
6+
vscode/

.local/uuid/v1tov6.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../v1tov6.js

.local/uuid/v6.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../v6.js

.local/uuid/v6tov1.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../v6tov1.js

.prettierignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22
dist/
33
node_modules/
44
README.md
5-
*.sh
5+
*.sh
6+
.gitignore
7+
.prettierignore

README.md

+58-7
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
-- This file is auto-generated from README_js.md. Changes should be made there.
33
-->
44

5+
56
# uuid [![CI](https://github.com/uuidjs/uuid/workflows/CI/badge.svg)](https://github.com/uuidjs/uuid/actions?query=workflow%3ACI) [![Browser](https://github.com/uuidjs/uuid/workflows/Browser/badge.svg)](https://github.com/uuidjs/uuid/actions?query=workflow%3ABrowser)
67

78
For the creation of [RFC9562](https://www.rfc-editor.org/rfc/rfc9562.html) (formally [RFC4122](https://www.rfc-editor.org/rfc/rfc4122.html)) UUIDs
89

9-
- **Complete** - Support for all RFC9562 UUID versions
10+
- **Complete** - Support for all RFC9562 (nee RFC4122) UUID versions
1011
- **Cross-platform** - Support for ...
1112
- CommonJS, [ECMAScript Modules](#ecmascript-modules) and [CDN builds](#cdn-builds)
1213
- NodeJS 16+ ([LTS releases](https://github.com/nodejs/Release))
@@ -60,10 +61,13 @@ For timestamp UUIDs, namespace UUIDs, and other options read on ...
6061
| [`uuid.parse()`](#uuidparsestr) | Convert UUID string to array of bytes | New in `[email protected]` |
6162
| [`uuid.stringify()`](#uuidstringifyarr-offset) | Convert array of bytes to UUID string | New in `[email protected]` |
6263
| [`uuid.v1()`](#uuidv1options-buffer-offset) | Create a version 1 (timestamp) UUID | |
64+
| [`uuid.v1ToV6()`](#uuidv1tov6uuid) | Create a version 6 UUID from a version 1 UUID | New in `uuid@10` |
6365
| [`uuid.v3()`](#uuidv3name-namespace-buffer-offset) | Create a version 3 (namespace w/ MD5) UUID | |
6466
| [`uuid.v4()`](#uuidv4options-buffer-offset) | Create a version 4 (random) UUID | |
6567
| [`uuid.v5()`](#uuidv5name-namespace-buffer-offset) | Create a version 5 (namespace w/ SHA-1) UUID | |
66-
| [`uuid.v7()`](#uuidv7options-buffer-offset) | Create a version 7 (Unix Epoch time-based) UUID | `experimental support` |
68+
| [`uuid.v6()`](#uuidv6options-buffer-offset) | Create a version 6 (timestamp, reordered) UUID | New in `uuid@10` |
69+
| [`uuid.v6ToV1()`](#uuidv6tov1uuid) | Create a version 1 UUID from a version 6 UUID | New in `uuid@10` |
70+
| [`uuid.v7()`](#uuidv7options-buffer-offset) | Create a version 7 (Unix Epoch time-based) UUID | New in `uuid@10` |
6771
| [`uuid.validate()`](#uuidvalidatestr) | Test a string to see if it is a valid UUID | New in `[email protected]` |
6872
| [`uuid.version()`](#uuidversionstr) | Detect RFC version of a UUID | New in `[email protected]` |
6973

@@ -191,13 +195,23 @@ Example using `options`:
191195
```javascript
192196
import { v1 as uuidv1 } from 'uuid';
193197

194-
const v1options = {
198+
const options = {
195199
node: [0x01, 0x23, 0x45, 0x67, 0x89, 0xab],
196200
clockseq: 0x1234,
197201
msecs: new Date('2011-11-01').getTime(),
198202
nsecs: 5678,
199203
};
200-
uuidv1(v1options); // ⇨ '710b962e-041c-11e1-9234-0123456789ab'
204+
uuidv1(options); // ⇨ '710b962e-041c-11e1-9234-0123456789ab'
205+
```
206+
207+
### uuid.v1ToV6(uuid)
208+
209+
Convert a UUID from version 1 to version 6
210+
211+
```javascript
212+
import { v1ToV6 } from 'uuid';
213+
214+
v1ToV6('92f62d9e-22c4-11ef-97e9-325096b39f47'); // ⇨ '1ef22c49-2f62-6d9e-97e9-325096b39f47'
201215
```
202216

203217
### uuid.v3(name, namespace[, buffer[, offset]])
@@ -280,6 +294,42 @@ import { v5 as uuidv5 } from 'uuid';
280294
uuidv5('https://www.w3.org/', uuidv5.URL); // ⇨ 'c106a26a-21bb-5538-8bf2-57095d1976c1'
281295
```
282296

297+
### uuid.v6([options[, buffer[, offset]]])
298+
299+
Create an RFC version 6 (timestamp, reordered) UUID
300+
301+
This method takes the same arguments as uuid.v1().
302+
303+
```javascript
304+
import { v6 as uuidv6 } from 'uuid';
305+
306+
uuidv6(); // ⇨ '1e940672-c5ea-64c0-8bad-9b1deb4d3b7d'
307+
```
308+
309+
Example using `options`:
310+
311+
```javascript
312+
import { v6 as uuidv6 } from 'uuid';
313+
314+
const options = {
315+
node: [0x01, 0x23, 0x45, 0x67, 0x89, 0xab],
316+
clockseq: 0x1234,
317+
msecs: new Date('2011-11-01').getTime(),
318+
nsecs: 5678,
319+
};
320+
uuidv6(options); // ⇨ '1e1041c7-10b9-662e-9234-0123456789ab'
321+
```
322+
323+
### uuid.v6ToV1(uuid)
324+
325+
Convert a UUID from version 6 to version 1
326+
327+
```javascript
328+
import { v6ToV1 } from 'uuid';
329+
330+
v6ToV1('1ef22c49-2f62-6d9e-97e9-325096b39f47'); // ⇨ '92f62d9e-22c4-11ef-97e9-325096b39f47'
331+
```
332+
283333
### uuid.v7([options[, buffer[, offset]]])
284334

285335
Create an RFC version 7 (random) UUID
@@ -300,7 +350,7 @@ Example:
300350
```javascript
301351
import { v7 as uuidv7 } from 'uuid';
302352

303-
uuidv7(); // ⇨ '01695553-c90c-7aad-9bdd-330d7b3dcb6d'
353+
uuidv7(); // ⇨ '01695553-c90c-722d-9b5d-b38dfbbd4bed'
304354
```
305355

306356
### uuid.validate(str)
@@ -520,5 +570,6 @@ const uuid = require('uuid'); // <== REMOVED!
520570

521571
This usage pattern was already discouraged in `uuid@3` and has been removed in `uuid@7`.
522572

523-
----
524-
Markdown generated from [README_js.md](README_js.md) by [![RunMD Logo](https://i.imgur.com/h0FVyzU.png)](https://github.com/broofa/runmd)
573+
---
574+
575+
Markdown generated from [README_js.md](README_js.md) by <a href="https://github.com/broofa/runmd"><image height="12px" src="https://camo.githubusercontent.com/5c7c603cd1e6a43370b0a5063d457e0dabb74cf317adc7baba183acb686ee8d0/687474703a2f2f692e696d6775722e636f6d2f634a4b6f3662552e706e67" /></a>

README_js.md

+53-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ require('crypto').randomUUID = undefined;
2121

2222
For the creation of [RFC9562](https://www.rfc-editor.org/rfc/rfc9562.html) (formally [RFC4122](https://www.rfc-editor.org/rfc/rfc4122.html)) UUIDs
2323

24-
- **Complete** - Support for RFC9562 version 1, 3, 4, 5, and 7 UUIDs
24+
- **Complete** - Support for all RFC9562 (nee RFC4122) UUID versions
2525
- **Cross-platform** - Support for ...
2626
- CommonJS, [ECMAScript Modules](#ecmascript-modules) and [CDN builds](#cdn-builds)
2727
- NodeJS 16+ ([LTS releases](https://github.com/nodejs/Release))
@@ -75,10 +75,13 @@ For timestamp UUIDs, namespace UUIDs, and other options read on ...
7575
| [`uuid.parse()`](#uuidparsestr) | Convert UUID string to array of bytes | New in `[email protected]` |
7676
| [`uuid.stringify()`](#uuidstringifyarr-offset) | Convert array of bytes to UUID string | New in `[email protected]` |
7777
| [`uuid.v1()`](#uuidv1options-buffer-offset) | Create a version 1 (timestamp) UUID | |
78+
| [`uuid.v1ToV6()`](#uuidv1tov6uuid) | Create a version 6 UUID from a version 1 UUID | New in `uuid@10` |
7879
| [`uuid.v3()`](#uuidv3name-namespace-buffer-offset) | Create a version 3 (namespace w/ MD5) UUID | |
7980
| [`uuid.v4()`](#uuidv4options-buffer-offset) | Create a version 4 (random) UUID | |
8081
| [`uuid.v5()`](#uuidv5name-namespace-buffer-offset) | Create a version 5 (namespace w/ SHA-1) UUID | |
81-
| [`uuid.v7()`](#uuidv7options-buffer-offset) | Create a version 7 (Unix Epoch time-based) UUID | `experimental support` |
82+
| [`uuid.v6()`](#uuidv6options-buffer-offset) | Create a version 6 (timestamp, reordered) UUID | New in `uuid@10` |
83+
| [`uuid.v6ToV1()`](#uuidv6tov1uuid) | Create a version 1 UUID from a version 6 UUID | New in `uuid@10` |
84+
| [`uuid.v7()`](#uuidv7options-buffer-offset) | Create a version 7 (Unix Epoch time-based) UUID | New in `uuid@10` |
8285
| [`uuid.validate()`](#uuidvalidatestr) | Test a string to see if it is a valid UUID | New in `[email protected]` |
8386
| [`uuid.version()`](#uuidversionstr) | Detect RFC version of a UUID | New in `[email protected]` |
8487

@@ -200,13 +203,23 @@ Example using `options`:
200203
```javascript --run
201204
import { v1 as uuidv1 } from 'uuid';
202205

203-
const v1options = {
206+
const options = {
204207
node: [0x01, 0x23, 0x45, 0x67, 0x89, 0xab],
205208
clockseq: 0x1234,
206209
msecs: new Date('2011-11-01').getTime(),
207210
nsecs: 5678,
208211
};
209-
uuidv1(v1options); // RESULT
212+
uuidv1(options); // RESULT
213+
```
214+
215+
### uuid.v1ToV6(uuid)
216+
217+
Convert a UUID from version 1 to version 6
218+
219+
```javascript --run
220+
import { v1ToV6 } from 'uuid';
221+
222+
v1ToV6('92f62d9e-22c4-11ef-97e9-325096b39f47'); // RESULT
210223
```
211224

212225
### uuid.v3(name, namespace[, buffer[, offset]])
@@ -289,6 +302,42 @@ import { v5 as uuidv5 } from 'uuid';
289302
uuidv5('https://www.w3.org/', uuidv5.URL); // RESULT
290303
```
291304

305+
### uuid.v6([options[, buffer[, offset]]])
306+
307+
Create an RFC version 6 (timestamp, reordered) UUID
308+
309+
This method takes the same arguments as uuid.v1().
310+
311+
```javascript --run
312+
import { v6 as uuidv6 } from 'uuid';
313+
314+
uuidv6(); // RESULT
315+
```
316+
317+
Example using `options`:
318+
319+
```javascript --run
320+
import { v6 as uuidv6 } from 'uuid';
321+
322+
const options = {
323+
node: [0x01, 0x23, 0x45, 0x67, 0x89, 0xab],
324+
clockseq: 0x1234,
325+
msecs: new Date('2011-11-01').getTime(),
326+
nsecs: 5678,
327+
};
328+
uuidv6(options); // RESULT
329+
```
330+
331+
### uuid.v6ToV1(uuid)
332+
333+
Convert a UUID from version 6 to version 1
334+
335+
```javascript --run
336+
import { v6ToV1 } from 'uuid';
337+
338+
v6ToV1('1ef22c49-2f62-6d9e-97e9-325096b39f47'); // RESULT
339+
```
340+
292341
### uuid.v7([options[, buffer[, offset]]])
293342

294343
Create an RFC version 7 (random) UUID

bundlewatch.config.json

+10-33
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,17 @@
44
"trackBranches": ["main"]
55
},
66
"files": [
7-
{
8-
"path": "./examples/browser-rollup/dist/v1-size.js",
9-
"maxSize": "1.0 kB"
10-
},
11-
{
12-
"path": "./examples/browser-rollup/dist/v3-size.js",
13-
"maxSize": "2.1 kB"
14-
},
15-
{
16-
"path": "./examples/browser-rollup/dist/v4-size.js",
17-
"maxSize": "0.7 kB"
18-
},
19-
{
20-
"path": "./examples/browser-rollup/dist/v5-size.js",
21-
"maxSize": "1.5 kB"
22-
},
7+
{ "path": "./examples/browser-rollup/dist/v1-size.js", "maxSize": "1.0 kB" },
8+
{ "path": "./examples/browser-rollup/dist/v3-size.js", "maxSize": "2.1 kB" },
9+
{ "path": "./examples/browser-rollup/dist/v4-size.js", "maxSize": "0.7 kB" },
10+
{ "path": "./examples/browser-rollup/dist/v5-size.js", "maxSize": "1.5 kB" },
11+
{ "path": "./examples/browser-rollup/dist/v6-size.js", "maxSize": "1.6 kB" },
2312
{ "path": "./examples/browser-rollup/dist/v7-size.js", "maxSize": "0.8 kB" },
24-
25-
{
26-
"path": "./examples/browser-webpack/dist/v1-size.js",
27-
"maxSize": "1.0 kB"
28-
},
29-
{
30-
"path": "./examples/browser-webpack/dist/v3-size.js",
31-
"maxSize": "2.1 kB"
32-
},
33-
{
34-
"path": "./examples/browser-webpack/dist/v4-size.js",
35-
"maxSize": "0.7 kB"
36-
},
37-
{
38-
"path": "./examples/browser-webpack/dist/v5-size.js",
39-
"maxSize": "1.5 kB"
40-
},
13+
{ "path": "./examples/browser-webpack/dist/v1-size.js", "maxSize": "1.0 kB" },
14+
{ "path": "./examples/browser-webpack/dist/v3-size.js", "maxSize": "2.1 kB" },
15+
{ "path": "./examples/browser-webpack/dist/v4-size.js", "maxSize": "0.7 kB" },
16+
{ "path": "./examples/browser-webpack/dist/v5-size.js", "maxSize": "1.5 kB" },
17+
{ "path": "./examples/browser-webpack/dist/v6-size.js", "maxSize": "1.6 kB" },
4118
{ "path": "./examples/browser-webpack/dist/v7-size.js", "maxSize": "0.8 kB" }
4219
]
4320
}

eslint.config.cjs

+3
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@ module.exports = [
2121
},
2222
parser: babelParser,
2323
},
24+
},
25+
{
2426
rules: {
2527
'no-var': ['error'],
28+
curly: ['error', 'all'],
2629
},
2730
},
2831
{

examples/benchmark/benchmark.js

+31
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ export default function benchmark(uuid, Benchmark) {
6666
.add('uuid.v5()', function () {
6767
uuid.v5('hello.example.com', uuid.v5.DNS);
6868
})
69+
.add('uuid.v6()', function () {
70+
uuid.v6();
71+
})
6972
.add('uuid.v7()', function () {
7073
uuid.v7();
7174
})
@@ -82,10 +85,38 @@ export default function benchmark(uuid, Benchmark) {
8285
})
8386
.on('complete', function () {
8487
console.log('Fastest is ' + this.filter('fastest').map('name'));
88+
console.log('---\n');
89+
})
90+
.run();
91+
}
92+
93+
function testV6Conversion() {
94+
const suite = new Benchmark.Suite({
95+
onError(event) {
96+
console.error(event.target.error);
97+
},
98+
});
99+
100+
const V1_ID = 'f1207660-21d2-11ef-8c4f-419efbd44d48';
101+
const V6_ID = '1ef21d2f-1207-6660-8c4f-419efbd44d48';
102+
103+
suite
104+
.add('uuid.v1ToV6()', function () {
105+
uuid.v1ToV6(V1_ID);
106+
})
107+
.add('uuid.v1ToV6() w/ randomization', function () {
108+
uuid.v1ToV6(V1_ID, true);
109+
})
110+
.add('uuid.v6ToV1()', function () {
111+
uuid.v6ToV1(V6_ID);
112+
})
113+
.on('cycle', function (event) {
114+
console.log(event.target.toString());
85115
})
86116
.run();
87117
}
88118

89119
testParseAndStringify();
90120
testGeneration();
121+
testV6Conversion();
91122
}

examples/benchmark/package-lock.json

+14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)