This repository has been archived by the owner on Feb 7, 2023. It is now read-only.
forked from pmccarren/uuid
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: implement uuid7 (uuidjs#580) * fix: add v7.js to .local (uuidjs#580) note, husky pre-commit hook was bypassed for this commit * fix: add v7 to uuid-bin * chore: fix readme anchor * chore: use generated readme, remove timestamp arg from uuid-bin v7 * fix: typo in uuid regex, add negative test cases * fix: do not mutate provided rnds, add v7 unit tests * fix: validation test should not pass version 0 * chore: update package.json description * Update src/v7.js Co-authored-by: Linus Unnebäck <[email protected]> * include uuid v6 and v8 in validation regex * chore: add test:matching script to package.json * fix: v7 monotonicity and lexicographical sorting * refactor: v7 seq reinitialization * chore: update v7 README --------- Co-authored-by: Patrick McCarren <[email protected]> Co-authored-by: Linus Unnebäck <[email protected]>
- Loading branch information
1 parent
eca69af
commit 9e3799a
Showing
37 changed files
with
534 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../v7.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ Christoph Tavan <[email protected]> | |
AJ ONeal <[email protected]> | ||
Vincent Voyer <[email protected]> | ||
Roman Shtylman <[email protected]> | ||
Patrick McCarren <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
|
||
For the creation of [RFC4122](https://www.ietf.org/rfc/rfc4122.txt) UUIDs | ||
|
||
- **Complete** - Support for RFC4122 version 1, 3, 4, and 5 UUIDs | ||
- **Complete** - Support for RFC4122 version 1, 3, 4, 5, and 7 UUIDs | ||
- **Cross-platform** - Support for ... | ||
- CommonJS, [ECMAScript Modules](#ecmascript-modules) and [CDN builds](#cdn-builds) | ||
- Node 12, 14, 16, 18 | ||
|
@@ -56,6 +56,7 @@ For timestamp UUIDs, namespace UUIDs, and other options read on ... | |
| [`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.validate()`](#uuidvalidatestr) | Test a string to see if it is a valid UUID | New in `[email protected]` | | ||
| [`uuid.version()`](#uuidversionstr) | Detect RFC version of a UUID | New in `[email protected]` | | ||
|
||
|
@@ -248,6 +249,29 @@ import { v5 as uuidv5 } from 'uuid'; | |
uuidv5('https://www.w3.org/', uuidv5.URL); // ⇨ 'c106a26a-21bb-5538-8bf2-57095d1976c1' | ||
``` | ||
|
||
### uuid.v7([options[, buffer[, offset]]]) | ||
|
||
Create an RFC version 7 (random) UUID | ||
|
||
| | | | ||
| --- | --- | | ||
| [`options`] | `Object` with one or more of the following properties: | | ||
| [`options.msecs`] | RFC "timestamp" field (`Number` of milliseconds, unix epoch) | | ||
| [`options.random`] | `Array` of 16 random bytes (0-255) | | ||
| [`options.rng`] | Alternative to `options.random`, a `Function` that returns an `Array` of 16 random bytes (0-255) | | ||
| [`options.seq`] | 31 bit monotonic sequence counter as `Number` between 0 - 0x7fffffff | | ||
| [`buffer`] | `Array \| Buffer` If specified, uuid will be written here in byte-form, starting at `offset` | | ||
| [`offset` = 0] | `Number` Index to start writing UUID bytes in `buffer` | | ||
| _returns_ | UUID `String` if no `buffer` is specified, otherwise returns `buffer` | | ||
|
||
Example: | ||
|
||
```javascript | ||
import { v7 as uuidv7 } from 'uuid'; | ||
|
||
uuidv7(); // ⇨ '01695553-c90c-7aad-9bdd-330d7b3dcb6d' | ||
``` | ||
|
||
### uuid.validate(str) | ||
|
||
Test a string to see if it is a valid UUID | ||
|
@@ -322,6 +346,7 @@ Usage: | |
uuid v3 <name> <namespace uuid> | ||
uuid v4 | ||
uuid v5 <name> <namespace uuid> | ||
uuid v7 | ||
uuid --help | ||
|
||
Note: <namespace uuid> may be "URL" or "DNS" to use the corresponding UUIDs | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ require('crypto').randomUUID = undefined; | |
|
||
For the creation of [RFC4122](https://www.ietf.org/rfc/rfc4122.txt) UUIDs | ||
|
||
- **Complete** - Support for RFC4122 version 1, 3, 4, and 5 UUIDs | ||
- **Complete** - Support for RFC4122 version 1, 3, 4, 5, and 7 UUIDs | ||
- **Cross-platform** - Support for ... | ||
- CommonJS, [ECMAScript Modules](#ecmascript-modules) and [CDN builds](#cdn-builds) | ||
- Node 12, 14, 16, 18 | ||
|
@@ -71,6 +71,7 @@ For timestamp UUIDs, namespace UUIDs, and other options read on ... | |
| [`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.validate()`](#uuidvalidatestr) | Test a string to see if it is a valid UUID | New in `[email protected]` | | ||
| [`uuid.version()`](#uuidversionstr) | Detect RFC version of a UUID | New in `[email protected]` | | ||
|
||
|
@@ -257,6 +258,29 @@ import { v5 as uuidv5 } from 'uuid'; | |
uuidv5('https://www.w3.org/', uuidv5.URL); // RESULT | ||
``` | ||
|
||
### uuid.v7([options[, buffer[, offset]]]) | ||
|
||
Create an RFC version 7 (random) UUID | ||
|
||
| | | | ||
| --- | --- | | ||
| [`options`] | `Object` with one or more of the following properties: | | ||
| [`options.msecs`] | RFC "timestamp" field (`Number` of milliseconds, unix epoch) | | ||
| [`options.random`] | `Array` of 16 random bytes (0-255) | | ||
| [`options.rng`] | Alternative to `options.random`, a `Function` that returns an `Array` of 16 random bytes (0-255) | | ||
| [`options.seq`] | 31 bit monotonic sequence counter as `Number` between 0 - 0x7fffffff | | ||
| [`buffer`] | `Array \| Buffer` If specified, uuid will be written here in byte-form, starting at `offset` | | ||
| [`offset` = 0] | `Number` Index to start writing UUID bytes in `buffer` | | ||
| _returns_ | UUID `String` if no `buffer` is specified, otherwise returns `buffer` | | ||
|
||
Example: | ||
|
||
```javascript --run | ||
import { v7 as uuidv7 } from 'uuid'; | ||
|
||
uuidv7(); // RESULT | ||
``` | ||
|
||
### uuid.validate(str) | ||
|
||
Test a string to see if it is a valid UUID | ||
|
@@ -331,6 +355,7 @@ Usage: | |
uuid v3 <name> <namespace uuid> | ||
uuid v4 | ||
uuid v5 <name> <namespace uuid> | ||
uuid v7 | ||
uuid --help | ||
|
||
Note: <namespace uuid> may be "URL" or "DNS" to use the corresponding UUIDs | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
|
||
<head> | ||
<title>UUID esmodule webpack example</title> | ||
</head> | ||
|
||
<body> | ||
<script type="text/javascript" src="./dist/v7.js"></script> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { v7 as uuidv7 } from 'uuid'; | ||
|
||
import testpage from '../utils/testpage'; | ||
|
||
testpage(function (addTest, done) { | ||
addTest('uuidv7()', uuidv7()); | ||
done(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { v7 as uuidv7 } from 'uuid'; | ||
|
||
uuidv7(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
|
||
<head> | ||
<title>UUID esmodule webpack example</title> | ||
</head> | ||
|
||
<body> | ||
<script type="text/javascript" src="./dist/v7.js"></script> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { v7 as uuidv7 } from 'uuid'; | ||
|
||
import testpage from '../utils/testpage'; | ||
|
||
testpage(function (addTest, done) { | ||
addTest('uuidv7()', uuidv7()); | ||
|
||
done(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { v7 as uuidv7 } from 'uuid'; | ||
|
||
uuidv7(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.