uuid 3.2.1 → 3.4.0
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 +79 -17
- package/README.md +30 -47
- package/lib/bytesToUuid.js +11 -8
- package/lib/rng-browser.js +5 -3
- package/lib/v35.js +5 -1
- package/package.json +21 -8
- package/v1.js +1 -1
- package/.eslintrc.json +0 -47
- package/README_js.md +0 -280
package/CHANGELOG.md
CHANGED
|
@@ -1,57 +1,119 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Changelog
|
|
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
|
+
## [3.4.0](https://github.com/uuidjs/uuid/compare/v3.3.3...v3.4.0) (2020-01-16)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* rename repository to github:uuidjs/uuid ([#351](https://github.com/uuidjs/uuid/issues/351)) ([e2d7314](https://github.com/uuidjs/uuid/commit/e2d7314)), closes [#338](https://github.com/uuidjs/uuid/issues/338)
|
|
11
|
+
|
|
12
|
+
### [3.3.3](https://github.com/uuidjs/uuid/compare/v3.3.2...v3.3.3) (2019-08-19)
|
|
13
|
+
|
|
14
|
+
<a name="3.3.2"></a>
|
|
15
|
+
## [3.3.2](https://github.com/uuidjs/uuid/compare/v3.3.1...v3.3.2) (2018-06-28)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* typo ([305d877](https://github.com/uuidjs/uuid/commit/305d877))
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
<a name="3.3.1"></a>
|
|
25
|
+
## [3.3.1](https://github.com/uuidjs/uuid/compare/v3.3.0...v3.3.1) (2018-06-28)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### Bug Fixes
|
|
29
|
+
|
|
30
|
+
* fix [#284](https://github.com/uuidjs/uuid/issues/284) by setting function name in try-catch ([f2a60f2](https://github.com/uuidjs/uuid/commit/f2a60f2))
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
<a name="3.3.0"></a>
|
|
35
|
+
# [3.3.0](https://github.com/uuidjs/uuid/compare/v3.2.1...v3.3.0) (2018-06-22)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
### Bug Fixes
|
|
39
|
+
|
|
40
|
+
* assignment to readonly property to allow running in strict mode ([#270](https://github.com/uuidjs/uuid/issues/270)) ([d062fdc](https://github.com/uuidjs/uuid/commit/d062fdc))
|
|
41
|
+
* fix [#229](https://github.com/uuidjs/uuid/issues/229) ([c9684d4](https://github.com/uuidjs/uuid/commit/c9684d4))
|
|
42
|
+
* Get correct version of IE11 crypto ([#274](https://github.com/uuidjs/uuid/issues/274)) ([153d331](https://github.com/uuidjs/uuid/commit/153d331))
|
|
43
|
+
* mem issue when generating uuid ([#267](https://github.com/uuidjs/uuid/issues/267)) ([c47702c](https://github.com/uuidjs/uuid/commit/c47702c))
|
|
44
|
+
|
|
45
|
+
### Features
|
|
46
|
+
|
|
47
|
+
* enforce Conventional Commit style commit messages ([#282](https://github.com/uuidjs/uuid/issues/282)) ([cc9a182](https://github.com/uuidjs/uuid/commit/cc9a182))
|
|
48
|
+
|
|
49
|
+
|
|
5
50
|
<a name="3.2.1"></a>
|
|
6
|
-
## [3.2.1](https://github.com/
|
|
51
|
+
## [3.2.1](https://github.com/uuidjs/uuid/compare/v3.2.0...v3.2.1) (2018-01-16)
|
|
7
52
|
|
|
8
53
|
|
|
9
54
|
### Bug Fixes
|
|
10
55
|
|
|
11
|
-
* use msCrypto if available. Fixes [#241](https://github.com/
|
|
56
|
+
* use msCrypto if available. Fixes [#241](https://github.com/uuidjs/uuid/issues/241) ([#247](https://github.com/uuidjs/uuid/issues/247)) ([1fef18b](https://github.com/uuidjs/uuid/commit/1fef18b))
|
|
12
57
|
|
|
13
58
|
|
|
14
59
|
|
|
15
60
|
<a name="3.2.0"></a>
|
|
16
|
-
# [3.2.0](https://github.com/
|
|
61
|
+
# [3.2.0](https://github.com/uuidjs/uuid/compare/v3.1.0...v3.2.0) (2018-01-16)
|
|
17
62
|
|
|
18
63
|
|
|
19
64
|
### Bug Fixes
|
|
20
65
|
|
|
21
|
-
* remove mistakenly added typescript dependency, rollback version (standard-version will auto-increment) ([09fa824](https://github.com/
|
|
22
|
-
* use msCrypto if available. Fixes [#241](https://github.com/
|
|
66
|
+
* remove mistakenly added typescript dependency, rollback version (standard-version will auto-increment) ([09fa824](https://github.com/uuidjs/uuid/commit/09fa824))
|
|
67
|
+
* use msCrypto if available. Fixes [#241](https://github.com/uuidjs/uuid/issues/241) ([#247](https://github.com/uuidjs/uuid/issues/247)) ([1fef18b](https://github.com/uuidjs/uuid/commit/1fef18b))
|
|
23
68
|
|
|
24
69
|
|
|
25
70
|
### Features
|
|
26
71
|
|
|
27
|
-
* Add v3 Support ([#217](https://github.com/
|
|
72
|
+
* Add v3 Support ([#217](https://github.com/uuidjs/uuid/issues/217)) ([d94f726](https://github.com/uuidjs/uuid/commit/d94f726))
|
|
73
|
+
|
|
28
74
|
|
|
75
|
+
# [3.1.0](https://github.com/uuidjs/uuid/compare/v3.1.0...v3.0.1) (2017-06-17)
|
|
76
|
+
|
|
77
|
+
### Bug Fixes
|
|
78
|
+
|
|
79
|
+
* (fix) Add .npmignore file to exclude test/ and other non-essential files from packing. (#183)
|
|
80
|
+
* Fix typo (#178)
|
|
81
|
+
* Simple typo fix (#165)
|
|
82
|
+
|
|
83
|
+
### Features
|
|
84
|
+
* v5 support in CLI (#197)
|
|
85
|
+
* V5 support (#188)
|
|
29
86
|
|
|
30
87
|
|
|
31
88
|
# 3.0.1 (2016-11-28)
|
|
32
89
|
|
|
33
|
-
|
|
90
|
+
* split uuid versions into separate files
|
|
91
|
+
|
|
34
92
|
|
|
35
93
|
# 3.0.0 (2016-11-17)
|
|
36
94
|
|
|
37
|
-
|
|
95
|
+
* remove .parse and .unparse
|
|
96
|
+
|
|
38
97
|
|
|
39
98
|
# 2.0.0
|
|
40
99
|
|
|
41
|
-
|
|
100
|
+
* Removed uuid.BufferClass
|
|
101
|
+
|
|
42
102
|
|
|
43
103
|
# 1.4.0
|
|
44
104
|
|
|
45
|
-
|
|
46
|
-
|
|
105
|
+
* Improved module context detection
|
|
106
|
+
* Removed public RNG functions
|
|
107
|
+
|
|
47
108
|
|
|
48
109
|
# 1.3.2
|
|
49
110
|
|
|
50
|
-
|
|
51
|
-
|
|
111
|
+
* Improve tests and handling of v1() options (Issue #24)
|
|
112
|
+
* Expose RNG option to allow for perf testing with different generators
|
|
113
|
+
|
|
52
114
|
|
|
53
115
|
# 1.3.0
|
|
54
116
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
117
|
+
* Support for version 1 ids, thanks to [@ctavan](https://github.com/ctavan)!
|
|
118
|
+
* Support for node.js crypto API
|
|
119
|
+
* De-emphasizing performance in favor of a) cryptographic quality PRNGs where available and b) more manageable code
|
package/README.md
CHANGED
|
@@ -28,7 +28,7 @@ Version 1 (timestamp):
|
|
|
28
28
|
|
|
29
29
|
```javascript
|
|
30
30
|
const uuidv1 = require('uuid/v1');
|
|
31
|
-
uuidv1(); // ⇨ '
|
|
31
|
+
uuidv1(); // ⇨ '2c5ea4c0-4067-11e9-8bad-9b1deb4d3b7d'
|
|
32
32
|
|
|
33
33
|
```
|
|
34
34
|
|
|
@@ -56,7 +56,7 @@ Version 4 (random):
|
|
|
56
56
|
|
|
57
57
|
```javascript
|
|
58
58
|
const uuidv4 = require('uuid/v4');
|
|
59
|
-
uuidv4(); // ⇨ '
|
|
59
|
+
uuidv4(); // ⇨ '1b9d6bcd-bbfd-4b2d-9b5d-ab8dfbbd4bed'
|
|
60
60
|
|
|
61
61
|
```
|
|
62
62
|
|
|
@@ -80,46 +80,6 @@ uuidv5('Hello, World!', MY_NAMESPACE); // ⇨ '630eb68f-e0fa-5ecc-887a-7c7a62614
|
|
|
80
80
|
|
|
81
81
|
```
|
|
82
82
|
|
|
83
|
-
## Quickstart - Browser-ready Versions
|
|
84
|
-
|
|
85
|
-
Browser-ready versions of this module are available via [wzrd.in](https://github.com/jfhbrook/wzrd.in).
|
|
86
|
-
|
|
87
|
-
For version 1 uuids:
|
|
88
|
-
|
|
89
|
-
```html
|
|
90
|
-
<script src="http://wzrd.in/standalone/uuid%2Fv1@latest"></script>
|
|
91
|
-
<script>
|
|
92
|
-
uuidv1(); // -> v1 UUID
|
|
93
|
-
</script>
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
For version 3 uuids:
|
|
97
|
-
|
|
98
|
-
```html
|
|
99
|
-
<script src="http://wzrd.in/standalone/uuid%2Fv3@latest"></script>
|
|
100
|
-
<script>
|
|
101
|
-
uuidv3('http://example.com/hello', uuidv3.URL); // -> v3 UUID
|
|
102
|
-
</script>
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
For version 4 uuids:
|
|
106
|
-
|
|
107
|
-
```html
|
|
108
|
-
<script src="http://wzrd.in/standalone/uuid%2Fv4@latest"></script>
|
|
109
|
-
<script>
|
|
110
|
-
uuidv4(); // -> v4 UUID
|
|
111
|
-
</script>
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
For version 5 uuids:
|
|
115
|
-
|
|
116
|
-
```html
|
|
117
|
-
<script src="http://wzrd.in/standalone/uuid%2Fv5@latest"></script>
|
|
118
|
-
<script>
|
|
119
|
-
uuidv5('http://example.com/hello', uuidv5.URL); // -> v5 UUID
|
|
120
|
-
</script>
|
|
121
|
-
```
|
|
122
|
-
|
|
123
83
|
## API
|
|
124
84
|
|
|
125
85
|
### Version 1
|
|
@@ -147,7 +107,7 @@ Generate and return a RFC4122 v1 (timestamp-based) UUID.
|
|
|
147
107
|
|
|
148
108
|
Returns `buffer`, if specified, otherwise the string form of the UUID
|
|
149
109
|
|
|
150
|
-
Note: The
|
|
110
|
+
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.
|
|
151
111
|
|
|
152
112
|
Example: Generate string UUID with fully-specified options
|
|
153
113
|
|
|
@@ -167,8 +127,19 @@ Example: In-place generation of two binary IDs
|
|
|
167
127
|
```javascript
|
|
168
128
|
// Generate two ids in an array
|
|
169
129
|
const arr = new Array();
|
|
170
|
-
uuidv1(null, arr, 0); // ⇨
|
|
171
|
-
|
|
130
|
+
uuidv1(null, arr, 0); // ⇨
|
|
131
|
+
// [
|
|
132
|
+
// 44, 94, 164, 192, 64, 103,
|
|
133
|
+
// 17, 233, 146, 52, 155, 29,
|
|
134
|
+
// 235, 77, 59, 125
|
|
135
|
+
// ]
|
|
136
|
+
uuidv1(null, arr, 16); // ⇨
|
|
137
|
+
// [
|
|
138
|
+
// 44, 94, 164, 192, 64, 103, 17, 233,
|
|
139
|
+
// 146, 52, 155, 29, 235, 77, 59, 125,
|
|
140
|
+
// 44, 94, 164, 193, 64, 103, 17, 233,
|
|
141
|
+
// 146, 52, 155, 29, 235, 77, 59, 125
|
|
142
|
+
// ]
|
|
172
143
|
|
|
173
144
|
```
|
|
174
145
|
|
|
@@ -237,8 +208,20 @@ Example: Generate two IDs in a single buffer
|
|
|
237
208
|
|
|
238
209
|
```javascript
|
|
239
210
|
const buffer = new Array();
|
|
240
|
-
uuidv4(null, buffer, 0); // ⇨
|
|
241
|
-
|
|
211
|
+
uuidv4(null, buffer, 0); // ⇨
|
|
212
|
+
// [
|
|
213
|
+
// 155, 29, 235, 77, 59,
|
|
214
|
+
// 125, 75, 173, 155, 221,
|
|
215
|
+
// 43, 13, 123, 61, 203,
|
|
216
|
+
// 109
|
|
217
|
+
// ]
|
|
218
|
+
uuidv4(null, buffer, 16); // ⇨
|
|
219
|
+
// [
|
|
220
|
+
// 155, 29, 235, 77, 59, 125, 75, 173,
|
|
221
|
+
// 155, 221, 43, 13, 123, 61, 203, 109,
|
|
222
|
+
// 27, 157, 107, 205, 187, 253, 75, 45,
|
|
223
|
+
// 155, 93, 171, 141, 251, 189, 75, 237
|
|
224
|
+
// ]
|
|
242
225
|
|
|
243
226
|
```
|
|
244
227
|
|
package/lib/bytesToUuid.js
CHANGED
|
@@ -10,14 +10,17 @@ for (var i = 0; i < 256; ++i) {
|
|
|
10
10
|
function bytesToUuid(buf, offset) {
|
|
11
11
|
var i = offset || 0;
|
|
12
12
|
var bth = byteToHex;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
// join used to fix memory issue caused by concatenation: https://bugs.chromium.org/p/v8/issues/detail?id=3175#c4
|
|
14
|
+
return ([
|
|
15
|
+
bth[buf[i++]], bth[buf[i++]],
|
|
16
|
+
bth[buf[i++]], bth[buf[i++]], '-',
|
|
17
|
+
bth[buf[i++]], bth[buf[i++]], '-',
|
|
18
|
+
bth[buf[i++]], bth[buf[i++]], '-',
|
|
19
|
+
bth[buf[i++]], bth[buf[i++]], '-',
|
|
20
|
+
bth[buf[i++]], bth[buf[i++]],
|
|
21
|
+
bth[buf[i++]], bth[buf[i++]],
|
|
22
|
+
bth[buf[i++]], bth[buf[i++]]
|
|
23
|
+
]).join('');
|
|
21
24
|
}
|
|
22
25
|
|
|
23
26
|
module.exports = bytesToUuid;
|
package/lib/rng-browser.js
CHANGED
|
@@ -3,9 +3,11 @@
|
|
|
3
3
|
// and inconsistent support for the `crypto` API. We do the best we can via
|
|
4
4
|
// feature-detection
|
|
5
5
|
|
|
6
|
-
// getRandomValues needs to be invoked in a context where "this" is a Crypto
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
// getRandomValues needs to be invoked in a context where "this" is a Crypto
|
|
7
|
+
// implementation. Also, find the complete implementation of crypto on IE11.
|
|
8
|
+
var getRandomValues = (typeof(crypto) != 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto)) ||
|
|
9
|
+
(typeof(msCrypto) != 'undefined' && typeof window.msCrypto.getRandomValues == 'function' && msCrypto.getRandomValues.bind(msCrypto));
|
|
10
|
+
|
|
9
11
|
if (getRandomValues) {
|
|
10
12
|
// WHATWG crypto RNG - http://wiki.whatwg.org/wiki/Crypto
|
|
11
13
|
var rnds8 = new Uint8Array(16); // eslint-disable-line no-undef
|
package/lib/v35.js
CHANGED
|
@@ -43,7 +43,11 @@ module.exports = function(name, version, hashfunc) {
|
|
|
43
43
|
return buf || bytesToUuid(bytes);
|
|
44
44
|
};
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
// Function#name is not settable on some platforms (#270)
|
|
47
|
+
try {
|
|
48
|
+
generateUUID.name = name;
|
|
49
|
+
} catch (err) {
|
|
50
|
+
}
|
|
47
51
|
|
|
48
52
|
// Pre-defined namespaces, per Appendix C
|
|
49
53
|
generateUUID.DNS = '6ba7b810-9dad-11d1-80b4-00c04fd430c8';
|
package/package.json
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "uuid",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0",
|
|
4
4
|
"description": "RFC4122 (v1, v4, and v5) UUIDs",
|
|
5
|
+
"commitlint": {
|
|
6
|
+
"extends": [
|
|
7
|
+
"@commitlint/config-conventional"
|
|
8
|
+
]
|
|
9
|
+
},
|
|
5
10
|
"keywords": [
|
|
6
11
|
"uuid",
|
|
7
12
|
"guid",
|
|
@@ -12,13 +17,17 @@
|
|
|
12
17
|
"uuid": "./bin/uuid"
|
|
13
18
|
},
|
|
14
19
|
"devDependencies": {
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
20
|
+
"@commitlint/cli": "~8.2.0",
|
|
21
|
+
"@commitlint/config-conventional": "~8.2.0",
|
|
22
|
+
"eslint": "~6.4.0",
|
|
23
|
+
"husky": "~3.0.5",
|
|
24
|
+
"mocha": "6.2.0",
|
|
25
|
+
"runmd": "1.2.1",
|
|
26
|
+
"standard-version": "7.0.0"
|
|
19
27
|
},
|
|
20
28
|
"scripts": {
|
|
21
|
-
"
|
|
29
|
+
"lint": "eslint .",
|
|
30
|
+
"test": "npm run lint && mocha test/test.js",
|
|
22
31
|
"md": "runmd --watch --output=README.md README_js.md",
|
|
23
32
|
"release": "standard-version",
|
|
24
33
|
"prepare": "runmd --output=README.md README_js.md"
|
|
@@ -30,7 +39,11 @@
|
|
|
30
39
|
},
|
|
31
40
|
"repository": {
|
|
32
41
|
"type": "git",
|
|
33
|
-
"url": "https://github.com/
|
|
42
|
+
"url": "https://github.com/uuidjs/uuid.git"
|
|
34
43
|
},
|
|
35
|
-
"
|
|
44
|
+
"husky": {
|
|
45
|
+
"hooks": {
|
|
46
|
+
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
|
|
47
|
+
}
|
|
48
|
+
}
|
|
36
49
|
}
|
package/v1.js
CHANGED
|
@@ -13,7 +13,7 @@ var _clockseq;
|
|
|
13
13
|
var _lastMSecs = 0;
|
|
14
14
|
var _lastNSecs = 0;
|
|
15
15
|
|
|
16
|
-
// See https://github.com/
|
|
16
|
+
// See https://github.com/uuidjs/uuid for API details
|
|
17
17
|
function v1(options, buf, offset) {
|
|
18
18
|
var i = buf && offset || 0;
|
|
19
19
|
var b = buf || [];
|
package/.eslintrc.json
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"root": true,
|
|
3
|
-
"env": {
|
|
4
|
-
"browser": true,
|
|
5
|
-
"commonjs": true,
|
|
6
|
-
"node": true,
|
|
7
|
-
"mocha": true
|
|
8
|
-
},
|
|
9
|
-
"extends": ["eslint:recommended"],
|
|
10
|
-
"rules": {
|
|
11
|
-
"array-bracket-spacing": ["warn", "never"],
|
|
12
|
-
"arrow-body-style": ["warn", "as-needed"],
|
|
13
|
-
"arrow-parens": ["warn", "as-needed"],
|
|
14
|
-
"arrow-spacing": "warn",
|
|
15
|
-
"brace-style": ["warn", "1tbs"],
|
|
16
|
-
"camelcase": "warn",
|
|
17
|
-
"comma-spacing": ["warn", {"after": true}],
|
|
18
|
-
"dot-notation": "warn",
|
|
19
|
-
"eqeqeq": ["warn", "smart"],
|
|
20
|
-
"indent": ["warn", 2, {
|
|
21
|
-
"SwitchCase": 1,
|
|
22
|
-
"FunctionDeclaration": {"parameters": 1},
|
|
23
|
-
"MemberExpression": 1,
|
|
24
|
-
"CallExpression": {"arguments": 1}
|
|
25
|
-
}],
|
|
26
|
-
"key-spacing": ["warn", {"beforeColon": false, "afterColon": true, "mode": "minimum"}],
|
|
27
|
-
"keyword-spacing": "warn",
|
|
28
|
-
"no-console": "off",
|
|
29
|
-
"no-empty": "off",
|
|
30
|
-
"no-multi-spaces": "warn",
|
|
31
|
-
"no-redeclare": "off",
|
|
32
|
-
"no-restricted-globals": ["warn", "Promise"],
|
|
33
|
-
"no-trailing-spaces": "warn",
|
|
34
|
-
"no-undef": "error",
|
|
35
|
-
"no-unused-vars": ["warn", {"args": "none"}],
|
|
36
|
-
"one-var": ["warn", "never"],
|
|
37
|
-
"padded-blocks": ["warn", "never"],
|
|
38
|
-
"object-curly-spacing": ["warn", "never"],
|
|
39
|
-
"quotes": ["warn", "single"],
|
|
40
|
-
"react/prop-types": "off",
|
|
41
|
-
"react/jsx-no-bind": "off",
|
|
42
|
-
"semi": ["warn", "always"],
|
|
43
|
-
"space-before-blocks": ["warn", "always"],
|
|
44
|
-
"space-before-function-paren": ["warn", "never"],
|
|
45
|
-
"space-in-parens": ["warn", "never"]
|
|
46
|
-
}
|
|
47
|
-
}
|
package/README_js.md
DELETED
|
@@ -1,280 +0,0 @@
|
|
|
1
|
-
```javascript --hide
|
|
2
|
-
runmd.onRequire = path => path.replace(/^uuid/, './');
|
|
3
|
-
```
|
|
4
|
-
|
|
5
|
-
# uuid [](http://travis-ci.org/kelektiv/node-uuid) #
|
|
6
|
-
|
|
7
|
-
Simple, fast generation of [RFC4122](http://www.ietf.org/rfc/rfc4122.txt) UUIDS.
|
|
8
|
-
|
|
9
|
-
Features:
|
|
10
|
-
|
|
11
|
-
* Support for version 1, 3, 4 and 5 UUIDs
|
|
12
|
-
* Cross-platform
|
|
13
|
-
* Uses cryptographically-strong random number APIs (when available)
|
|
14
|
-
* Zero-dependency, small footprint (... but not [this small](https://gist.github.com/982883))
|
|
15
|
-
|
|
16
|
-
[**Deprecation warning**: The use of `require('uuid')` is deprecated and will not be
|
|
17
|
-
supported after version 3.x of this module. Instead, use `require('uuid/[v1|v3|v4|v5]')` as shown in the examples below.]
|
|
18
|
-
|
|
19
|
-
## Quickstart - CommonJS (Recommended)
|
|
20
|
-
|
|
21
|
-
```shell
|
|
22
|
-
npm install uuid
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
Then generate your uuid version of choice ...
|
|
26
|
-
|
|
27
|
-
Version 1 (timestamp):
|
|
28
|
-
|
|
29
|
-
```javascript --run v1
|
|
30
|
-
const uuidv1 = require('uuid/v1');
|
|
31
|
-
uuidv1(); // RESULT
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
Version 3 (namespace):
|
|
35
|
-
|
|
36
|
-
```javascript --run v3
|
|
37
|
-
const uuidv3 = require('uuid/v3');
|
|
38
|
-
|
|
39
|
-
// ... using predefined DNS namespace (for domain names)
|
|
40
|
-
uuidv3('hello.example.com', uuidv3.DNS); // RESULT
|
|
41
|
-
|
|
42
|
-
// ... using predefined URL namespace (for, well, URLs)
|
|
43
|
-
uuidv3('http://example.com/hello', uuidv3.URL); // RESULT
|
|
44
|
-
|
|
45
|
-
// ... using a custom namespace
|
|
46
|
-
//
|
|
47
|
-
// Note: Custom namespaces should be a UUID string specific to your application!
|
|
48
|
-
// E.g. the one here was generated using this modules `uuid` CLI.
|
|
49
|
-
const MY_NAMESPACE = '1b671a64-40d5-491e-99b0-da01ff1f3341';
|
|
50
|
-
uuidv3('Hello, World!', MY_NAMESPACE); // RESULT
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
Version 4 (random):
|
|
54
|
-
|
|
55
|
-
```javascript --run v4
|
|
56
|
-
const uuidv4 = require('uuid/v4');
|
|
57
|
-
uuidv4(); // RESULT
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
Version 5 (namespace):
|
|
61
|
-
|
|
62
|
-
```javascript --run v5
|
|
63
|
-
const uuidv5 = require('uuid/v5');
|
|
64
|
-
|
|
65
|
-
// ... using predefined DNS namespace (for domain names)
|
|
66
|
-
uuidv5('hello.example.com', uuidv5.DNS); // RESULT
|
|
67
|
-
|
|
68
|
-
// ... using predefined URL namespace (for, well, URLs)
|
|
69
|
-
uuidv5('http://example.com/hello', uuidv5.URL); // RESULT
|
|
70
|
-
|
|
71
|
-
// ... using a custom namespace
|
|
72
|
-
//
|
|
73
|
-
// Note: Custom namespaces should be a UUID string specific to your application!
|
|
74
|
-
// E.g. the one here was generated using this modules `uuid` CLI.
|
|
75
|
-
const MY_NAMESPACE = '1b671a64-40d5-491e-99b0-da01ff1f3341';
|
|
76
|
-
uuidv5('Hello, World!', MY_NAMESPACE); // RESULT
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
## Quickstart - Browser-ready Versions
|
|
80
|
-
|
|
81
|
-
Browser-ready versions of this module are available via [wzrd.in](https://github.com/jfhbrook/wzrd.in).
|
|
82
|
-
|
|
83
|
-
For version 1 uuids:
|
|
84
|
-
|
|
85
|
-
```html
|
|
86
|
-
<script src="http://wzrd.in/standalone/uuid%2Fv1@latest"></script>
|
|
87
|
-
<script>
|
|
88
|
-
uuidv1(); // -> v1 UUID
|
|
89
|
-
</script>
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
For version 3 uuids:
|
|
93
|
-
|
|
94
|
-
```html
|
|
95
|
-
<script src="http://wzrd.in/standalone/uuid%2Fv3@latest"></script>
|
|
96
|
-
<script>
|
|
97
|
-
uuidv3('http://example.com/hello', uuidv3.URL); // -> v3 UUID
|
|
98
|
-
</script>
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
For version 4 uuids:
|
|
102
|
-
|
|
103
|
-
```html
|
|
104
|
-
<script src="http://wzrd.in/standalone/uuid%2Fv4@latest"></script>
|
|
105
|
-
<script>
|
|
106
|
-
uuidv4(); // -> v4 UUID
|
|
107
|
-
</script>
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
For version 5 uuids:
|
|
111
|
-
|
|
112
|
-
```html
|
|
113
|
-
<script src="http://wzrd.in/standalone/uuid%2Fv5@latest"></script>
|
|
114
|
-
<script>
|
|
115
|
-
uuidv5('http://example.com/hello', uuidv5.URL); // -> v5 UUID
|
|
116
|
-
</script>
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
## API
|
|
120
|
-
|
|
121
|
-
### Version 1
|
|
122
|
-
|
|
123
|
-
```javascript
|
|
124
|
-
const uuidv1 = require('uuid/v1');
|
|
125
|
-
|
|
126
|
-
// Incantations
|
|
127
|
-
uuidv1();
|
|
128
|
-
uuidv1(options);
|
|
129
|
-
uuidv1(options, buffer, offset);
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
Generate and return a RFC4122 v1 (timestamp-based) UUID.
|
|
133
|
-
|
|
134
|
-
* `options` - (Object) Optional uuid state to apply. Properties may include:
|
|
135
|
-
|
|
136
|
-
* `node` - (Array) Node id as Array of 6 bytes (per 4.1.6). Default: Randomly generated ID. See note 1.
|
|
137
|
-
* `clockseq` - (Number between 0 - 0x3fff) RFC clock sequence. Default: An internally maintained clockseq is used.
|
|
138
|
-
* `msecs` - (Number) Time in milliseconds since unix Epoch. Default: The current time is used.
|
|
139
|
-
* `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.
|
|
140
|
-
|
|
141
|
-
* `buffer` - (Array | Buffer) Array or buffer where UUID bytes are to be written.
|
|
142
|
-
* `offset` - (Number) Starting index in `buffer` at which to begin writing.
|
|
143
|
-
|
|
144
|
-
Returns `buffer`, if specified, otherwise the string form of the UUID
|
|
145
|
-
|
|
146
|
-
Note: The <node> id is generated guaranteed to stay constant for the lifetime of the current JS runtime. (Future versions of this module may use persistent storage mechanisms to extend this guarantee.)
|
|
147
|
-
|
|
148
|
-
Example: Generate string UUID with fully-specified options
|
|
149
|
-
|
|
150
|
-
```javascript --run v1
|
|
151
|
-
const v1options = {
|
|
152
|
-
node: [0x01, 0x23, 0x45, 0x67, 0x89, 0xab],
|
|
153
|
-
clockseq: 0x1234,
|
|
154
|
-
msecs: new Date('2011-11-01').getTime(),
|
|
155
|
-
nsecs: 5678
|
|
156
|
-
};
|
|
157
|
-
uuidv1(v1options); // RESULT
|
|
158
|
-
```
|
|
159
|
-
|
|
160
|
-
Example: In-place generation of two binary IDs
|
|
161
|
-
|
|
162
|
-
```javascript --run v1
|
|
163
|
-
// Generate two ids in an array
|
|
164
|
-
const arr = new Array();
|
|
165
|
-
uuidv1(null, arr, 0); // RESULT
|
|
166
|
-
uuidv1(null, arr, 16); // RESULT
|
|
167
|
-
```
|
|
168
|
-
|
|
169
|
-
### Version 3
|
|
170
|
-
|
|
171
|
-
```javascript
|
|
172
|
-
const uuidv3 = require('uuid/v3');
|
|
173
|
-
|
|
174
|
-
// Incantations
|
|
175
|
-
uuidv3(name, namespace);
|
|
176
|
-
uuidv3(name, namespace, buffer);
|
|
177
|
-
uuidv3(name, namespace, buffer, offset);
|
|
178
|
-
```
|
|
179
|
-
|
|
180
|
-
Generate and return a RFC4122 v3 UUID.
|
|
181
|
-
|
|
182
|
-
* `name` - (String | Array[]) "name" to create UUID with
|
|
183
|
-
* `namespace` - (String | Array[]) "namespace" UUID either as a String or Array[16] of byte values
|
|
184
|
-
* `buffer` - (Array | Buffer) Array or buffer where UUID bytes are to be written.
|
|
185
|
-
* `offset` - (Number) Starting index in `buffer` at which to begin writing. Default = 0
|
|
186
|
-
|
|
187
|
-
Returns `buffer`, if specified, otherwise the string form of the UUID
|
|
188
|
-
|
|
189
|
-
Example:
|
|
190
|
-
|
|
191
|
-
```javascript --run v3
|
|
192
|
-
uuidv3('hello world', MY_NAMESPACE); // RESULT
|
|
193
|
-
```
|
|
194
|
-
|
|
195
|
-
### Version 4
|
|
196
|
-
|
|
197
|
-
```javascript
|
|
198
|
-
const uuidv4 = require('uuid/v4')
|
|
199
|
-
|
|
200
|
-
// Incantations
|
|
201
|
-
uuidv4();
|
|
202
|
-
uuidv4(options);
|
|
203
|
-
uuidv4(options, buffer, offset);
|
|
204
|
-
```
|
|
205
|
-
|
|
206
|
-
Generate and return a RFC4122 v4 UUID.
|
|
207
|
-
|
|
208
|
-
* `options` - (Object) Optional uuid state to apply. Properties may include:
|
|
209
|
-
* `random` - (Number[16]) Array of 16 numbers (0-255) to use in place of randomly generated values
|
|
210
|
-
* `rng` - (Function) Random # generator function that returns an Array[16] of byte values (0-255)
|
|
211
|
-
* `buffer` - (Array | Buffer) Array or buffer where UUID bytes are to be written.
|
|
212
|
-
* `offset` - (Number) Starting index in `buffer` at which to begin writing.
|
|
213
|
-
|
|
214
|
-
Returns `buffer`, if specified, otherwise the string form of the UUID
|
|
215
|
-
|
|
216
|
-
Example: Generate string UUID with predefined `random` values
|
|
217
|
-
|
|
218
|
-
```javascript --run v4
|
|
219
|
-
const v4options = {
|
|
220
|
-
random: [
|
|
221
|
-
0x10, 0x91, 0x56, 0xbe, 0xc4, 0xfb, 0xc1, 0xea,
|
|
222
|
-
0x71, 0xb4, 0xef, 0xe1, 0x67, 0x1c, 0x58, 0x36
|
|
223
|
-
]
|
|
224
|
-
};
|
|
225
|
-
uuidv4(v4options); // RESULT
|
|
226
|
-
```
|
|
227
|
-
|
|
228
|
-
Example: Generate two IDs in a single buffer
|
|
229
|
-
|
|
230
|
-
```javascript --run v4
|
|
231
|
-
const buffer = new Array();
|
|
232
|
-
uuidv4(null, buffer, 0); // RESULT
|
|
233
|
-
uuidv4(null, buffer, 16); // RESULT
|
|
234
|
-
```
|
|
235
|
-
|
|
236
|
-
### Version 5
|
|
237
|
-
|
|
238
|
-
```javascript
|
|
239
|
-
const uuidv5 = require('uuid/v5');
|
|
240
|
-
|
|
241
|
-
// Incantations
|
|
242
|
-
uuidv5(name, namespace);
|
|
243
|
-
uuidv5(name, namespace, buffer);
|
|
244
|
-
uuidv5(name, namespace, buffer, offset);
|
|
245
|
-
```
|
|
246
|
-
|
|
247
|
-
Generate and return a RFC4122 v5 UUID.
|
|
248
|
-
|
|
249
|
-
* `name` - (String | Array[]) "name" to create UUID with
|
|
250
|
-
* `namespace` - (String | Array[]) "namespace" UUID either as a String or Array[16] of byte values
|
|
251
|
-
* `buffer` - (Array | Buffer) Array or buffer where UUID bytes are to be written.
|
|
252
|
-
* `offset` - (Number) Starting index in `buffer` at which to begin writing. Default = 0
|
|
253
|
-
|
|
254
|
-
Returns `buffer`, if specified, otherwise the string form of the UUID
|
|
255
|
-
|
|
256
|
-
Example:
|
|
257
|
-
|
|
258
|
-
```javascript --run v5
|
|
259
|
-
uuidv5('hello world', MY_NAMESPACE); // RESULT
|
|
260
|
-
```
|
|
261
|
-
|
|
262
|
-
## Command Line
|
|
263
|
-
|
|
264
|
-
UUIDs can be generated from the command line with the `uuid` command.
|
|
265
|
-
|
|
266
|
-
```shell
|
|
267
|
-
$ uuid
|
|
268
|
-
ddeb27fb-d9a0-4624-be4d-4615062daed4
|
|
269
|
-
|
|
270
|
-
$ uuid v1
|
|
271
|
-
02d37060-d446-11e7-a9fa-7bdae751ebe1
|
|
272
|
-
```
|
|
273
|
-
|
|
274
|
-
Type `uuid --help` for usage details
|
|
275
|
-
|
|
276
|
-
## Testing
|
|
277
|
-
|
|
278
|
-
```shell
|
|
279
|
-
npm test
|
|
280
|
-
```
|