Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: v8 support #759

Merged
merged 30 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
9b365da
feat: support v6 uuids
broofa Jun 3, 2024
8aeee27
fix: test and comment
broofa Jun 3, 2024
6eebe89
test: add v1<->v6 utilities to browser tests
broofa Jun 4, 2024
a69f436
fix: filenames and lint flags
broofa Jun 4, 2024
f4cf3e8
chore: upgrade husky dependency
broofa Jun 4, 2024
4710dee
chore: revert bundlewatch config
broofa Jun 4, 2024
f7efb7f
feat: add v6 method
broofa Jun 4, 2024
f5c6018
fix: make browser test more resilient to test order
broofa Jun 4, 2024
18cff2e
chore: revise v6 implementation
broofa Jun 5, 2024
09e269d
docs: update with v6 API
broofa Jun 5, 2024
3c35893
chore: update v6 bundlewatch size
broofa Jun 5, 2024
d09e432
docs: v6 uuid
broofa Jun 5, 2024
b510bac
Merge branch 'main' into v1v6
broofa Jun 5, 2024
7d206b4
chore: v6 bundlewatch size
broofa Jun 5, 2024
e06069d
Merge branch 'main' into v1v6
broofa Jun 5, 2024
e94c947
fix: add .local/v6.js
broofa Jun 5, 2024
ac6bfdb
chore: gitignore vscode
broofa Jun 5, 2024
fdab55f
chore: rm vscode dir
broofa Jun 5, 2024
5df758e
chore: update comments
broofa Jun 5, 2024
4f13e5c
chore: v8 support (meaning improved unit tests)
broofa Jun 5, 2024
f3a94e2
docs: document v8() as deliberately not-implemented
broofa Jun 5, 2024
08d9303
fix: pr feedback
broofa Jun 5, 2024
0212b6e
docs: fix broken anchor refs
broofa Jun 5, 2024
3e12bf6
Merge branch 'v1v6' into v8
broofa Jun 5, 2024
fe81cbb
docs: typo
broofa Jun 5, 2024
604505e
Merge branch 'v1v6' into v8
broofa Jun 5, 2024
5d54310
docs: fix regression
broofa Jun 5, 2024
59978d7
Merge branch 'v1v6' into v8
broofa Jun 5, 2024
c851c4d
fix: eslint --fix
broofa Jun 5, 2024
c471e30
Merge branch 'main' into v8
broofa Jun 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
node_modules/
dist/
# Browserstack
*.tgz
browserstack.err
dist/
local.log
*.tgz
node_modules/
vscode/
1 change: 1 addition & 0 deletions .local/uuid/v1tov6.js
1 change: 1 addition & 0 deletions .local/uuid/v6.js
1 change: 1 addition & 0 deletions .local/uuid/v6tov1.js
4 changes: 3 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
dist/
node_modules/
README.md
*.sh
*.sh
.gitignore
.prettierignore
76 changes: 68 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
-- This file is auto-generated from README_js.md. Changes should be made there.
-->


# 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)

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

