uuid 3.0.1 → 3.3.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/.eslintrc.json +47 -0
- package/CHANGELOG.md +99 -0
- package/README.md +203 -42
- package/README_js.md +280 -0
- package/bin/uuid +56 -17
- package/lib/bytesToUuid.js +10 -9
- package/lib/md5-browser.js +216 -0
- package/lib/md5.js +25 -0
- package/lib/rng-browser.js +14 -13
- package/lib/rng.js +4 -6
- package/lib/sha1-browser.js +89 -0
- package/lib/sha1.js +25 -0
- package/lib/v35.js +56 -0
- package/package.json +23 -6
- package/v1.js +23 -17
- package/v3.js +4 -0
- package/v4.js +1 -1
- package/v5.js +3 -0
- package/.npmignore +0 -8
- package/.travis.yml +0 -5
- package/HISTORY.md +0 -28
- package/test/mocha.opts +0 -3
- package/test/test.js +0 -96
package/.eslintrc.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
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/CHANGELOG.md
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
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
|
+
|
|
5
|
+
<a name="3.3.0"></a>
|
|
6
|
+
# [3.3.0](https://github.com/kelektiv/node-uuid/compare/v3.2.1...v3.3.0) (2018-06-22)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* assignment to readonly property to allow running in strict mode ([#270](https://github.com/kelektiv/node-uuid/issues/270)) ([d062fdc](https://github.com/kelektiv/node-uuid/commit/d062fdc))
|
|
12
|
+
* fix [#229](https://github.com/kelektiv/node-uuid/issues/229) ([c9684d4](https://github.com/kelektiv/node-uuid/commit/c9684d4))
|
|
13
|
+
* Get correct version of IE11 crypto ([#274](https://github.com/kelektiv/node-uuid/issues/274)) ([153d331](https://github.com/kelektiv/node-uuid/commit/153d331))
|
|
14
|
+
* mem issue when generating uuid ([#267](https://github.com/kelektiv/node-uuid/issues/267)) ([c47702c](https://github.com/kelektiv/node-uuid/commit/c47702c))
|
|
15
|
+
|
|
16
|
+
### Features
|
|
17
|
+
|
|
18
|
+
* enforce Conventional Commit style commit messages ([#282](https://github.com/kelektiv/node-uuid/issues/282)) ([cc9a182](https://github.com/kelektiv/node-uuid/commit/cc9a182))
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
<a name="3.2.1"></a>
|
|
22
|
+
## [3.2.1](https://github.com/kelektiv/node-uuid/compare/v3.2.0...v3.2.1) (2018-01-16)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Bug Fixes
|
|
26
|
+
|
|
27
|
+
* assignment to readonly property to allow running in strict mode ([#270](https://github.com/kelektiv/node-uuid/issues/270)) ([d062fdc](https://github.com/kelektiv/node-uuid/commit/d062fdc))
|
|
28
|
+
* fix [#229](https://github.com/kelektiv/node-uuid/issues/229) ([c9684d4](https://github.com/kelektiv/node-uuid/commit/c9684d4))
|
|
29
|
+
* Get correct version of IE11 crypto ([#274](https://github.com/kelektiv/node-uuid/issues/274)) ([153d331](https://github.com/kelektiv/node-uuid/commit/153d331))
|
|
30
|
+
* mem issue when generating uuid ([#267](https://github.com/kelektiv/node-uuid/issues/267)) ([c47702c](https://github.com/kelektiv/node-uuid/commit/c47702c))
|
|
31
|
+
* use msCrypto if available. Fixes [#241](https://github.com/kelektiv/node-uuid/issues/241) ([#247](https://github.com/kelektiv/node-uuid/issues/247)) ([1fef18b](https://github.com/kelektiv/node-uuid/commit/1fef18b))
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
### Features
|
|
35
|
+
|
|
36
|
+
* enforce Conventional Commit style commit messages ([#282](https://github.com/kelektiv/node-uuid/issues/282)) ([cc9a182](https://github.com/kelektiv/node-uuid/commit/cc9a182))
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
<a name="3.2.0"></a>
|
|
41
|
+
# [3.2.0](https://github.com/kelektiv/node-uuid/compare/v3.1.0...v3.2.0) (2018-01-16)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
### Bug Fixes
|
|
45
|
+
|
|
46
|
+
* remove mistakenly added typescript dependency, rollback version (standard-version will auto-increment) ([09fa824](https://github.com/kelektiv/node-uuid/commit/09fa824))
|
|
47
|
+
* use msCrypto if available. Fixes [#241](https://github.com/kelektiv/node-uuid/issues/241) ([#247](https://github.com/kelektiv/node-uuid/issues/247)) ([1fef18b](https://github.com/kelektiv/node-uuid/commit/1fef18b))
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
### Features
|
|
51
|
+
|
|
52
|
+
* Add v3 Support ([#217](https://github.com/kelektiv/node-uuid/issues/217)) ([d94f726](https://github.com/kelektiv/node-uuid/commit/d94f726))
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
# [3.1.0](https://github.com/kelektiv/node-uuid/compare/v3.1.0...v3.0.1) (2017-06-17)
|
|
56
|
+
|
|
57
|
+
### Bug Fixes
|
|
58
|
+
|
|
59
|
+
* (fix) Add .npmignore file to exclude test/ and other non-essential files from packing. (#183)
|
|
60
|
+
* Fix typo (#178)
|
|
61
|
+
* Simple typo fix (#165)
|
|
62
|
+
|
|
63
|
+
### Features
|
|
64
|
+
* v5 support in CLI (#197)
|
|
65
|
+
* V5 support (#188)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
# 3.0.1 (2016-11-28)
|
|
69
|
+
|
|
70
|
+
* split uuid versions into separate files
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
# 3.0.0 (2016-11-17)
|
|
74
|
+
|
|
75
|
+
* remove .parse and .unparse
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
# 2.0.0
|
|
79
|
+
|
|
80
|
+
* Removed uuid.BufferClass
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
# 1.4.0
|
|
84
|
+
|
|
85
|
+
* Improved module context detection
|
|
86
|
+
* Removed public RNG functions
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
# 1.3.2
|
|
90
|
+
|
|
91
|
+
* Improve tests and handling of v1() options (Issue #24)
|
|
92
|
+
* Expose RNG option to allow for perf testing with different generators
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
# 1.3.0
|
|
96
|
+
|
|
97
|
+
* Support for version 1 ids, thanks to [@ctavan](https://github.com/ctavan)!
|
|
98
|
+
* Support for node.js crypto API
|
|
99
|
+
* De-emphasizing performance in favor of a) cryptographic quality PRNGs where available and b) more manageable code
|
package/README.md
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
-- This file is auto-generated from README_js.md. Changes should be made there.
|
|
3
|
+
-->
|
|
4
|
+
|
|
1
5
|
# uuid [](http://travis-ci.org/kelektiv/node-uuid) #
|
|
2
6
|
|
|
3
7
|
Simple, fast generation of [RFC4122](http://www.ietf.org/rfc/rfc4122.txt) UUIDS.
|
|
4
8
|
|
|
5
9
|
Features:
|
|
6
10
|
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
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.]
|
|
11
18
|
|
|
12
19
|
## Quickstart - CommonJS (Recommended)
|
|
13
20
|
|
|
@@ -15,39 +22,116 @@ Features:
|
|
|
15
22
|
npm install uuid
|
|
16
23
|
```
|
|
17
24
|
|
|
25
|
+
Then generate your uuid version of choice ...
|
|
26
|
+
|
|
27
|
+
Version 1 (timestamp):
|
|
28
|
+
|
|
29
|
+
```javascript
|
|
30
|
+
const uuidv1 = require('uuid/v1');
|
|
31
|
+
uuidv1(); // ⇨ '22643650-7944-11e8-8ca7-93cbb72bf7b7'
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Version 3 (namespace):
|
|
36
|
+
|
|
37
|
+
```javascript
|
|
38
|
+
const uuidv3 = require('uuid/v3');
|
|
39
|
+
|
|
40
|
+
// ... using predefined DNS namespace (for domain names)
|
|
41
|
+
uuidv3('hello.example.com', uuidv3.DNS); // ⇨ '9125a8dc-52ee-365b-a5aa-81b0b3681cf6'
|
|
42
|
+
|
|
43
|
+
// ... using predefined URL namespace (for, well, URLs)
|
|
44
|
+
uuidv3('http://example.com/hello', uuidv3.URL); // ⇨ 'c6235813-3ba4-3801-ae84-e0a6ebb7d138'
|
|
45
|
+
|
|
46
|
+
// ... using a custom namespace
|
|
47
|
+
//
|
|
48
|
+
// Note: Custom namespaces should be a UUID string specific to your application!
|
|
49
|
+
// E.g. the one here was generated using this modules `uuid` CLI.
|
|
50
|
+
const MY_NAMESPACE = '1b671a64-40d5-491e-99b0-da01ff1f3341';
|
|
51
|
+
uuidv3('Hello, World!', MY_NAMESPACE); // ⇨ 'e8b5a51d-11c8-3310-a6ab-367563f20686'
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Version 4 (random):
|
|
56
|
+
|
|
57
|
+
```javascript
|
|
58
|
+
const uuidv4 = require('uuid/v4');
|
|
59
|
+
uuidv4(); // ⇨ '7afe74af-5a7d-4a4e-a3c1-ebe44f564695'
|
|
60
|
+
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Version 5 (namespace):
|
|
64
|
+
|
|
18
65
|
```javascript
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
66
|
+
const uuidv5 = require('uuid/v5');
|
|
67
|
+
|
|
68
|
+
// ... using predefined DNS namespace (for domain names)
|
|
69
|
+
uuidv5('hello.example.com', uuidv5.DNS); // ⇨ 'fdda765f-fc57-5604-a269-52a7df8164ec'
|
|
70
|
+
|
|
71
|
+
// ... using predefined URL namespace (for, well, URLs)
|
|
72
|
+
uuidv5('http://example.com/hello', uuidv5.URL); // ⇨ '3bbcee75-cecc-5b56-8031-b6641c1ed1f1'
|
|
73
|
+
|
|
74
|
+
// ... using a custom namespace
|
|
75
|
+
//
|
|
76
|
+
// Note: Custom namespaces should be a UUID string specific to your application!
|
|
77
|
+
// E.g. the one here was generated using this modules `uuid` CLI.
|
|
78
|
+
const MY_NAMESPACE = '1b671a64-40d5-491e-99b0-da01ff1f3341';
|
|
79
|
+
uuidv5('Hello, World!', MY_NAMESPACE); // ⇨ '630eb68f-e0fa-5ecc-887a-7c7a62614681'
|
|
22
80
|
|
|
23
|
-
// Generate a v4 UUID (random)
|
|
24
|
-
const uuidV4 = require('uuid/v4');
|
|
25
|
-
uuidV4(); // -> '110ec58a-a0f2-4ac4-8393-c866d813b8d1'
|
|
26
81
|
```
|
|
27
82
|
|
|
28
|
-
## Quickstart -
|
|
83
|
+
## Quickstart - Browser-ready Versions
|
|
29
84
|
|
|
30
85
|
Browser-ready versions of this module are available via [wzrd.in](https://github.com/jfhbrook/wzrd.in).
|
|
31
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
|
+
|
|
32
98
|
```html
|
|
33
|
-
<script src="http://wzrd.in/standalone/uuid@latest"></script>
|
|
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:
|
|
34
106
|
|
|
107
|
+
```html
|
|
108
|
+
<script src="http://wzrd.in/standalone/uuid%2Fv4@latest"></script>
|
|
35
109
|
<script>
|
|
36
|
-
|
|
37
|
-
uuid.v4(); // -> v4 UUID
|
|
110
|
+
uuidv4(); // -> v4 UUID
|
|
38
111
|
</script>
|
|
39
112
|
```
|
|
40
113
|
|
|
41
|
-
|
|
114
|
+
For version 5 uuids:
|
|
42
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
|
+
```
|
|
43
122
|
|
|
44
123
|
## API
|
|
45
124
|
|
|
46
|
-
###
|
|
125
|
+
### Version 1
|
|
47
126
|
|
|
48
|
-
|
|
127
|
+
```javascript
|
|
128
|
+
const uuidv1 = require('uuid/v1');
|
|
49
129
|
|
|
50
|
-
|
|
130
|
+
// Incantations
|
|
131
|
+
uuidv1();
|
|
132
|
+
uuidv1(options);
|
|
133
|
+
uuidv1(options, buffer, offset);
|
|
134
|
+
```
|
|
51
135
|
|
|
52
136
|
Generate and return a RFC4122 v1 (timestamp-based) UUID.
|
|
53
137
|
|
|
@@ -55,7 +139,7 @@ Generate and return a RFC4122 v1 (timestamp-based) UUID.
|
|
|
55
139
|
|
|
56
140
|
* `node` - (Array) Node id as Array of 6 bytes (per 4.1.6). Default: Randomly generated ID. See note 1.
|
|
57
141
|
* `clockseq` - (Number between 0 - 0x3fff) RFC clock sequence. Default: An internally maintained clockseq is used.
|
|
58
|
-
* `msecs` - (Number
|
|
142
|
+
* `msecs` - (Number) Time in milliseconds since unix Epoch. Default: The current time is used.
|
|
59
143
|
* `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.
|
|
60
144
|
|
|
61
145
|
* `buffer` - (Array | Buffer) Array or buffer where UUID bytes are to be written.
|
|
@@ -63,70 +147,147 @@ Generate and return a RFC4122 v1 (timestamp-based) UUID.
|
|
|
63
147
|
|
|
64
148
|
Returns `buffer`, if specified, otherwise the string form of the UUID
|
|
65
149
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
1. The randomly generated node id is only 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.)
|
|
150
|
+
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.)
|
|
69
151
|
|
|
70
152
|
Example: Generate string UUID with fully-specified options
|
|
71
153
|
|
|
72
154
|
```javascript
|
|
73
|
-
|
|
155
|
+
const v1options = {
|
|
74
156
|
node: [0x01, 0x23, 0x45, 0x67, 0x89, 0xab],
|
|
75
157
|
clockseq: 0x1234,
|
|
76
158
|
msecs: new Date('2011-11-01').getTime(),
|
|
77
159
|
nsecs: 5678
|
|
78
|
-
}
|
|
160
|
+
};
|
|
161
|
+
uuidv1(v1options); // ⇨ '710b962e-041c-11e1-9234-0123456789ab'
|
|
162
|
+
|
|
79
163
|
```
|
|
80
164
|
|
|
81
165
|
Example: In-place generation of two binary IDs
|
|
82
166
|
|
|
83
167
|
```javascript
|
|
84
168
|
// Generate two ids in an array
|
|
85
|
-
const arr = new Array(
|
|
86
|
-
|
|
87
|
-
|
|
169
|
+
const arr = new Array();
|
|
170
|
+
uuidv1(null, arr, 0); // ⇨ [ 34, 101, 32, 176, 121, 68, 17, 232, 146, 52, 147, 203, 183, 43, 247, 183 ]
|
|
171
|
+
uuidv1(null, arr, 16); // ⇨ [ 34, 101, 32, 176, 121, 68, 17, 232, 146, 52, 147, 203, 183, 43, 247, 183, 34, 101, 71, 192, 121, 68, 17, 232, 146, 52, 147, 203, 183, 43, 247, 183 ]
|
|
172
|
+
|
|
88
173
|
```
|
|
89
174
|
|
|
90
|
-
###
|
|
175
|
+
### Version 3
|
|
176
|
+
|
|
177
|
+
```javascript
|
|
178
|
+
const uuidv3 = require('uuid/v3');
|
|
179
|
+
|
|
180
|
+
// Incantations
|
|
181
|
+
uuidv3(name, namespace);
|
|
182
|
+
uuidv3(name, namespace, buffer);
|
|
183
|
+
uuidv3(name, namespace, buffer, offset);
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
Generate and return a RFC4122 v3 UUID.
|
|
187
|
+
|
|
188
|
+
* `name` - (String | Array[]) "name" to create UUID with
|
|
189
|
+
* `namespace` - (String | Array[]) "namespace" UUID either as a String or Array[16] of byte values
|
|
190
|
+
* `buffer` - (Array | Buffer) Array or buffer where UUID bytes are to be written.
|
|
191
|
+
* `offset` - (Number) Starting index in `buffer` at which to begin writing. Default = 0
|
|
192
|
+
|
|
193
|
+
Returns `buffer`, if specified, otherwise the string form of the UUID
|
|
194
|
+
|
|
195
|
+
Example:
|
|
196
|
+
|
|
197
|
+
```javascript
|
|
198
|
+
uuidv3('hello world', MY_NAMESPACE); // ⇨ '042ffd34-d989-321c-ad06-f60826172424'
|
|
199
|
+
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### Version 4
|
|
203
|
+
|
|
204
|
+
```javascript
|
|
205
|
+
const uuidv4 = require('uuid/v4')
|
|
206
|
+
|
|
207
|
+
// Incantations
|
|
208
|
+
uuidv4();
|
|
209
|
+
uuidv4(options);
|
|
210
|
+
uuidv4(options, buffer, offset);
|
|
211
|
+
```
|
|
91
212
|
|
|
92
213
|
Generate and return a RFC4122 v4 UUID.
|
|
93
214
|
|
|
94
215
|
* `options` - (Object) Optional uuid state to apply. Properties may include:
|
|
95
|
-
|
|
96
216
|
* `random` - (Number[16]) Array of 16 numbers (0-255) to use in place of randomly generated values
|
|
97
|
-
* `rng` - (Function) Random # generator
|
|
98
|
-
|
|
217
|
+
* `rng` - (Function) Random # generator function that returns an Array[16] of byte values (0-255)
|
|
99
218
|
* `buffer` - (Array | Buffer) Array or buffer where UUID bytes are to be written.
|
|
100
219
|
* `offset` - (Number) Starting index in `buffer` at which to begin writing.
|
|
101
220
|
|
|
102
221
|
Returns `buffer`, if specified, otherwise the string form of the UUID
|
|
103
222
|
|
|
104
|
-
Example: Generate string UUID with
|
|
223
|
+
Example: Generate string UUID with predefined `random` values
|
|
105
224
|
|
|
106
225
|
```javascript
|
|
107
|
-
|
|
226
|
+
const v4options = {
|
|
108
227
|
random: [
|
|
109
228
|
0x10, 0x91, 0x56, 0xbe, 0xc4, 0xfb, 0xc1, 0xea,
|
|
110
229
|
0x71, 0xb4, 0xef, 0xe1, 0x67, 0x1c, 0x58, 0x36
|
|
111
230
|
]
|
|
112
|
-
}
|
|
113
|
-
//
|
|
231
|
+
};
|
|
232
|
+
uuidv4(v4options); // ⇨ '109156be-c4fb-41ea-b1b4-efe1671c5836'
|
|
233
|
+
|
|
114
234
|
```
|
|
115
235
|
|
|
116
236
|
Example: Generate two IDs in a single buffer
|
|
117
237
|
|
|
118
238
|
```javascript
|
|
119
|
-
const buffer = new Array(
|
|
120
|
-
|
|
121
|
-
|
|
239
|
+
const buffer = new Array();
|
|
240
|
+
uuidv4(null, buffer, 0); // ⇨ [ 99, 19, 185, 60, 95, 165, 69, 65, 170, 166, 39, 0, 243, 153, 94, 148 ]
|
|
241
|
+
uuidv4(null, buffer, 16); // ⇨ [ 99, 19, 185, 60, 95, 165, 69, 65, 170, 166, 39, 0, 243, 153, 94, 148, 208, 145, 176, 198, 100, 47, 65, 92, 182, 96, 194, 143, 212, 122, 218, 15 ]
|
|
242
|
+
|
|
122
243
|
```
|
|
123
244
|
|
|
124
|
-
|
|
245
|
+
### Version 5
|
|
125
246
|
|
|
247
|
+
```javascript
|
|
248
|
+
const uuidv5 = require('uuid/v5');
|
|
249
|
+
|
|
250
|
+
// Incantations
|
|
251
|
+
uuidv5(name, namespace);
|
|
252
|
+
uuidv5(name, namespace, buffer);
|
|
253
|
+
uuidv5(name, namespace, buffer, offset);
|
|
126
254
|
```
|
|
127
|
-
|
|
255
|
+
|
|
256
|
+
Generate and return a RFC4122 v5 UUID.
|
|
257
|
+
|
|
258
|
+
* `name` - (String | Array[]) "name" to create UUID with
|
|
259
|
+
* `namespace` - (String | Array[]) "namespace" UUID either as a String or Array[16] of byte values
|
|
260
|
+
* `buffer` - (Array | Buffer) Array or buffer where UUID bytes are to be written.
|
|
261
|
+
* `offset` - (Number) Starting index in `buffer` at which to begin writing. Default = 0
|
|
262
|
+
|
|
263
|
+
Returns `buffer`, if specified, otherwise the string form of the UUID
|
|
264
|
+
|
|
265
|
+
Example:
|
|
266
|
+
|
|
267
|
+
```javascript
|
|
268
|
+
uuidv5('hello world', MY_NAMESPACE); // ⇨ '9f282611-e0fd-5650-8953-89c8e342da0b'
|
|
269
|
+
|
|
128
270
|
```
|
|
129
271
|
|
|
130
|
-
##
|
|
272
|
+
## Command Line
|
|
273
|
+
|
|
274
|
+
UUIDs can be generated from the command line with the `uuid` command.
|
|
275
|
+
|
|
276
|
+
```shell
|
|
277
|
+
$ uuid
|
|
278
|
+
ddeb27fb-d9a0-4624-be4d-4615062daed4
|
|
279
|
+
|
|
280
|
+
$ uuid v1
|
|
281
|
+
02d37060-d446-11e7-a9fa-7bdae751ebe1
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
Type `uuid --help` for usage details
|
|
285
|
+
|
|
286
|
+
## Testing
|
|
287
|
+
|
|
288
|
+
```shell
|
|
289
|
+
npm test
|
|
290
|
+
```
|
|
131
291
|
|
|
132
|
-
|
|
292
|
+
----
|
|
293
|
+
Markdown generated from [README_js.md](README_js.md) by [](https://github.com/broofa/runmd)
|