uuid 2.0.3 → 3.2.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/AUTHORS +5 -0
- package/CHANGELOG.md +47 -0
- package/LICENSE.md +21 -2
- package/README.md +195 -107
- package/README_js.md +280 -0
- package/bin/uuid +65 -0
- package/index.js +8 -0
- package/lib/bytesToUuid.js +23 -0
- package/lib/md5-browser.js +216 -0
- package/lib/md5.js +25 -0
- package/lib/rng-browser.js +31 -0
- package/lib/rng.js +8 -0
- package/lib/sha1-browser.js +89 -0
- package/lib/sha1.js +25 -0
- package/lib/v35.js +53 -0
- package/package.json +18 -28
- package/v1.js +109 -0
- package/v3.js +4 -0
- package/v4.js +29 -0
- package/v5.js +3 -0
- package/.npmignore +0 -2
- package/.travis.yml +0 -5
- package/benchmark/README.md +0 -53
- package/benchmark/bench.gnu +0 -174
- package/benchmark/bench.sh +0 -34
- package/benchmark/benchmark-native.c +0 -34
- package/benchmark/benchmark.js +0 -84
- package/benchmark/package.json +0 -9
- package/misc/compare.js +0 -62
- package/misc/perf.js +0 -102
- package/rng-browser.js +0 -32
- package/rng.js +0 -4
- package/test/mocha.opts +0 -1
- package/test/test.js +0 -105
- package/uuid.js +0 -183
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/AUTHORS
ADDED
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
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.2.0"></a>
|
|
6
|
+
# [3.2.0](https://github.com/kelektiv/node-uuid/compare/v3.1.0...v3.2.0) (2018-01-16)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* remove mistakenly added typescript dependency, rollback version (standard-version will auto-increment) ([09fa824](https://github.com/kelektiv/node-uuid/commit/09fa824))
|
|
12
|
+
* 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))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
|
|
17
|
+
* Add v3 Support ([#217](https://github.com/kelektiv/node-uuid/issues/217)) ([d94f726](https://github.com/kelektiv/node-uuid/commit/d94f726))
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
# 3.0.1 (2016-11-28)
|
|
22
|
+
|
|
23
|
+
* split uuid versions into separate files
|
|
24
|
+
|
|
25
|
+
# 3.0.0 (2016-11-17)
|
|
26
|
+
|
|
27
|
+
* remove .parse and .unparse
|
|
28
|
+
|
|
29
|
+
# 2.0.0
|
|
30
|
+
|
|
31
|
+
* Removed uuid.BufferClass
|
|
32
|
+
|
|
33
|
+
# 1.4.0
|
|
34
|
+
|
|
35
|
+
* Improved module context detection
|
|
36
|
+
* Removed public RNG functions
|
|
37
|
+
|
|
38
|
+
# 1.3.2
|
|
39
|
+
|
|
40
|
+
* Improve tests and handling of v1() options (Issue #24)
|
|
41
|
+
* Expose RNG option to allow for perf testing with different generators
|
|
42
|
+
|
|
43
|
+
# 1.3.0
|
|
44
|
+
|
|
45
|
+
* Support for version 1 ids, thanks to [@ctavan](https://github.com/ctavan)!
|
|
46
|
+
* Support for node.js crypto API
|
|
47
|
+
* De-emphasizing performance in favor of a) cryptographic quality PRNGs where available and b) more manageable code
|
package/LICENSE.md
CHANGED
|
@@ -1,2 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2010-2016 Robert Kieffer and other contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,44 +1,137 @@
|
|
|
1
|
-
|
|
1
|
+
<!--
|
|
2
|
+
-- This file is auto-generated from README_js.md. Changes should be made there.
|
|
3
|
+
-->
|
|
2
4
|
|
|
3
|
-
[](http://travis-ci.org/kelektiv/node-uuid) #
|
|
4
6
|
|
|
5
7
|
Simple, fast generation of [RFC4122](http://www.ietf.org/rfc/rfc4122.txt) UUIDS.
|
|
6
8
|
|
|
7
9
|
Features:
|
|
8
10
|
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* [Annotated source code](http://broofa.github.com/node-uuid/docs/uuid.html)
|
|
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))
|
|
14
15
|
|
|
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.]
|
|
16
18
|
|
|
17
|
-
|
|
19
|
+
## Quickstart - CommonJS (Recommended)
|
|
18
20
|
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
+
```shell
|
|
22
|
+
npm install uuid
|
|
21
23
|
```
|
|
22
24
|
|
|
23
|
-
|
|
25
|
+
Then generate your uuid version of choice ...
|
|
26
|
+
|
|
27
|
+
Version 1 (timestamp):
|
|
28
|
+
|
|
29
|
+
```javascript
|
|
30
|
+
const uuidv1 = require('uuid/v1');
|
|
31
|
+
uuidv1(); // ⇨ 'cd4b78f0-facb-11e7-8ab9-db97a89e6c61'
|
|
24
32
|
|
|
25
33
|
```
|
|
26
|
-
|
|
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(); // ⇨ '50fcd19b-5302-4b7b-97fd-92cabead0a6d'
|
|
60
|
+
|
|
27
61
|
```
|
|
28
62
|
|
|
63
|
+
Version 5 (namespace):
|
|
64
|
+
|
|
29
65
|
```javascript
|
|
30
|
-
|
|
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'
|
|
80
|
+
|
|
81
|
+
```
|
|
31
82
|
|
|
32
|
-
|
|
33
|
-
uuid.v1(); // -> '6c84fb90-12c4-11e1-840d-7b25c5ee775a'
|
|
83
|
+
## Quickstart - Browser-ready Versions
|
|
34
84
|
|
|
35
|
-
|
|
36
|
-
|
|
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>
|
|
37
121
|
```
|
|
38
122
|
|
|
39
123
|
## API
|
|
40
124
|
|
|
41
|
-
###
|
|
125
|
+
### Version 1
|
|
126
|
+
|
|
127
|
+
```javascript
|
|
128
|
+
const uuidv1 = require('uuid/v1');
|
|
129
|
+
|
|
130
|
+
// Incantations
|
|
131
|
+
uuidv1();
|
|
132
|
+
uuidv1(options);
|
|
133
|
+
uuidv1(options, buffer, offset);
|
|
134
|
+
```
|
|
42
135
|
|
|
43
136
|
Generate and return a RFC4122 v1 (timestamp-based) UUID.
|
|
44
137
|
|
|
@@ -46,7 +139,7 @@ Generate and return a RFC4122 v1 (timestamp-based) UUID.
|
|
|
46
139
|
|
|
47
140
|
* `node` - (Array) Node id as Array of 6 bytes (per 4.1.6). Default: Randomly generated ID. See note 1.
|
|
48
141
|
* `clockseq` - (Number between 0 - 0x3fff) RFC clock sequence. Default: An internally maintained clockseq is used.
|
|
49
|
-
* `msecs` - (Number
|
|
142
|
+
* `msecs` - (Number) Time in milliseconds since unix Epoch. Default: The current time is used.
|
|
50
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.
|
|
51
144
|
|
|
52
145
|
* `buffer` - (Array | Buffer) Array or buffer where UUID bytes are to be written.
|
|
@@ -54,152 +147,147 @@ Generate and return a RFC4122 v1 (timestamp-based) UUID.
|
|
|
54
147
|
|
|
55
148
|
Returns `buffer`, if specified, otherwise the string form of the UUID
|
|
56
149
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
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.)
|
|
60
151
|
|
|
61
152
|
Example: Generate string UUID with fully-specified options
|
|
62
153
|
|
|
63
154
|
```javascript
|
|
64
|
-
|
|
155
|
+
const v1options = {
|
|
65
156
|
node: [0x01, 0x23, 0x45, 0x67, 0x89, 0xab],
|
|
66
157
|
clockseq: 0x1234,
|
|
67
158
|
msecs: new Date('2011-11-01').getTime(),
|
|
68
159
|
nsecs: 5678
|
|
69
|
-
}
|
|
160
|
+
};
|
|
161
|
+
uuidv1(v1options); // ⇨ '710b962e-041c-11e1-9234-0123456789ab'
|
|
162
|
+
|
|
70
163
|
```
|
|
71
164
|
|
|
72
165
|
Example: In-place generation of two binary IDs
|
|
73
166
|
|
|
74
167
|
```javascript
|
|
75
168
|
// Generate two ids in an array
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
169
|
+
const arr = new Array();
|
|
170
|
+
uuidv1(null, arr, 0); // ⇨ [ 205, 84, 121, 160, 250, 203, 17, 231, 146, 52, 219, 151, 168, 158, 108, 97 ]
|
|
171
|
+
uuidv1(null, arr, 16); // ⇨ [ 205, 84, 121, 160, 250, 203, 17, 231, 146, 52, 219, 151, 168, 158, 108, 97, 205, 84, 160, 176, 250, 203, 17, 231, 146, 52, 219, 151, 168, 158, 108, 97 ]
|
|
79
172
|
|
|
80
|
-
// Optionally use uuid.unparse() to get stringify the ids
|
|
81
|
-
uuid.unparse(buffer); // -> '02a2ce90-1432-11e1-8558-0b488e4fc115'
|
|
82
|
-
uuid.unparse(buffer, 16) // -> '02a31cb0-1432-11e1-8558-0b488e4fc115'
|
|
83
173
|
```
|
|
84
174
|
|
|
85
|
-
###
|
|
175
|
+
### Version 3
|
|
86
176
|
|
|
87
|
-
|
|
177
|
+
```javascript
|
|
178
|
+
const uuidv3 = require('uuid/v3');
|
|
88
179
|
|
|
89
|
-
|
|
180
|
+
// Incantations
|
|
181
|
+
uuidv3(name, namespace);
|
|
182
|
+
uuidv3(name, namespace, buffer);
|
|
183
|
+
uuidv3(name, namespace, buffer, offset);
|
|
184
|
+
```
|
|
90
185
|
|
|
91
|
-
|
|
92
|
-
* `rng` - (Function) Random # generator to use. Set to one of the built-in generators - `uuid.mathRNG` (all platforms), `uuid.nodeRNG` (node.js only), `uuid.whatwgRNG` (WebKit only) - or a custom function that returns an array[16] of byte values.
|
|
186
|
+
Generate and return a RFC4122 v3 UUID.
|
|
93
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
|
|
94
190
|
* `buffer` - (Array | Buffer) Array or buffer where UUID bytes are to be written.
|
|
95
|
-
* `offset` - (Number) Starting index in `buffer` at which to begin writing.
|
|
191
|
+
* `offset` - (Number) Starting index in `buffer` at which to begin writing. Default = 0
|
|
96
192
|
|
|
97
193
|
Returns `buffer`, if specified, otherwise the string form of the UUID
|
|
98
194
|
|
|
99
|
-
Example:
|
|
195
|
+
Example:
|
|
100
196
|
|
|
101
197
|
```javascript
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
0x10, 0x91, 0x56, 0xbe, 0xc4, 0xfb, 0xc1, 0xea,
|
|
105
|
-
0x71, 0xb4, 0xef, 0xe1, 0x67, 0x1c, 0x58, 0x36
|
|
106
|
-
]
|
|
107
|
-
});
|
|
108
|
-
// -> "109156be-c4fb-41ea-b1b4-efe1671c5836"
|
|
198
|
+
uuidv3('hello world', MY_NAMESPACE); // ⇨ '042ffd34-d989-321c-ad06-f60826172424'
|
|
199
|
+
|
|
109
200
|
```
|
|
110
201
|
|
|
111
|
-
|
|
202
|
+
### Version 4
|
|
112
203
|
|
|
113
204
|
```javascript
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
205
|
+
const uuidv4 = require('uuid/v4')
|
|
206
|
+
|
|
207
|
+
// Incantations
|
|
208
|
+
uuidv4();
|
|
209
|
+
uuidv4(options);
|
|
210
|
+
uuidv4(options, buffer, offset);
|
|
117
211
|
```
|
|
118
212
|
|
|
119
|
-
|
|
120
|
-
### uuid.unparse(buffer[, offset])
|
|
213
|
+
Generate and return a RFC4122 v4 UUID.
|
|
121
214
|
|
|
122
|
-
|
|
215
|
+
* `options` - (Object) Optional uuid state to apply. Properties may include:
|
|
216
|
+
* `random` - (Number[16]) Array of 16 numbers (0-255) to use in place of randomly generated values
|
|
217
|
+
* `rng` - (Function) Random # generator function that returns an Array[16] of byte values (0-255)
|
|
218
|
+
* `buffer` - (Array | Buffer) Array or buffer where UUID bytes are to be written.
|
|
219
|
+
* `offset` - (Number) Starting index in `buffer` at which to begin writing.
|
|
123
220
|
|
|
124
|
-
|
|
125
|
-
* `buffer` - (Array | Buffer) Array or buffer where UUID bytes are to be written. Default: A new Array or Buffer is used
|
|
126
|
-
* `offset` - (Number) Starting index in `buffer` at which to begin writing. Default: 0
|
|
221
|
+
Returns `buffer`, if specified, otherwise the string form of the UUID
|
|
127
222
|
|
|
128
|
-
Example
|
|
223
|
+
Example: Generate string UUID with predefined `random` values
|
|
129
224
|
|
|
130
225
|
```javascript
|
|
131
|
-
|
|
132
|
-
|
|
226
|
+
const v4options = {
|
|
227
|
+
random: [
|
|
228
|
+
0x10, 0x91, 0x56, 0xbe, 0xc4, 0xfb, 0xc1, 0xea,
|
|
229
|
+
0x71, 0xb4, 0xef, 0xe1, 0x67, 0x1c, 0x58, 0x36
|
|
230
|
+
]
|
|
231
|
+
};
|
|
232
|
+
uuidv4(v4options); // ⇨ '109156be-c4fb-41ea-b1b4-efe1671c5836'
|
|
233
|
+
|
|
133
234
|
```
|
|
134
235
|
|
|
135
|
-
|
|
236
|
+
Example: Generate two IDs in a single buffer
|
|
136
237
|
|
|
137
|
-
|
|
238
|
+
```javascript
|
|
239
|
+
const buffer = new Array();
|
|
240
|
+
uuidv4(null, buffer, 0); // ⇨ [ 67, 176, 245, 14, 66, 213, 76, 211, 160, 194, 254, 30, 190, 20, 195, 236 ]
|
|
241
|
+
uuidv4(null, buffer, 16); // ⇨ [ 67, 176, 245, 14, 66, 213, 76, 211, 160, 194, 254, 30, 190, 20, 195, 236, 25, 78, 246, 100, 115, 188, 70, 66, 185, 84, 18, 78, 23, 254, 174, 151 ]
|
|
138
242
|
|
|
139
|
-
|
|
243
|
+
```
|
|
140
244
|
|
|
141
|
-
|
|
245
|
+
### Version 5
|
|
142
246
|
|
|
143
247
|
```javascript
|
|
144
|
-
|
|
145
|
-
myUuid.v1(); // -> '6c84fb90-12c4-11e1-840d-7b25c5ee775a'
|
|
146
|
-
```
|
|
248
|
+
const uuidv5 = require('uuid/v5');
|
|
147
249
|
|
|
148
|
-
|
|
250
|
+
// Incantations
|
|
251
|
+
uuidv5(name, namespace);
|
|
252
|
+
uuidv5(name, namespace, buffer);
|
|
253
|
+
uuidv5(name, namespace, buffer, offset);
|
|
254
|
+
```
|
|
149
255
|
|
|
150
|
-
|
|
256
|
+
Generate and return a RFC4122 v5 UUID.
|
|
151
257
|
|
|
152
|
-
|
|
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
|
|
153
262
|
|
|
154
|
-
|
|
263
|
+
Returns `buffer`, if specified, otherwise the string form of the UUID
|
|
155
264
|
|
|
156
|
-
|
|
265
|
+
Example:
|
|
157
266
|
|
|
158
|
-
|
|
267
|
+
```javascript
|
|
268
|
+
uuidv5('hello world', MY_NAMESPACE); // ⇨ '9f282611-e0fd-5650-8953-89c8e342da0b'
|
|
159
269
|
|
|
160
|
-
```
|
|
161
|
-
> cd test
|
|
162
|
-
> node test.js
|
|
163
270
|
```
|
|
164
271
|
|
|
165
|
-
|
|
272
|
+
## Command Line
|
|
166
273
|
|
|
167
|
-
|
|
168
|
-
open test/test.html
|
|
169
|
-
```
|
|
170
|
-
|
|
171
|
-
### Benchmarking
|
|
274
|
+
UUIDs can be generated from the command line with the `uuid` command.
|
|
172
275
|
|
|
173
|
-
|
|
276
|
+
```shell
|
|
277
|
+
$ uuid
|
|
278
|
+
ddeb27fb-d9a0-4624-be4d-4615062daed4
|
|
174
279
|
|
|
280
|
+
$ uuid v1
|
|
281
|
+
02d37060-d446-11e7-a9fa-7bdae751ebe1
|
|
175
282
|
```
|
|
176
|
-
cd benchmark/
|
|
177
|
-
npm install
|
|
178
|
-
node benchmark.js
|
|
179
|
-
```
|
|
180
|
-
|
|
181
|
-
For a more complete discussion of uuid performance, please see the `benchmark/README.md` file, and the [benchmark wiki](https://github.com/broofa/uuid/wiki/Benchmark)
|
|
182
|
-
|
|
183
|
-
For browser performance [checkout the JSPerf tests](http://jsperf.com/node-uuid-performance).
|
|
184
|
-
|
|
185
|
-
## Release notes
|
|
186
283
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
* Removed uuid.BufferClass
|
|
284
|
+
Type `uuid --help` for usage details
|
|
190
285
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
* Improved module context detection
|
|
194
|
-
* Removed public RNG functions
|
|
195
|
-
|
|
196
|
-
### 1.3.2
|
|
197
|
-
|
|
198
|
-
* Improve tests and handling of v1() options (Issue #24)
|
|
199
|
-
* Expose RNG option to allow for perf testing with different generators
|
|
286
|
+
## Testing
|
|
200
287
|
|
|
201
|
-
|
|
288
|
+
```shell
|
|
289
|
+
npm test
|
|
290
|
+
```
|
|
202
291
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
* De-emphasizing performance in favor of a) cryptographic quality PRNGs where available and b) more manageable code
|
|
292
|
+
----
|
|
293
|
+
Markdown generated from [README_js.md](README_js.md) by [](https://github.com/broofa/runmd)
|