- **Complete** - Support for all RFC9562 UUID versions
- **Complete** - Support for all RFC9562 (nee RFC4122) UUID versions
- **Cross-platform** - Support for ...
- CommonJS, [ECMAScript Modules](#ecmascript-modules) and [CDN builds](#cdn-builds)
- NodeJS 16+ ([LTS releases](https://github.com/nodejs/Release))
Expand Down Expand Up @@ -60,10 +61,14 @@ For timestamp UUIDs, namespace UUIDs, and other options read on ...
| [`uuid.parse()`](#uuidparsestr) | Convert UUID string to array of bytes | New in `uuid@8.3` |
| [`uuid.stringify()`](#uuidstringifyarr-offset) | Convert array of bytes to UUID string | New in `uuid@8.3` |
| [`uuid.v1()`](#uuidv1options-buffer-offset) | Create a version 1 (timestamp) UUID | |
| [`uuid.v1ToV6()`](#uuidv1tov6uuid) | Create a version 6 UUID from a version 1 UUID | New in `uuid@10` |
| [`uuid.v3()`](#uuidv3name-namespace-buffer-offset) | Create a version 3 (namespace w/ MD5) UUID | |
| [`uuid.v4()`](#uuidv4options-buffer-offset) | Create a version 4 (random) UUID | |
| [`uuid.v5()`](#uuidv5name-namespace-buffer-offset) | Create a version 5 (namespace w/ SHA-1) UUID | |
| [`uuid.v7()`](#uuidv7options-buffer-offset) | Create a version 7 (Unix Epoch time-based) UUID | `experimental support` |
| [`uuid.v6()`](#uuidv6options-buffer-offset) | Create a version 6 (timestamp, reordered) UUID | New in `uuid@10` |
| [`uuid.v6ToV1()`](#uuidv6tov1uuid) | Create a version 1 UUID from a version 6 UUID | New in `uuid@10` |
| [`uuid.v7()`](#uuidv7options-buffer-offset) | Create a version 7 (Unix Epoch time-based) UUID | New in `uuid@10` |
| ~~[`uuid.v8()`](#uuidv8)~~ | "Intentionally left blank" | |
| [`uuid.validate()`](#uuidvalidatestr) | Test a string to see if it is a valid UUID | New in `uuid@8.3` |
| [`uuid.version()`](#uuidversionstr) | Detect RFC version of a UUID | New in `uuid@8.3` |

Expand Down Expand Up @@ -116,7 +121,7 @@ import { parse as uuidParse } from 'uuid';
const bytes = uuidParse('6ec0bd7f-11c0-43da-975e-2a8ad9ebae0b');

// Convert to hex strings to show byte order (for documentation purposes)
[...bytes].map((v) => v.toString(16).padStart(2, '0')); // ⇨
[...bytes].map((v) => v.toString(16).padStart(2, '0')); // ⇨
// [
// '6e', 'c0', 'bd', '7f',
// '11', 'c0', '43', 'da',
Expand Down Expand Up @@ -191,13 +196,23 @@ Example using `options`:
```javascript
import { v1 as uuidv1 } from 'uuid';

const v1options = {
const options = {
node: [0x01, 0x23, 0x45, 0x67, 0x89, 0xab],
clockseq: 0x1234,
msecs: new Date('2011-11-01').getTime(),
nsecs: 5678,
};
uuidv1(v1options); // ⇨ '710b962e-041c-11e1-9234-0123456789ab'
uuidv1(options); // ⇨ '710b962e-041c-11e1-9234-0123456789ab'
```

### uuid.v1ToV6(uuid)

Convert a UUID from version 1 to version 6

```javascript
import { v1ToV6 } from 'uuid';

v1ToV6('92f62d9e-22c4-11ef-97e9-325096b39f47'); // ⇨ '1ef22c49-2f62-6d9e-97e9-325096b39f47'
```

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

### uuid.v6([options[, buffer[, offset]]])

Create an RFC version 6 (timestamp, reordered) UUID

This method takes the same arguments as uuid.v1().

```javascript
import { v6 as uuidv6 } from 'uuid';

uuidv6(); // ⇨ '1e940672-c5ea-64c0-8bad-9b1deb4d3b7d'
```

Example using `options`:

```javascript
import { v6 as uuidv6 } from 'uuid';

const options = {
node: [0x01, 0x23, 0x45, 0x67, 0x89, 0xab],
clockseq: 0x1234,
msecs: new Date('2011-11-01').getTime(),
nsecs: 5678,
};
uuidv6(options); // ⇨ '1e1041c7-10b9-662e-9234-0123456789ab'
```

### uuid.v6ToV1(uuid)

Convert a UUID from version 6 to version 1

```javascript
import { v6ToV1 } from 'uuid';

v6ToV1('1ef22c49-2f62-6d9e-97e9-325096b39f47'); // ⇨ '92f62d9e-22c4-11ef-97e9-325096b39f47'
```

### uuid.v7([options[, buffer[, offset]]])

Create an RFC version 7 (random) UUID
Expand All @@ -300,9 +351,17 @@ Example:
```javascript
import { v7 as uuidv7 } from 'uuid';

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

### ~~uuid.v8()~~

**_"Intentionally left blank"_**

<!-- prettier-ignore -->
> [!NOTE]
> Version 8 (experimental) UUIDs are "[for experimental or vendor-specific use cases](https://www.rfc-editor.org/rfc/rfc9562.html#name-uuid-version-8)". The RFC does not define a creation algorithm for them, which is why this package does not offer a `v8()` method. The `validate()` and `version()` methods do work with such UUIDs, however.

### uuid.validate(str)

Test a string to see if it is a valid UUID
Expand Down Expand Up @@ -520,5 +579,6 @@ const uuid = require('uuid'); // <== REMOVED!

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

----
Markdown generated from [README_js.md](README_js.md) by [![RunMD Logo](https://i.imgur.com/h0FVyzU.png)](https://github.com/broofa/runmd)
---

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>
66 changes: 62 additions & 4 deletions README_js.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ require('crypto').randomUUID = undefined;

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

- **Complete** - Support for RFC9562 version 1, 3, 4, 5, and 7 UUIDs
- **Complete** - Support for all RFC9562 (nee RFC4122) UUID versions
- **Cross-platform** - Support for ...
- CommonJS, [ECMAScript Modules](#ecmascript-modules) and [CDN builds](#cdn-builds)
- NodeJS 16+ ([LTS releases](https://github.com/nodejs/Release))
Expand Down Expand Up @@ -75,10 +75,14 @@ For timestamp UUIDs, namespace UUIDs, and other options read on ...
| [`uuid.parse()`](#uuidparsestr) | Convert UUID string to array of bytes | New in `uuid@8.3` |
| [`uuid.stringify()`](#uuidstringifyarr-offset) | Convert array of bytes to UUID string | New in `uuid@8.3` |
| [`uuid.v1()`](#uuidv1options-buffer-offset) | Create a version 1 (timestamp) UUID | |
| [`uuid.v1ToV6()`](#uuidv1tov6uuid) | Create a version 6 UUID from a version 1 UUID | New in `uuid@10` |
| [`uuid.v3()`](#uuidv3name-namespace-buffer-offset) | Create a version 3 (namespace w/ MD5) UUID | |
| [`uuid.v4()`](#uuidv4options-buffer-offset) | Create a version 4 (random) UUID | |
| [`uuid.v5()`](#uuidv5name-namespace-buffer-offset) | Create a version 5 (namespace w/ SHA-1) UUID | |
| [`uuid.v7()`](#uuidv7options-buffer-offset) | Create a version 7 (Unix Epoch time-based) UUID | `experimental support` |
| [`uuid.v6()`](#uuidv6options-buffer-offset) | Create a version 6 (timestamp, reordered) UUID | New in `uuid@10` |
| [`uuid.v6ToV1()`](#uuidv6tov1uuid) | Create a version 1 UUID from a version 6 UUID | New in `uuid@10` |
| [`uuid.v7()`](#uuidv7options-buffer-offset) | Create a version 7 (Unix Epoch time-based) UUID | New in `uuid@10` |
| ~~[`uuid.v8()`](#uuidv8)~~ | "Intentionally left blank" | |
| [`uuid.validate()`](#uuidvalidatestr) | Test a string to see if it is a valid UUID | New in `uuid@8.3` |
| [`uuid.version()`](#uuidversionstr) | Detect RFC version of a UUID | New in `uuid@8.3` |

Expand Down Expand Up @@ -200,13 +204,23 @@ Example using `options`:
```javascript --run
import { v1 as uuidv1 } from 'uuid';

const v1options = {
const options = {
node: [0x01, 0x23, 0x45, 0x67, 0x89, 0xab],
clockseq: 0x1234,
msecs: new Date('2011-11-01').getTime(),
nsecs: 5678,
};
uuidv1(v1options); // RESULT
uuidv1(options); // RESULT
```

### uuid.v1ToV6(uuid)

Convert a UUID from version 1 to version 6

```javascript --run
import { v1ToV6 } from 'uuid';

v1ToV6('92f62d9e-22c4-11ef-97e9-325096b39f47'); // RESULT
```

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

### uuid.v6([options[, buffer[, offset]]])

Create an RFC version 6 (timestamp, reordered) UUID

This method takes the same arguments as uuid.v1().

```javascript --run
import { v6 as uuidv6 } from 'uuid';

uuidv6(); // RESULT
```

Example using `options`:

```javascript --run
import { v6 as uuidv6 } from 'uuid';

const options = {
node: [0x01, 0x23, 0x45, 0x67, 0x89, 0xab],
clockseq: 0x1234,
msecs: new Date('2011-11-01').getTime(),
nsecs: 5678,
};
uuidv6(options); // RESULT
```

### uuid.v6ToV1(uuid)

Convert a UUID from version 6 to version 1

```javascript --run
import { v6ToV1 } from 'uuid';

v6ToV1('1ef22c49-2f62-6d9e-97e9-325096b39f47'); // RESULT
```

### uuid.v7([options[, buffer[, offset]]])

Create an RFC version 7 (random) UUID
Expand All @@ -312,6 +362,14 @@ import { v7 as uuidv7 } from 'uuid';
uuidv7(); // RESULT
```

### ~~uuid.v8()~~

**_"Intentionally left blank"_**

<!-- prettier-ignore -->
> [!NOTE]
> Version 8 (experimental) UUIDs are "[for experimental or vendor-specific use cases](https://www.rfc-editor.org/rfc/rfc9562.html#name-uuid-version-8)". The RFC does not define a creation algorithm for them, which is why this package does not offer a `v8()` method. The `validate()` and `version()` methods do work with such UUIDs, however.

### uuid.validate(str)

Test a string to see if it is a valid UUID
Expand Down
43 changes: 10 additions & 33 deletions bundlewatch.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,17 @@
"trackBranches": ["main"]
},
"files": [
{
"path": "./examples/browser-rollup/dist/v1-size.js",
"maxSize": "1.0 kB"
},
{
"path": "./examples/browser-rollup/dist/v3-size.js",
"maxSize": "2.1 kB"
},
{
"path": "./examples/browser-rollup/dist/v4-size.js",
"maxSize": "0.7 kB"
},
{
"path": "./examples/browser-rollup/dist/v5-size.js",
"maxSize": "1.5 kB"
},
{ "path": "./examples/browser-rollup/dist/v1-size.js", "maxSize": "1.0 kB" },
{ "path": "./examples/browser-rollup/dist/v3-size.js", "maxSize": "2.1 kB" },
{ "path": "./examples/browser-rollup/dist/v4-size.js", "maxSize": "0.7 kB" },
{ "path": "./examples/browser-rollup/dist/v5-size.js", "maxSize": "1.5 kB" },
{ "path": "./examples/browser-rollup/dist/v6-size.js", "maxSize": "1.6 kB" },
{ "path": "./examples/browser-rollup/dist/v7-size.js", "maxSize": "0.8 kB" },

{
"path": "./examples/browser-webpack/dist/v1-size.js",
"maxSize": "1.0 kB"
},
{
"path": "./examples/browser-webpack/dist/v3-size.js",
"maxSize": "2.1 kB"
},
{
"path": "./examples/browser-webpack/dist/v4-size.js",
"maxSize": "0.7 kB"
},
{
"path": "./examples/browser-webpack/dist/v5-size.js",
"maxSize": "1.5 kB"
},
{ "path": "./examples/browser-webpack/dist/v1-size.js", "maxSize": "1.0 kB" },
{ "path": "./examples/browser-webpack/dist/v3-size.js", "maxSize": "2.1 kB" },
{ "path": "./examples/browser-webpack/dist/v4-size.js", "maxSize": "0.7 kB" },
{ "path": "./examples/browser-webpack/dist/v5-size.js", "maxSize": "1.5 kB" },
{ "path": "./examples/browser-webpack/dist/v6-size.js", "maxSize": "1.6 kB" },
{ "path": "./examples/browser-webpack/dist/v7-size.js", "maxSize": "0.8 kB" }
]
}
3 changes: 3 additions & 0 deletions eslint.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ module.exports = [
},
parser: babelParser,
},
},
{
rules: {
'no-var': ['error'],
curly: ['error', 'all'],
},
},
{
Expand Down
31 changes: 31 additions & 0 deletions examples/benchmark/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ export default function benchmark(uuid, Benchmark) {
.add('uuid.v5()', function () {
uuid.v5('hello.example.com', uuid.v5.DNS);
})
.add('uuid.v6()', function () {
uuid.v6();
})
.add('uuid.v7()', function () {
uuid.v7();
})
Expand All @@ -82,10 +85,38 @@ export default function benchmark(uuid, Benchmark) {
})
.on('complete', function () {
console.log('Fastest is ' + this.filter('fastest').map('name'));
console.log('---\n');
})
.run();
}

function testV6Conversion() {
const suite = new Benchmark.Suite({
onError(event) {
console.error(event.target.error);
},
});

const V1_ID = 'f1207660-21d2-11ef-8c4f-419efbd44d48';
const V6_ID = '1ef21d2f-1207-6660-8c4f-419efbd44d48';

suite
.add('uuid.v1ToV6()', function () {
uuid.v1ToV6(V1_ID);
})
.add('uuid.v1ToV6() w/ randomization', function () {
uuid.v1ToV6(V1_ID, true);
})
.add('uuid.v6ToV1()', function () {
uuid.v6ToV1(V6_ID);
})
.on('cycle', function (event) {
console.log(event.target.toString());
})
.run();
}

testParseAndStringify();
testGeneration();
testV6Conversion();
}
Loading
Loading