uuid 3.1.0 → 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 CHANGED
@@ -7,16 +7,16 @@
7
7
  "mocha": true
8
8
  },
9
9
  "extends": ["eslint:recommended"],
10
- "installedESLint": true,
11
10
  "rules": {
12
11
  "array-bracket-spacing": ["warn", "never"],
13
12
  "arrow-body-style": ["warn", "as-needed"],
14
13
  "arrow-parens": ["warn", "as-needed"],
15
14
  "arrow-spacing": "warn",
16
- "brace-style": "warn",
15
+ "brace-style": ["warn", "1tbs"],
17
16
  "camelcase": "warn",
18
17
  "comma-spacing": ["warn", {"after": true}],
19
18
  "dot-notation": "warn",
19
+ "eqeqeq": ["warn", "smart"],
20
20
  "indent": ["warn", 2, {
21
21
  "SwitchCase": 1,
22
22
  "FunctionDeclaration": {"parameters": 1},
@@ -33,6 +33,7 @@
33
33
  "no-trailing-spaces": "warn",
34
34
  "no-undef": "error",
35
35
  "no-unused-vars": ["warn", {"args": "none"}],
36
+ "one-var": ["warn", "never"],
36
37
  "padded-blocks": ["warn", "never"],
37
38
  "object-curly-spacing": ["warn", "never"],
38
39
  "quotes": ["warn", "single"],
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/README.md CHANGED
@@ -1,14 +1,21 @@
1
+ <!--
2
+ -- This file is auto-generated from README_js.md. Changes should be made there.
3
+ -->
4
+
1
5
  # uuid [![Build Status](https://secure.travis-ci.org/kelektiv/node-uuid.svg?branch=master)](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
- * Support for version 1, 4 and 5 UUIDs
11
+ * Support for version 1, 3, 4 and 5 UUIDs
8
12
  * Cross-platform
9
13
  * Uses cryptographically-strong random number APIs (when available)
10
14
  * Zero-dependency, small footprint (... but not [this small](https://gist.github.com/982883))
11
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
+
12
19
  ## Quickstart - CommonJS (Recommended)
13
20
 
14
21
  ```shell
@@ -21,14 +28,36 @@ Version 1 (timestamp):
21
28
 
22
29
  ```javascript
23
30
  const uuidv1 = require('uuid/v1');
24
- uuidv1(); // -> '6c84fb90-12c4-11e1-840d-7b25c5ee775a'
31
+ uuidv1(); // 'cd4b78f0-facb-11e7-8ab9-db97a89e6c61'
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
+
25
53
  ```
26
54
 
27
55
  Version 4 (random):
28
56
 
29
57
  ```javascript
30
58
  const uuidv4 = require('uuid/v4');
31
- uuidv4(); // -> '110ec58a-a0f2-4ac4-8393-c866d813b8d1'
59
+ uuidv4(); // '50fcd19b-5302-4b7b-97fd-92cabead0a6d'
60
+
32
61
  ```
33
62
 
34
63
  Version 5 (namespace):
@@ -37,14 +66,18 @@ Version 5 (namespace):
37
66
  const uuidv5 = require('uuid/v5');
38
67
 
39
68
  // ... using predefined DNS namespace (for domain names)
40
- uuidv5('hello.example.com', uuidv5.DNS)); // -> 'fdda765f-fc57-5604-a269-52a7df8164ec'
69
+ uuidv5('hello.example.com', uuidv5.DNS); // 'fdda765f-fc57-5604-a269-52a7df8164ec'
41
70
 
42
71
  // ... using predefined URL namespace (for, well, URLs)
43
- uuidv5('http://example.com/hello', uuidv5.URL); // -> '3bbcee75-cecc-5b56-8031-b6641c1ed1f1'
72
+ uuidv5('http://example.com/hello', uuidv5.URL); // '3bbcee75-cecc-5b56-8031-b6641c1ed1f1'
44
73
 
45
74
  // ... using a custom namespace
46
- const MY_NAMESPACE = '<UUID string you previously generated elsewhere>';
47
- uuidv5('Hello, World!', MY_NAMESPACE); // -> '90123e1c-7512-523e-bb28-76fab9f2f73d'
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
+
48
81
  ```
49
82
 
50
83
  ## Quickstart - Browser-ready Versions
@@ -60,6 +93,15 @@ uuidv1(); // -> v1 UUID
60
93
  </script>
61
94
  ```
62
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
+
63
105
  For version 4 uuids:
64
106
 
65
107
  ```html
@@ -85,7 +127,7 @@ uuidv5('http://example.com/hello', uuidv5.URL); // -> v5 UUID
85
127
  ```javascript
86
128
  const uuidv1 = require('uuid/v1');
87
129
 
88
- // Allowed arguments
130
+ // Incantations
89
131
  uuidv1();
90
132
  uuidv1(options);
91
133
  uuidv1(options, buffer, offset);
@@ -97,7 +139,7 @@ Generate and return a RFC4122 v1 (timestamp-based) UUID.
97
139
 
98
140
  * `node` - (Array) Node id as Array of 6 bytes (per 4.1.6). Default: Randomly generated ID. See note 1.
99
141
  * `clockseq` - (Number between 0 - 0x3fff) RFC clock sequence. Default: An internally maintained clockseq is used.
100
- * `msecs` - (Number | Date) Time in milliseconds since unix Epoch. Default: The current time is used.
142
+ * `msecs` - (Number) Time in milliseconds since unix Epoch. Default: The current time is used.
101
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.
102
144
 
103
145
  * `buffer` - (Array | Buffer) Array or buffer where UUID bytes are to be written.
@@ -110,21 +152,51 @@ Note: The <node> id is generated guaranteed to stay constant for the lifetime of
110
152
  Example: Generate string UUID with fully-specified options
111
153
 
112
154
  ```javascript
113
- uuidv1({
155
+ const v1options = {
114
156
  node: [0x01, 0x23, 0x45, 0x67, 0x89, 0xab],
115
157
  clockseq: 0x1234,
116
158
  msecs: new Date('2011-11-01').getTime(),
117
159
  nsecs: 5678
118
- }); // -> "710b962e-041c-11e1-9234-0123456789ab"
160
+ };
161
+ uuidv1(v1options); // ⇨ '710b962e-041c-11e1-9234-0123456789ab'
162
+
119
163
  ```
120
164
 
121
165
  Example: In-place generation of two binary IDs
122
166
 
123
167
  ```javascript
124
168
  // Generate two ids in an array
125
- const arr = new Array(32); // -> []
126
- uuidv1(null, arr, 0); // -> [02 a2 ce 90 14 32 11 e1 85 58 0b 48 8e 4f c1 15]
127
- uuidv1(null, arr, 16); // -> [02 a2 ce 90 14 32 11 e1 85 58 0b 48 8e 4f c1 15 02 a3 1c b0 14 32 11 e1 85 58 0b 48 8e 4f c1 15]
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 ]
172
+
173
+ ```
174
+
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
+
128
200
  ```
129
201
 
130
202
  ### Version 4
@@ -132,7 +204,7 @@ uuidv1(null, arr, 16); // -> [02 a2 ce 90 14 32 11 e1 85 58 0b 48 8e 4f c1 15 0
132
204
  ```javascript
133
205
  const uuidv4 = require('uuid/v4')
134
206
 
135
- // Allowed arguments
207
+ // Incantations
136
208
  uuidv4();
137
209
  uuidv4(options);
138
210
  uuidv4(options, buffer, offset);
@@ -148,38 +220,40 @@ Generate and return a RFC4122 v4 UUID.
148
220
 
149
221
  Returns `buffer`, if specified, otherwise the string form of the UUID
150
222
 
151
- Example: Generate string UUID with fully-specified options
223
+ Example: Generate string UUID with predefined `random` values
152
224
 
153
225
  ```javascript
154
- uuid.v4({
226
+ const v4options = {
155
227
  random: [
156
228
  0x10, 0x91, 0x56, 0xbe, 0xc4, 0xfb, 0xc1, 0xea,
157
229
  0x71, 0xb4, 0xef, 0xe1, 0x67, 0x1c, 0x58, 0x36
158
230
  ]
159
- });
160
- // -> "109156be-c4fb-41ea-b1b4-efe1671c5836"
231
+ };
232
+ uuidv4(v4options); // '109156be-c4fb-41ea-b1b4-efe1671c5836'
233
+
161
234
  ```
162
235
 
163
236
  Example: Generate two IDs in a single buffer
164
237
 
165
238
  ```javascript
166
- const buffer = new Array(32); // (or 'new Buffer' in node.js)
167
- uuid.v4(null, buffer, 0);
168
- uuid.v4(null, buffer, 16);
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 ]
242
+
169
243
  ```
170
244
 
171
245
  ### Version 5
172
246
 
173
247
  ```javascript
174
- const uuidv5 = require('uuid/v4');
248
+ const uuidv5 = require('uuid/v5');
175
249
 
176
- // Allowed arguments
250
+ // Incantations
177
251
  uuidv5(name, namespace);
178
252
  uuidv5(name, namespace, buffer);
179
253
  uuidv5(name, namespace, buffer, offset);
180
254
  ```
181
255
 
182
- Generate and return a RFC4122 v4 UUID.
256
+ Generate and return a RFC4122 v5 UUID.
183
257
 
184
258
  * `name` - (String | Array[]) "name" to create UUID with
185
259
  * `namespace` - (String | Array[]) "namespace" UUID either as a String or Array[16] of byte values
@@ -191,37 +265,29 @@ Returns `buffer`, if specified, otherwise the string form of the UUID
191
265
  Example:
192
266
 
193
267
  ```javascript
194
- // Generate a unique namespace (typically you would do this once, outside of
195
- // your project, then bake this value into your code)
196
- const uuidv4 = require('uuid/v4');
197
- const MY_NAMESPACE = uuidv4(); //
268
+ uuidv5('hello world', MY_NAMESPACE); // '9f282611-e0fd-5650-8953-89c8e342da0b'
198
269
 
199
- // Generate a couple namespace uuids
200
- const uuidv5 = require('uuid/v5');
201
- uuidv5('hello', MY_NAMESPACE);
202
- uuidv5('world', MY_NAMESPACE);
203
270
  ```
204
271
 
205
- ## Testing
272
+ ## Command Line
206
273
 
207
- ```shell
208
- npm test
209
- ```
274
+ UUIDs can be generated from the command line with the `uuid` command.
210
275
 
211
- ## Deprecated / Browser-ready API
276
+ ```shell
277
+ $ uuid
278
+ ddeb27fb-d9a0-4624-be4d-4615062daed4
212
279
 
213
- The API below is available for legacy purposes and is not expected to be available post-3.X
280
+ $ uuid v1
281
+ 02d37060-d446-11e7-a9fa-7bdae751ebe1
282
+ ```
214
283
 
215
- ```javascript
216
- const uuid = require('uuid');
284
+ Type `uuid --help` for usage details
217
285
 
218
- uuid.v1(...); // alias of uuid/v1
219
- uuid.v4(...); // alias of uuid/v4
220
- uuid(...); // alias of uuid/v4
286
+ ## Testing
221
287
 
222
- // uuid.v5() is not supported in this API
288
+ ```shell
289
+ npm test
223
290
  ```
224
291
 
225
- ## Legacy node-uuid package
226
-
227
- The code for the legacy node-uuid package is available in the `node-uuid` branch.
292
+ ----
293
+ Markdown generated from [README_js.md](README_js.md) by [![RunMD Logo](http://i.imgur.com/h0FVyzU.png)](https://github.com/broofa/runmd)
package/README_js.md ADDED
@@ -0,0 +1,280 @@
1
+ ```javascript --hide
2
+ runmd.onRequire = path => path.replace(/^uuid/, './');
3
+ ```
4
+
5
+ # uuid [![Build Status](https://secure.travis-ci.org/kelektiv/node-uuid.svg?branch=master)](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
+ ```
package/bin/uuid CHANGED
@@ -5,6 +5,7 @@ function usage() {
5
5
  console.log('Usage:');
6
6
  console.log(' uuid');
7
7
  console.log(' uuid v1');
8
+ console.log(' uuid v3 <name> <namespace uuid>');
8
9
  console.log(' uuid v4');
9
10
  console.log(' uuid v5 <name> <namespace uuid>');
10
11
  console.log(' uuid --help');
@@ -25,6 +26,20 @@ switch (version) {
25
26
  console.log(uuidV1());
26
27
  break;
27
28
 
29
+ case 'v3':
30
+ var uuidV3 = require('../v3');
31
+
32
+ var name = args.shift();
33
+ var namespace = args.shift();
34
+ assert(name != null, 'v3 name not specified');
35
+ assert(namespace != null, 'v3 namespace not specified');
36
+
37
+ if (namespace == 'URL') namespace = uuidV3.URL;
38
+ if (namespace == 'DNS') namespace = uuidV3.DNS;
39
+
40
+ console.log(uuidV3(name, namespace));
41
+ break;
42
+
28
43
  case 'v4':
29
44
  var uuidV4 = require('../v4');
30
45
  console.log(uuidV4());
@@ -0,0 +1,216 @@
1
+ /*
2
+ * Browser-compatible JavaScript MD5
3
+ *
4
+ * Modification of JavaScript MD5
5
+ * https://github.com/blueimp/JavaScript-MD5
6
+ *
7
+ * Copyright 2011, Sebastian Tschan
8
+ * https://blueimp.net
9
+ *
10
+ * Licensed under the MIT license:
11
+ * https://opensource.org/licenses/MIT
12
+ *
13
+ * Based on
14
+ * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
15
+ * Digest Algorithm, as defined in RFC 1321.
16
+ * Version 2.2 Copyright (C) Paul Johnston 1999 - 2009
17
+ * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
18
+ * Distributed under the BSD License
19
+ * See http://pajhome.org.uk/crypt/md5 for more info.
20
+ */
21
+
22
+ 'use strict';
23
+
24
+ function md5(bytes) {
25
+ if (typeof(bytes) == 'string') {
26
+ var msg = unescape(encodeURIComponent(bytes)); // UTF8 escape
27
+ bytes = new Array(msg.length);
28
+ for (var i = 0; i < msg.length; i++) bytes[i] = msg.charCodeAt(i);
29
+ }
30
+
31
+ return md5ToHexEncodedArray(
32
+ wordsToMd5(
33
+ bytesToWords(bytes)
34
+ , bytes.length * 8)
35
+ );
36
+ }
37
+
38
+
39
+ /*
40
+ * Convert an array of little-endian words to an array of bytes
41
+ */
42
+ function md5ToHexEncodedArray(input) {
43
+ var i;
44
+ var x;
45
+ var output = [];
46
+ var length32 = input.length * 32;
47
+ var hexTab = '0123456789abcdef';
48
+ var hex;
49
+
50
+ for (i = 0; i < length32; i += 8) {
51
+ x = (input[i >> 5] >>> (i % 32)) & 0xFF;
52
+
53
+ hex = parseInt(hexTab.charAt((x >>> 4) & 0x0F) + hexTab.charAt(x & 0x0F), 16);
54
+
55
+ output.push(hex);
56
+ }
57
+ return output;
58
+ }
59
+
60
+ /*
61
+ * Calculate the MD5 of an array of little-endian words, and a bit length.
62
+ */
63
+ function wordsToMd5(x, len) {
64
+ /* append padding */
65
+ x[len >> 5] |= 0x80 << (len % 32);
66
+ x[(((len + 64) >>> 9) << 4) + 14] = len;
67
+
68
+ var i;
69
+ var olda;
70
+ var oldb;
71
+ var oldc;
72
+ var oldd;
73
+ var a = 1732584193;
74
+ var b = -271733879;
75
+ var c = -1732584194;
76
+
77
+ var d = 271733878;
78
+
79
+ for (i = 0; i < x.length; i += 16) {
80
+ olda = a;
81
+ oldb = b;
82
+ oldc = c;
83
+ oldd = d;
84
+
85
+ a = md5ff(a, b, c, d, x[i], 7, -680876936);
86
+ d = md5ff(d, a, b, c, x[i + 1], 12, -389564586);
87
+ c = md5ff(c, d, a, b, x[i + 2], 17, 606105819);
88
+ b = md5ff(b, c, d, a, x[i + 3], 22, -1044525330);
89
+ a = md5ff(a, b, c, d, x[i + 4], 7, -176418897);
90
+ d = md5ff(d, a, b, c, x[i + 5], 12, 1200080426);
91
+ c = md5ff(c, d, a, b, x[i + 6], 17, -1473231341);
92
+ b = md5ff(b, c, d, a, x[i + 7], 22, -45705983);
93
+ a = md5ff(a, b, c, d, x[i + 8], 7, 1770035416);
94
+ d = md5ff(d, a, b, c, x[i + 9], 12, -1958414417);
95
+ c = md5ff(c, d, a, b, x[i + 10], 17, -42063);
96
+ b = md5ff(b, c, d, a, x[i + 11], 22, -1990404162);
97
+ a = md5ff(a, b, c, d, x[i + 12], 7, 1804603682);
98
+ d = md5ff(d, a, b, c, x[i + 13], 12, -40341101);
99
+ c = md5ff(c, d, a, b, x[i + 14], 17, -1502002290);
100
+ b = md5ff(b, c, d, a, x[i + 15], 22, 1236535329);
101
+
102
+ a = md5gg(a, b, c, d, x[i + 1], 5, -165796510);
103
+ d = md5gg(d, a, b, c, x[i + 6], 9, -1069501632);
104
+ c = md5gg(c, d, a, b, x[i + 11], 14, 643717713);
105
+ b = md5gg(b, c, d, a, x[i], 20, -373897302);
106
+ a = md5gg(a, b, c, d, x[i + 5], 5, -701558691);
107
+ d = md5gg(d, a, b, c, x[i + 10], 9, 38016083);
108
+ c = md5gg(c, d, a, b, x[i + 15], 14, -660478335);
109
+ b = md5gg(b, c, d, a, x[i + 4], 20, -405537848);
110
+ a = md5gg(a, b, c, d, x[i + 9], 5, 568446438);
111
+ d = md5gg(d, a, b, c, x[i + 14], 9, -1019803690);
112
+ c = md5gg(c, d, a, b, x[i + 3], 14, -187363961);
113
+ b = md5gg(b, c, d, a, x[i + 8], 20, 1163531501);
114
+ a = md5gg(a, b, c, d, x[i + 13], 5, -1444681467);
115
+ d = md5gg(d, a, b, c, x[i + 2], 9, -51403784);
116
+ c = md5gg(c, d, a, b, x[i + 7], 14, 1735328473);
117
+ b = md5gg(b, c, d, a, x[i + 12], 20, -1926607734);
118
+
119
+ a = md5hh(a, b, c, d, x[i + 5], 4, -378558);
120
+ d = md5hh(d, a, b, c, x[i + 8], 11, -2022574463);
121
+ c = md5hh(c, d, a, b, x[i + 11], 16, 1839030562);
122
+ b = md5hh(b, c, d, a, x[i + 14], 23, -35309556);
123
+ a = md5hh(a, b, c, d, x[i + 1], 4, -1530992060);
124
+ d = md5hh(d, a, b, c, x[i + 4], 11, 1272893353);
125
+ c = md5hh(c, d, a, b, x[i + 7], 16, -155497632);
126
+ b = md5hh(b, c, d, a, x[i + 10], 23, -1094730640);
127
+ a = md5hh(a, b, c, d, x[i + 13], 4, 681279174);
128
+ d = md5hh(d, a, b, c, x[i], 11, -358537222);
129
+ c = md5hh(c, d, a, b, x[i + 3], 16, -722521979);
130
+ b = md5hh(b, c, d, a, x[i + 6], 23, 76029189);
131
+ a = md5hh(a, b, c, d, x[i + 9], 4, -640364487);
132
+ d = md5hh(d, a, b, c, x[i + 12], 11, -421815835);
133
+ c = md5hh(c, d, a, b, x[i + 15], 16, 530742520);
134
+ b = md5hh(b, c, d, a, x[i + 2], 23, -995338651);
135
+
136
+ a = md5ii(a, b, c, d, x[i], 6, -198630844);
137
+ d = md5ii(d, a, b, c, x[i + 7], 10, 1126891415);
138
+ c = md5ii(c, d, a, b, x[i + 14], 15, -1416354905);
139
+ b = md5ii(b, c, d, a, x[i + 5], 21, -57434055);
140
+ a = md5ii(a, b, c, d, x[i + 12], 6, 1700485571);
141
+ d = md5ii(d, a, b, c, x[i + 3], 10, -1894986606);
142
+ c = md5ii(c, d, a, b, x[i + 10], 15, -1051523);
143
+ b = md5ii(b, c, d, a, x[i + 1], 21, -2054922799);
144
+ a = md5ii(a, b, c, d, x[i + 8], 6, 1873313359);
145
+ d = md5ii(d, a, b, c, x[i + 15], 10, -30611744);
146
+ c = md5ii(c, d, a, b, x[i + 6], 15, -1560198380);
147
+ b = md5ii(b, c, d, a, x[i + 13], 21, 1309151649);
148
+ a = md5ii(a, b, c, d, x[i + 4], 6, -145523070);
149
+ d = md5ii(d, a, b, c, x[i + 11], 10, -1120210379);
150
+ c = md5ii(c, d, a, b, x[i + 2], 15, 718787259);
151
+ b = md5ii(b, c, d, a, x[i + 9], 21, -343485551);
152
+
153
+ a = safeAdd(a, olda);
154
+ b = safeAdd(b, oldb);
155
+ c = safeAdd(c, oldc);
156
+ d = safeAdd(d, oldd);
157
+ }
158
+ return [a, b, c, d];
159
+ }
160
+
161
+ /*
162
+ * Convert an array bytes to an array of little-endian words
163
+ * Characters >255 have their high-byte silently ignored.
164
+ */
165
+ function bytesToWords(input) {
166
+ var i;
167
+ var output = [];
168
+ output[(input.length >> 2) - 1] = undefined;
169
+ for (i = 0; i < output.length; i += 1) {
170
+ output[i] = 0;
171
+ }
172
+ var length8 = input.length * 8;
173
+ for (i = 0; i < length8; i += 8) {
174
+ output[i >> 5] |= (input[(i / 8)] & 0xFF) << (i % 32);
175
+ }
176
+
177
+ return output;
178
+ }
179
+
180
+ /*
181
+ * Add integers, wrapping at 2^32. This uses 16-bit operations internally
182
+ * to work around bugs in some JS interpreters.
183
+ */
184
+ function safeAdd(x, y) {
185
+ var lsw = (x & 0xFFFF) + (y & 0xFFFF);
186
+ var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
187
+ return (msw << 16) | (lsw & 0xFFFF);
188
+ }
189
+
190
+ /*
191
+ * Bitwise rotate a 32-bit number to the left.
192
+ */
193
+ function bitRotateLeft(num, cnt) {
194
+ return (num << cnt) | (num >>> (32 - cnt));
195
+ }
196
+
197
+ /*
198
+ * These functions implement the four basic operations the algorithm uses.
199
+ */
200
+ function md5cmn(q, a, b, x, s, t) {
201
+ return safeAdd(bitRotateLeft(safeAdd(safeAdd(a, q), safeAdd(x, t)), s), b);
202
+ }
203
+ function md5ff(a, b, c, d, x, s, t) {
204
+ return md5cmn((b & c) | ((~b) & d), a, b, x, s, t);
205
+ }
206
+ function md5gg(a, b, c, d, x, s, t) {
207
+ return md5cmn((b & d) | (c & (~d)), a, b, x, s, t);
208
+ }
209
+ function md5hh(a, b, c, d, x, s, t) {
210
+ return md5cmn(b ^ c ^ d, a, b, x, s, t);
211
+ }
212
+ function md5ii(a, b, c, d, x, s, t) {
213
+ return md5cmn(c ^ (b | (~d)), a, b, x, s, t);
214
+ }
215
+
216
+ module.exports = md5;
package/lib/md5.js ADDED
@@ -0,0 +1,25 @@
1
+ 'use strict';
2
+
3
+ var crypto = require('crypto');
4
+
5
+ function md5(bytes) {
6
+ if (typeof Buffer.from === 'function') {
7
+ // Modern Buffer API
8
+ if (Array.isArray(bytes)) {
9
+ bytes = Buffer.from(bytes);
10
+ } else if (typeof bytes === 'string') {
11
+ bytes = Buffer.from(bytes, 'utf8');
12
+ }
13
+ } else {
14
+ // Pre-v4 Buffer API
15
+ if (Array.isArray(bytes)) {
16
+ bytes = new Buffer(bytes);
17
+ } else if (typeof bytes === 'string') {
18
+ bytes = new Buffer(bytes, 'utf8');
19
+ }
20
+ }
21
+
22
+ return crypto.createHash('md5').update(bytes).digest();
23
+ }
24
+
25
+ module.exports = md5;
@@ -2,25 +2,25 @@
2
2
  // browser this is a little complicated due to unknown quality of Math.random()
3
3
  // and inconsistent support for the `crypto` API. We do the best we can via
4
4
  // feature-detection
5
- var rng;
6
5
 
7
- var crypto = global.crypto || global.msCrypto; // for IE 11
8
- if (crypto && crypto.getRandomValues) {
6
+ var getRandomValues = (typeof(crypto) != 'undefined' && crypto.getRandomValues) ||
7
+ (typeof(msCrypto) != 'undefined' && msCrypto.getRandomValues);
8
+ if (getRandomValues) {
9
9
  // WHATWG crypto RNG - http://wiki.whatwg.org/wiki/Crypto
10
10
  var rnds8 = new Uint8Array(16); // eslint-disable-line no-undef
11
- rng = function whatwgRNG() {
12
- crypto.getRandomValues(rnds8);
11
+
12
+ module.exports = function whatwgRNG() {
13
+ getRandomValues(rnds8);
13
14
  return rnds8;
14
15
  };
15
- }
16
-
17
- if (!rng) {
16
+ } else {
18
17
  // Math.random()-based (RNG)
19
18
  //
20
19
  // If all else fails, use Math.random(). It's fast, but is of unspecified
21
20
  // quality.
22
21
  var rnds = new Array(16);
23
- rng = function() {
22
+
23
+ module.exports = function mathRNG() {
24
24
  for (var i = 0, r; i < 16; i++) {
25
25
  if ((i & 0x03) === 0) r = Math.random() * 0x100000000;
26
26
  rnds[i] = r >>> ((i & 0x03) << 3) & 0xff;
@@ -29,5 +29,3 @@ if (!rng) {
29
29
  return rnds;
30
30
  };
31
31
  }
32
-
33
- module.exports = rng;
package/lib/rng.js CHANGED
@@ -1,10 +1,8 @@
1
1
  // Unique ID creation requires a high quality random # generator. In node.js
2
2
  // this is pretty straight-forward - we use the crypto API.
3
3
 
4
- var rb = require('crypto').randomBytes;
4
+ var crypto = require('crypto');
5
5
 
6
- function rng() {
7
- return rb(16);
8
- }
9
-
10
- module.exports = rng;
6
+ module.exports = function nodeRNG() {
7
+ return crypto.randomBytes(16);
8
+ };
@@ -54,7 +54,11 @@ function sha1(bytes) {
54
54
  W[t] = ROTL(W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16], 1);
55
55
  }
56
56
 
57
- var a = H[0], b = H[1], c = H[2], d = H[3], e = H[4];
57
+ var a = H[0];
58
+ var b = H[1];
59
+ var c = H[2];
60
+ var d = H[3];
61
+ var e = H[4];
58
62
 
59
63
  for (var t=0; t<80; t++) {
60
64
  var s = Math.floor(t/20);
package/lib/sha1.js CHANGED
@@ -3,19 +3,23 @@
3
3
  var crypto = require('crypto');
4
4
 
5
5
  function sha1(bytes) {
6
- // support modern Buffer API
7
- if (typeof Buffer.from === 'function') {
8
- if (Array.isArray(bytes)) bytes = Buffer.from(bytes);
9
- else if (typeof bytes === 'string') bytes = Buffer.from(bytes, 'utf8');
10
- }
6
+ if (typeof Buffer.from === 'function') {
7
+ // Modern Buffer API
8
+ if (Array.isArray(bytes)) {
9
+ bytes = Buffer.from(bytes);
10
+ } else if (typeof bytes === 'string') {
11
+ bytes = Buffer.from(bytes, 'utf8');
12
+ }
13
+ } else {
14
+ // Pre-v4 Buffer API
15
+ if (Array.isArray(bytes)) {
16
+ bytes = new Buffer(bytes);
17
+ } else if (typeof bytes === 'string') {
18
+ bytes = new Buffer(bytes, 'utf8');
19
+ }
20
+ }
11
21
 
12
- // support pre-v4 Buffer API
13
- else {
14
- if (Array.isArray(bytes)) bytes = new Buffer(bytes);
15
- else if (typeof bytes === 'string') bytes = new Buffer(bytes, 'utf8');
16
- }
17
-
18
- return crypto.createHash('sha1').update(bytes).digest();
22
+ return crypto.createHash('sha1').update(bytes).digest();
19
23
  }
20
24
 
21
25
  module.exports = sha1;
package/lib/v35.js ADDED
@@ -0,0 +1,53 @@
1
+ var bytesToUuid = require('./bytesToUuid');
2
+
3
+ function uuidToBytes(uuid) {
4
+ // Note: We assume we're being passed a valid uuid string
5
+ var bytes = [];
6
+ uuid.replace(/[a-fA-F0-9]{2}/g, function(hex) {
7
+ bytes.push(parseInt(hex, 16));
8
+ });
9
+
10
+ return bytes;
11
+ }
12
+
13
+ function stringToBytes(str) {
14
+ str = unescape(encodeURIComponent(str)); // UTF8 escape
15
+ var bytes = new Array(str.length);
16
+ for (var i = 0; i < str.length; i++) {
17
+ bytes[i] = str.charCodeAt(i);
18
+ }
19
+ return bytes;
20
+ }
21
+
22
+ module.exports = function(name, version, hashfunc) {
23
+ var generateUUID = function(value, namespace, buf, offset) {
24
+ var off = buf && offset || 0;
25
+
26
+ if (typeof(value) == 'string') value = stringToBytes(value);
27
+ if (typeof(namespace) == 'string') namespace = uuidToBytes(namespace);
28
+
29
+ if (!Array.isArray(value)) throw TypeError('value must be an array of bytes');
30
+ if (!Array.isArray(namespace) || namespace.length !== 16) throw TypeError('namespace must be uuid string or an Array of 16 byte values');
31
+
32
+ // Per 4.3
33
+ var bytes = hashfunc(namespace.concat(value));
34
+ bytes[6] = (bytes[6] & 0x0f) | version;
35
+ bytes[8] = (bytes[8] & 0x3f) | 0x80;
36
+
37
+ if (buf) {
38
+ for (var idx = 0; idx < 16; ++idx) {
39
+ buf[off+idx] = bytes[idx];
40
+ }
41
+ }
42
+
43
+ return buf || bytesToUuid(bytes);
44
+ };
45
+
46
+ generateUUID.name = name;
47
+
48
+ // Pre-defined namespaces, per Appendix C
49
+ generateUUID.DNS = '6ba7b810-9dad-11d1-80b4-00c04fd430c8';
50
+ generateUUID.URL = '6ba7b811-9dad-11d1-80b4-00c04fd430c8';
51
+
52
+ return generateUUID;
53
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "uuid",
3
- "version": "3.1.0",
3
+ "version": "3.2.0",
4
4
  "description": "RFC4122 (v1, v4, and v5) UUIDs",
5
5
  "keywords": [
6
6
  "uuid",
@@ -12,17 +12,25 @@
12
12
  "uuid": "./bin/uuid"
13
13
  },
14
14
  "devDependencies": {
15
- "mocha": "3.1.2"
15
+ "eslint": "4.5.0",
16
+ "mocha": "3.1.2",
17
+ "runmd": "1.0.1",
18
+ "standard-version": "4.2.0"
16
19
  },
17
20
  "scripts": {
18
- "test": "mocha test/test.js"
21
+ "test": "mocha test/test.js",
22
+ "md": "runmd --watch --output=README.md README_js.md",
23
+ "release": "standard-version",
24
+ "prepare": "runmd --output=README.md README_js.md"
19
25
  },
20
26
  "browser": {
21
27
  "./lib/rng.js": "./lib/rng-browser.js",
22
- "./lib/sha1.js": "./lib/sha1-browser.js"
28
+ "./lib/sha1.js": "./lib/sha1-browser.js",
29
+ "./lib/md5.js": "./lib/md5-browser.js"
23
30
  },
24
31
  "repository": {
25
32
  "type": "git",
26
33
  "url": "https://github.com/kelektiv/node-uuid.git"
27
- }
34
+ },
35
+ "dependencies": {}
28
36
  }
package/v1.js CHANGED
@@ -6,20 +6,12 @@ var bytesToUuid = require('./lib/bytesToUuid');
6
6
  // Inspired by https://github.com/LiosK/UUID.js
7
7
  // and http://docs.python.org/library/uuid.html
8
8
 
9
- // random #'s we need to init node and clockseq
10
- var _seedBytes = rng();
11
-
12
- // Per 4.5, create and 48-bit node id, (47 random bits + multicast bit = 1)
13
- var _nodeId = [
14
- _seedBytes[0] | 0x01,
15
- _seedBytes[1], _seedBytes[2], _seedBytes[3], _seedBytes[4], _seedBytes[5]
16
- ];
17
-
18
- // Per 4.2.2, randomize (14 bit) clockseq
19
- var _clockseq = (_seedBytes[6] << 8 | _seedBytes[7]) & 0x3fff;
9
+ var _nodeId;
10
+ var _clockseq;
20
11
 
21
12
  // Previous uuid creation time
22
- var _lastMSecs = 0, _lastNSecs = 0;
13
+ var _lastMSecs = 0;
14
+ var _lastNSecs = 0;
23
15
 
24
16
  // See https://github.com/broofa/node-uuid for API details
25
17
  function v1(options, buf, offset) {
@@ -27,9 +19,27 @@ function v1(options, buf, offset) {
27
19
  var b = buf || [];
28
20
 
29
21
  options = options || {};
30
-
22
+ var node = options.node || _nodeId;
31
23
  var clockseq = options.clockseq !== undefined ? options.clockseq : _clockseq;
32
24
 
25
+ // node and clockseq need to be initialized to random values if they're not
26
+ // specified. We do this lazily to minimize issues related to insufficient
27
+ // system entropy. See #189
28
+ if (node == null || clockseq == null) {
29
+ var seedBytes = rng();
30
+ if (node == null) {
31
+ // Per 4.5, create and 48-bit node id, (47 random bits + multicast bit = 1)
32
+ node = _nodeId = [
33
+ seedBytes[0] | 0x01,
34
+ seedBytes[1], seedBytes[2], seedBytes[3], seedBytes[4], seedBytes[5]
35
+ ];
36
+ }
37
+ if (clockseq == null) {
38
+ // Per 4.2.2, randomize (14 bit) clockseq
39
+ clockseq = _clockseq = (seedBytes[6] << 8 | seedBytes[7]) & 0x3fff;
40
+ }
41
+ }
42
+
33
43
  // UUID timestamps are 100 nano-second units since the Gregorian epoch,
34
44
  // (1582-10-15 00:00). JSNumbers aren't precise enough for this, so
35
45
  // time is handled internally as 'msecs' (integer milliseconds) and 'nsecs'
@@ -89,7 +99,6 @@ function v1(options, buf, offset) {
89
99
  b[i++] = clockseq & 0xff;
90
100
 
91
101
  // `node`
92
- var node = options.node || _nodeId;
93
102
  for (var n = 0; n < 6; ++n) {
94
103
  b[i + n] = node[n];
95
104
  }
package/v3.js ADDED
@@ -0,0 +1,4 @@
1
+ var v35 = require('./lib/v35.js');
2
+ var md5 = require('./lib/md5');
3
+
4
+ module.exports = v35('v3', 0x30, md5);
package/v4.js CHANGED
@@ -5,7 +5,7 @@ function v4(options, buf, offset) {
5
5
  var i = buf && offset || 0;
6
6
 
7
7
  if (typeof(options) == 'string') {
8
- buf = options == 'binary' ? new Array(16) : null;
8
+ buf = options === 'binary' ? new Array(16) : null;
9
9
  options = null;
10
10
  }
11
11
  options = options || {};
package/v5.js CHANGED
@@ -1,42 +1,3 @@
1
- var sha1 = require('./lib/sha1-browser');
2
- var bytesToUuid = require('./lib/bytesToUuid');
3
-
4
- function uuidToBytes(uuid) {
5
- // Note: We assume we're being passed a valid uuid string
6
- var bytes = [];
7
- uuid.replace(/[a-fA-F0-9]{2}/g, function(hex) {
8
- bytes.push(parseInt(hex, 16));
9
- });
10
-
11
- return bytes;
12
- }
13
-
14
- function stringToBytes(str) {
15
- str = unescape(encodeURIComponent(str)); // UTF8 escape
16
- var bytes = new Array(str.length);
17
- for (var i = 0; i < str.length; i++) {
18
- bytes[i] = str.charCodeAt(i);
19
- }
20
- return bytes;
21
- }
22
-
23
- function v5(name, namespace, buf, offset) {
24
- if (typeof(name) == 'string') name = stringToBytes(name);
25
- if (typeof(namespace) == 'string') namespace = uuidToBytes(namespace);
26
-
27
- if (!Array.isArray(name)) throw TypeError('name must be an array of bytes');
28
- if (!Array.isArray(namespace) || namespace.length != 16) throw TypeError('namespace must be uuid string or an Array of 16 byte values');
29
-
30
- // Per 4.3
31
- var bytes = sha1(namespace.concat(name));
32
- bytes[6] = (bytes[6] & 0x0f) | 0x50;
33
- bytes[8] = (bytes[8] & 0x3f) | 0x80;
34
-
35
- return buf || bytesToUuid(bytes);
36
- }
37
-
38
- // Pre-defined namespaces, per Appendix C
39
- v5.DNS = '6ba7b810-9dad-11d1-80b4-00c04fd430c8';
40
- v5.URL = '6ba7b811-9dad-11d1-80b4-00c04fd430c8';
41
-
42
- module.exports = v5;
1
+ var v35 = require('./lib/v35.js');
2
+ var sha1 = require('./lib/sha1');
3
+ module.exports = v35('v5', 0x50, sha1);
package/HISTORY.md DELETED
@@ -1,28 +0,0 @@
1
- # 3.0.1 (2016-11-28)
2
-
3
- * split uuid versions into separate files
4
-
5
- # 3.0.0 (2016-11-17)
6
-
7
- * remove .parse and .unparse
8
-
9
- # 2.0.0
10
-
11
- * Removed uuid.BufferClass
12
-
13
- # 1.4.0
14
-
15
- * Improved module context detection
16
- * Removed public RNG functions
17
-
18
- # 1.3.2
19
-
20
- * Improve tests and handling of v1() options (Issue #24)
21
- * Expose RNG option to allow for perf testing with different generators
22
-
23
- # 1.3.0
24
-
25
- * Support for version 1 ids, thanks to [@ctavan](https://github.com/ctavan)!
26
- * Support for node.js crypto API
27
- * De-emphasizing performance in favor of a) cryptographic quality PRNGs where available and b) more manageable code
28
-