uuid 7.0.2 → 8.1.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 CHANGED
@@ -2,6 +2,65 @@
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
+ ## [8.1.0](https://github.com/uuidjs/uuid/compare/v8.0.0...v8.1.0) (2020-05-20)
6
+
7
+ ### Features
8
+
9
+ - improve v4 performance by reusing random number array ([#435](https://github.com/uuidjs/uuid/issues/435)) ([bf4af0d](https://github.com/uuidjs/uuid/commit/bf4af0d711b4d2ed03d1f74fd12ad0baa87dc79d))
10
+ - optimize V8 performance of bytesToUuid ([#434](https://github.com/uuidjs/uuid/issues/434)) ([e156415](https://github.com/uuidjs/uuid/commit/e156415448ec1af2351fa0b6660cfb22581971f2))
11
+
12
+ ### Bug Fixes
13
+
14
+ - export package.json required by react-native and bundlers ([#449](https://github.com/uuidjs/uuid/issues/449)) ([be1c8fe](https://github.com/uuidjs/uuid/commit/be1c8fe9a3206c358e0059b52fafd7213aa48a52)), closes [/github.com/ai/nanoevents/issues/44#issuecomment-602010343](https://github.com/uuidjs//github.com/ai/nanoevents/issues/44/issues/issuecomment-602010343) [#444](https://github.com/uuidjs/uuid/issues/444)
15
+
16
+ ## [8.0.0](https://github.com/uuidjs/uuid/compare/v7.0.3...v8.0.0) (2020-04-29)
17
+
18
+ ### ⚠ BREAKING CHANGES
19
+
20
+ - For native ECMAScript Module (ESM) usage in Node.js only named exports are exposed, there is no more default export.
21
+
22
+ ```diff
23
+ -import uuid from 'uuid';
24
+ -console.log(uuid.v4()); // -> 'cd6c3b08-0adc-4f4b-a6ef-36087a1c9869'
25
+ +import { v4 as uuidv4 } from 'uuid';
26
+ +uuidv4(); // ⇨ '9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d'
27
+ ```
28
+
29
+ - Deep requiring specific algorithms of this library like `require('uuid/v4')`, which has been deprecated in `uuid@7`, is no longer supported.
30
+
31
+ Instead use the named exports that this module exports.
32
+
33
+ For ECMAScript Modules (ESM):
34
+
35
+ ```diff
36
+ -import uuidv4 from 'uuid/v4';
37
+ +import { v4 as uuidv4 } from 'uuid';
38
+ uuidv4();
39
+ ```
40
+
41
+ For CommonJS:
42
+
43
+ ```diff
44
+ -const uuidv4 = require('uuid/v4');
45
+ +const { v4: uuidv4 } = require('uuid');
46
+ uuidv4();
47
+ ```
48
+
49
+ ### Features
50
+
51
+ - native Node.js ES Modules (wrapper approach) ([#423](https://github.com/uuidjs/uuid/issues/423)) ([2d9f590](https://github.com/uuidjs/uuid/commit/2d9f590ad9701d692625c07ed62f0a0f91227991)), closes [#245](https://github.com/uuidjs/uuid/issues/245) [#419](https://github.com/uuidjs/uuid/issues/419) [#342](https://github.com/uuidjs/uuid/issues/342)
52
+ - remove deep requires ([#426](https://github.com/uuidjs/uuid/issues/426)) ([daf72b8](https://github.com/uuidjs/uuid/commit/daf72b84ceb20272a81bb5fbddb05dd95922cbba))
53
+
54
+ ### Bug Fixes
55
+
56
+ - add CommonJS syntax example to README quickstart section ([#417](https://github.com/uuidjs/uuid/issues/417)) ([e0ec840](https://github.com/uuidjs/uuid/commit/e0ec8402c7ad44b7ef0453036c612f5db513fda0))
57
+
58
+ ### [7.0.3](https://github.com/uuidjs/uuid/compare/v7.0.2...v7.0.3) (2020-03-31)
59
+
60
+ ### Bug Fixes
61
+
62
+ - make deep require deprecation warning work in browsers ([#409](https://github.com/uuidjs/uuid/issues/409)) ([4b71107](https://github.com/uuidjs/uuid/commit/4b71107d8c0d2ef56861ede6403fc9dc35a1e6bf)), closes [#408](https://github.com/uuidjs/uuid/issues/408)
63
+
5
64
  ### [7.0.2](https://github.com/uuidjs/uuid/compare/v7.0.1...v7.0.2) (2020-03-04)
6
65
 
7
66
  ### Bug Fixes
package/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2010-2016 Robert Kieffer and other contributors
3
+ Copyright (c) 2010-2020 Robert Kieffer and other contributors
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -9,7 +9,7 @@ For the creation of [RFC4122](http://www.ietf.org/rfc/rfc4122.txt) UUIDs
9
9
  - **Complete** - Support for RFC4122 version 1, 3, 4, and 5 UUIDs
10
10
  - **Cross-platform** - Support for ...
11
11
  - CommonJS, [ECMAScript Modules](#ecmascript-modules) and UMD builds
12
- - Node 8, 10, 12
12
+ - Node 8, 10, 12, 14
13
13
  - Chrome, Safari, Firefox, Edge, IE 11 browsers
14
14
  - Webpack and rollup.js module bundlers
15
15
  - [React Native](#react-native)
@@ -20,7 +20,7 @@ For the creation of [RFC4122](http://www.ietf.org/rfc/rfc4122.txt) UUIDs
20
20
  **Upgrading from uuid\@3?** Your code is probably okay, but check out [Upgrading
21
21
  From uuid\@3](#upgrading-from-uuid3) for details.
22
22
 
23
- ## Quickstart - Node.js/CommonJS
23
+ ## Quickstart
24
24
 
25
25
  ```shell
26
26
  npm install uuid
@@ -38,16 +38,25 @@ versions, all of which are supported here. In order of popularity, they are:
38
38
 
39
39
  ### Create Version 4 (Random) UUIDs
40
40
 
41
+ ECMAScript Module syntax:
42
+
41
43
  ```javascript
42
44
  import { v4 as uuidv4 } from 'uuid';
43
45
  uuidv4(); // ⇨ '9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d'
44
46
  ```
45
47
 
48
+ CommonJS syntax:
49
+
50
+ ```javascript
51
+ const { v4: uuidv4 } = require('uuid');
52
+ uuidv4(); // ⇨ '1b9d6bcd-bbfd-4b2d-9b5d-ab8dfbbd4bed'
53
+ ```
54
+
46
55
  ### Create Version 1 (Timestamp) UUIDs
47
56
 
48
57
  ```javascript
49
58
  import { v1 as uuidv1 } from 'uuid';
50
- uuidv1(); // ⇨ '2c5ea4c0-4067-11e9-8b2d-1b9d6bcdbbfd'
59
+ uuidv1(); // ⇨ '2c5ea4c0-4067-11e9-8bad-9b1deb4d3b7d'
51
60
  ```
52
61
 
53
62
  ### Create Version 3 or Version 5 (Namespace) UUIDs
@@ -133,17 +142,17 @@ Example: Generate two IDs in a single buffer
133
142
  const buffer = new Array();
134
143
  uuidv4(null, buffer, 0); // ⇨
135
144
  // [
136
- // 155, 29, 235, 77, 59,
137
- // 125, 75, 173, 155, 221,
138
- // 43, 13, 123, 61, 203,
139
- // 109
145
+ // 27, 157, 107, 205, 187,
146
+ // 253, 75, 45, 155, 93,
147
+ // 171, 141, 251, 189, 75,
148
+ // 237
140
149
  // ]
141
150
  uuidv4(null, buffer, 16); // ⇨
142
151
  // [
143
- // 155, 29, 235, 77, 59, 125, 75, 173,
144
- // 155, 221, 43, 13, 123, 61, 203, 109,
145
152
  // 27, 157, 107, 205, 187, 253, 75, 45,
146
- // 155, 93, 171, 141, 251, 189, 75, 237
153
+ // 155, 93, 171, 141, 251, 189, 75, 237,
154
+ // 155, 29, 235, 77, 59, 125, 75, 173,
155
+ // 155, 221, 43, 13, 123, 61, 203, 109
147
156
  // ]
148
157
  ```
149
158
 
@@ -193,17 +202,16 @@ Example: In-place generation of two binary IDs
193
202
  const arr = new Array();
194
203
  uuidv1(null, arr, 0); // ⇨
195
204
  // [
196
- // 44, 94, 164, 192, 64,
197
- // 103, 17, 233, 146, 52,
198
- // 27, 157, 107, 205, 187,
199
- // 253
205
+ // 44, 94, 164, 192, 64, 103,
206
+ // 17, 233, 146, 52, 155, 29,
207
+ // 235, 77, 59, 125
200
208
  // ]
201
209
  uuidv1(null, arr, 16); // ⇨
202
210
  // [
203
- // 44, 94, 164, 192, 64, 103, 17, 233,
204
- // 146, 52, 27, 157, 107, 205, 187, 253,
205
- // 44, 94, 164, 193, 64, 103, 17, 233,
206
- // 146, 52, 27, 157, 107, 205, 187, 253
211
+ // 44, 94, 164, 192, 64, 103, 17, 233,
212
+ // 146, 52, 155, 29, 235, 77, 59, 125,
213
+ // 44, 94, 164, 193, 64, 103, 17, 233,
214
+ // 146, 52, 155, 29, 235, 77, 59, 125
207
215
  // ]
208
216
  ```
209
217
 
@@ -289,20 +297,18 @@ defined by RFC4122
289
297
 
290
298
  ## ECMAScript Modules
291
299
 
292
- For usage in the browser `uuid` provides support for [ECMAScript
293
- Modules](https://www.ecma-international.org/ecma-262/6.0/#sec-modules) (ESM) that enable
294
- tree-shaking for bundlers, like [rollup.js](https://rollupjs.org/guide/en/#tree-shaking)
295
- ([example](./examples/browser-rollup/)) and [webpack](https://webpack.js.org/guides/tree-shaking/)
296
- ([example](./examples/browser-webpack/)).
300
+ This library comes with [ECMAScript
301
+ Modules](https://www.ecma-international.org/ecma-262/6.0/#sec-modules) (ESM) support for Node.js
302
+ versions that support it ([example](./examples/node-esmodules/)) as well as bundlers like
303
+ [rollup.js](https://rollupjs.org/guide/en/#tree-shaking) ([example](./examples/browser-rollup/))
304
+ and [webpack](https://webpack.js.org/guides/tree-shaking/)
305
+ ([example](./examples/browser-webpack/)) (targeting both, Node.js and browser environments).
297
306
 
298
307
  ```javascript
299
308
  import { v4 as uuidv4 } from 'uuid';
300
309
  uuidv4(); // ⇨ '1b9d6bcd-bbfd-4b2d-9b5d-ab8dfbbd4bed'
301
310
  ```
302
311
 
303
- There is experimental native ESM support for [the browser](./examples/browser-esmodules/) but it
304
- should not be considered ready for production use and may change or disappear in future releases.
305
-
306
312
  To run the examples you must first create a dist build of this library in the module root:
307
313
 
308
314
  ```
@@ -357,6 +363,33 @@ import { v4 as uuidv4 } from 'uuid';
357
363
  Workers](https://caniuse.com/#feat=cryptography) and we are not aware of a polyfill (let us know if
358
364
  you find one, please).
359
365
 
366
+ ## Upgrading From uuid\@7
367
+
368
+ ### Only Named Exports Supported When Using with Node.js ESM
369
+
370
+ uuid\@7 did not come with native ECMAScript Module (ESM) support for Node.js. Importing it in
371
+ Node.js ESM consequently imported the CommonJS source with a default export. This library now comes
372
+ with true Node.js ESM support and only provides named exports.
373
+
374
+ Instead of doing:
375
+
376
+ ```javascript
377
+ import uuid from 'uuid';
378
+ uuid.v4();
379
+ ```
380
+
381
+ you will now have to use the named exports:
382
+
383
+ ```javascript
384
+ import { v4 as uuidv4 } from 'uuid';
385
+ uuidv4();
386
+ ```
387
+
388
+ ### Deep Requires No Longer Supported
389
+
390
+ Deep requires like `require('uuid/v4')` [which have been deprecated in
391
+ uuid\@7](#deep-requires-now-deprecated) are no longer supported.
392
+
360
393
  ## Upgrading From uuid\@3
361
394
 
362
395
  "_Wait... what happened to uuid\@4 - uuid\@6?!?_"
@@ -9,19 +9,19 @@ exports.default = void 0;
9
9
  * Convert array of 16 byte values to UUID string format of the form:
10
10
  * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
11
11
  */
12
- var byteToHex = [];
12
+ const byteToHex = [];
13
13
 
14
- for (var i = 0; i < 256; ++i) {
15
- byteToHex[i] = (i + 0x100).toString(16).substr(1);
14
+ for (let i = 0; i < 256; ++i) {
15
+ byteToHex.push((i + 0x100).toString(16).substr(1));
16
16
  }
17
17
 
18
18
  function bytesToUuid(buf, offset) {
19
- var i = offset || 0;
20
- var bth = byteToHex; // join used to fix memory issue caused by concatenation: https://bugs.chromium.org/p/v8/issues/detail?id=3175#c4
19
+ const i = offset || 0;
20
+ const bth = byteToHex; // Note: Be careful editing this code! It's been tuned for performance
21
+ // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434
21
22
 
22
- return [bth[buf[i++]], bth[buf[i++]], bth[buf[i++]], bth[buf[i++]], '-', bth[buf[i++]], bth[buf[i++]], '-', bth[buf[i++]], bth[buf[i++]], '-', bth[buf[i++]], bth[buf[i++]], '-', bth[buf[i++]], bth[buf[i++]], bth[buf[i++]], bth[buf[i++]], bth[buf[i++]], bth[buf[i++]]].join('');
23
+ return (bth[buf[i + 0]] + bth[buf[i + 1]] + bth[buf[i + 2]] + bth[buf[i + 3]] + '-' + bth[buf[i + 4]] + bth[buf[i + 5]] + '-' + bth[buf[i + 6]] + bth[buf[i + 7]] + '-' + bth[buf[i + 8]] + bth[buf[i + 9]] + '-' + bth[buf[i + 10]] + bth[buf[i + 11]] + bth[buf[i + 12]] + bth[buf[i + 13]] + bth[buf[i + 14]] + bth[buf[i + 15]]).toLowerCase();
23
24
  }
24
25
 
25
26
  var _default = bytesToUuid;
26
- exports.default = _default;
27
- module.exports = exports.default;
27
+ exports.default = _default;
@@ -5,14 +5,15 @@
5
5
  var byteToHex = [];
6
6
 
7
7
  for (var i = 0; i < 256; ++i) {
8
- byteToHex[i] = (i + 0x100).toString(16).substr(1);
8
+ byteToHex.push((i + 0x100).toString(16).substr(1));
9
9
  }
10
10
 
11
11
  function bytesToUuid(buf, offset) {
12
12
  var i = offset || 0;
13
- var bth = byteToHex; // join used to fix memory issue caused by concatenation: https://bugs.chromium.org/p/v8/issues/detail?id=3175#c4
13
+ var bth = byteToHex; // Note: Be careful editing this code! It's been tuned for performance
14
+ // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434
14
15
 
15
- return [bth[buf[i++]], bth[buf[i++]], bth[buf[i++]], bth[buf[i++]], '-', bth[buf[i++]], bth[buf[i++]], '-', bth[buf[i++]], bth[buf[i++]], '-', bth[buf[i++]], bth[buf[i++]], '-', bth[buf[i++]], bth[buf[i++]], bth[buf[i++]], bth[buf[i++]], bth[buf[i++]], bth[buf[i++]]].join('');
16
+ return (bth[buf[i + 0]] + bth[buf[i + 1]] + bth[buf[i + 2]] + bth[buf[i + 3]] + '-' + bth[buf[i + 4]] + bth[buf[i + 5]] + '-' + bth[buf[i + 6]] + bth[buf[i + 7]] + '-' + bth[buf[i + 8]] + bth[buf[i + 9]] + '-' + bth[buf[i + 10]] + bth[buf[i + 11]] + bth[buf[i + 12]] + bth[buf[i + 13]] + bth[buf[i + 14]] + bth[buf[i + 15]]).toLowerCase();
16
17
  }
17
18
 
18
19
  export default bytesToUuid;
@@ -19,12 +19,12 @@
19
19
  * See http://pajhome.org.uk/crypt/md5 for more info.
20
20
  */
21
21
  function md5(bytes) {
22
- if (typeof bytes == 'string') {
22
+ if (typeof bytes === 'string') {
23
23
  var msg = unescape(encodeURIComponent(bytes)); // UTF8 escape
24
24
 
25
- bytes = new Array(msg.length);
25
+ bytes = new Uint8Array(msg.length);
26
26
 
27
- for (var i = 0; i < msg.length; i++) {
27
+ for (var i = 0; i < msg.length; ++i) {
28
28
  bytes[i] = msg.charCodeAt(i);
29
29
  }
30
30
  }
@@ -37,21 +37,26 @@ function md5(bytes) {
37
37
 
38
38
 
39
39
  function md5ToHexEncodedArray(input) {
40
- var i;
41
- var x;
42
40
  var output = [];
43
41
  var length32 = input.length * 32;
44
42
  var hexTab = '0123456789abcdef';
45
- var hex;
46
43
 
47
- for (i = 0; i < length32; i += 8) {
48
- x = input[i >> 5] >>> i % 32 & 0xff;
49
- hex = parseInt(hexTab.charAt(x >>> 4 & 0x0f) + hexTab.charAt(x & 0x0f), 16);
44
+ for (var i = 0; i < length32; i += 8) {
45
+ var x = input[i >> 5] >>> i % 32 & 0xff;
46
+ var hex = parseInt(hexTab.charAt(x >>> 4 & 0x0f) + hexTab.charAt(x & 0x0f), 16);
50
47
  output.push(hex);
51
48
  }
52
49
 
53
50
  return output;
54
51
  }
52
+ /**
53
+ * Calculate output length with padding and bit length
54
+ */
55
+
56
+
57
+ function getOutputLength(inputLength8) {
58
+ return (inputLength8 + 64 >>> 9 << 4) + 14 + 1;
59
+ }
55
60
  /*
56
61
  * Calculate the MD5 of an array of little-endian words, and a bit length.
57
62
  */
@@ -60,22 +65,17 @@ function md5ToHexEncodedArray(input) {
60
65
  function wordsToMd5(x, len) {
61
66
  /* append padding */
62
67
  x[len >> 5] |= 0x80 << len % 32;
63
- x[(len + 64 >>> 9 << 4) + 14] = len;
64
- var i;
65
- var olda;
66
- var oldb;
67
- var oldc;
68
- var oldd;
68
+ x[getOutputLength(len) - 1] = len;
69
69
  var a = 1732584193;
70
70
  var b = -271733879;
71
71
  var c = -1732584194;
72
72
  var d = 271733878;
73
73
 
74
- for (i = 0; i < x.length; i += 16) {
75
- olda = a;
76
- oldb = b;
77
- oldc = c;
78
- oldd = d;
74
+ for (var i = 0; i < x.length; i += 16) {
75
+ var olda = a;
76
+ var oldb = b;
77
+ var oldc = c;
78
+ var oldd = d;
79
79
  a = md5ff(a, b, c, d, x[i], 7, -680876936);
80
80
  d = md5ff(d, a, b, c, x[i + 1], 12, -389564586);
81
81
  c = md5ff(c, d, a, b, x[i + 2], 17, 606105819);
@@ -155,17 +155,14 @@ function wordsToMd5(x, len) {
155
155
 
156
156
 
157
157
  function bytesToWords(input) {
158
- var i;
159
- var output = [];
160
- output[(input.length >> 2) - 1] = undefined;
161
-
162
- for (i = 0; i < output.length; i += 1) {
163
- output[i] = 0;
158
+ if (input.length === 0) {
159
+ return [];
164
160
  }
165
161
 
166
162
  var length8 = input.length * 8;
163
+ var output = new Uint32Array(getOutputLength(length8));
167
164
 
168
- for (i = 0; i < length8; i += 8) {
165
+ for (var i = 0; i < length8; i += 8) {
169
166
  output[i >> 5] |= (input[i / 8] & 0xff) << i % 32;
170
167
  }
171
168
 
@@ -3,9 +3,8 @@
3
3
  // generators (like Math.random()).
4
4
  // getRandomValues needs to be invoked in a context where "this" is a Crypto implementation. Also,
5
5
  // find the complete implementation of crypto (msCrypto) on IE11.
6
- var getRandomValues = typeof crypto != 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto) || typeof msCrypto != 'undefined' && typeof msCrypto.getRandomValues == 'function' && msCrypto.getRandomValues.bind(msCrypto);
7
- var rnds8 = new Uint8Array(16); // eslint-disable-line no-undef
8
-
6
+ var getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto) || typeof msCrypto !== 'undefined' && typeof msCrypto.getRandomValues === 'function' && msCrypto.getRandomValues.bind(msCrypto);
7
+ var rnds8 = new Uint8Array(16);
9
8
  export default function rng() {
10
9
  if (!getRandomValues) {
11
10
  throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');
@@ -24,13 +24,13 @@ function sha1(bytes) {
24
24
  var K = [0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6];
25
25
  var H = [0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0];
26
26
 
27
- if (typeof bytes == 'string') {
27
+ if (typeof bytes === 'string') {
28
28
  var msg = unescape(encodeURIComponent(bytes)); // UTF8 escape
29
29
 
30
- bytes = new Array(msg.length);
30
+ bytes = [];
31
31
 
32
- for (var i = 0; i < msg.length; i++) {
33
- bytes[i] = msg.charCodeAt(i);
32
+ for (var i = 0; i < msg.length; ++i) {
33
+ bytes.push(msg.charCodeAt(i));
34
34
  }
35
35
  }
36
36
 
@@ -39,27 +39,29 @@ function sha1(bytes) {
39
39
  var N = Math.ceil(l / 16);
40
40
  var M = new Array(N);
41
41
 
42
- for (var i = 0; i < N; i++) {
43
- M[i] = new Array(16);
42
+ for (var _i = 0; _i < N; ++_i) {
43
+ var arr = new Uint32Array(16);
44
44
 
45
- for (var j = 0; j < 16; j++) {
46
- M[i][j] = bytes[i * 64 + j * 4] << 24 | bytes[i * 64 + j * 4 + 1] << 16 | bytes[i * 64 + j * 4 + 2] << 8 | bytes[i * 64 + j * 4 + 3];
45
+ for (var j = 0; j < 16; ++j) {
46
+ arr[j] = bytes[_i * 64 + j * 4] << 24 | bytes[_i * 64 + j * 4 + 1] << 16 | bytes[_i * 64 + j * 4 + 2] << 8 | bytes[_i * 64 + j * 4 + 3];
47
47
  }
48
+
49
+ M[_i] = arr;
48
50
  }
49
51
 
50
52
  M[N - 1][14] = (bytes.length - 1) * 8 / Math.pow(2, 32);
51
53
  M[N - 1][14] = Math.floor(M[N - 1][14]);
52
54
  M[N - 1][15] = (bytes.length - 1) * 8 & 0xffffffff;
53
55
 
54
- for (var i = 0; i < N; i++) {
55
- var W = new Array(80);
56
+ for (var _i2 = 0; _i2 < N; ++_i2) {
57
+ var W = new Uint32Array(80);
56
58
 
57
- for (var t = 0; t < 16; t++) {
58
- W[t] = M[i][t];
59
+ for (var t = 0; t < 16; ++t) {
60
+ W[t] = M[_i2][t];
59
61
  }
60
62
 
61
- for (var t = 16; t < 80; t++) {
62
- W[t] = ROTL(W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16], 1);
63
+ for (var _t = 16; _t < 80; ++_t) {
64
+ W[_t] = ROTL(W[_t - 3] ^ W[_t - 8] ^ W[_t - 14] ^ W[_t - 16], 1);
63
65
  }
64
66
 
65
67
  var a = H[0];
@@ -68,9 +70,9 @@ function sha1(bytes) {
68
70
  var d = H[3];
69
71
  var e = H[4];
70
72
 
71
- for (var t = 0; t < 80; t++) {
72
- var s = Math.floor(t / 20);
73
- var T = ROTL(a, 5) + f(s, b, c, d) + e + K[s] + W[t] >>> 0;
73
+ for (var _t2 = 0; _t2 < 80; ++_t2) {
74
+ var s = Math.floor(_t2 / 20);
75
+ var T = ROTL(a, 5) + f(s, b, c, d) + e + K[s] + W[_t2] >>> 0;
74
76
  e = d;
75
77
  d = c;
76
78
  c = ROTL(b, 30) >>> 0;
@@ -39,7 +39,7 @@ function v1(options, buf, offset) {
39
39
  // (100-nanoseconds offset from msecs) since unix epoch, 1970-01-01 00:00.
40
40
 
41
41
 
42
- var msecs = options.msecs !== undefined ? options.msecs : new Date().getTime(); // Per 4.2.1.2, use count of uuid's generated during the current clock
42
+ var msecs = options.msecs !== undefined ? options.msecs : Date.now(); // Per 4.2.1.2, use count of uuid's generated during the current clock
43
43
  // cycle to simulate higher resolution clock
44
44
 
45
45
  var nsecs = options.nsecs !== undefined ? options.nsecs : _lastNSecs + 1; // Time since last uuid creation (in msecs)
@@ -89,7 +89,7 @@ function v1(options, buf, offset) {
89
89
  b[i + n] = node[n];
90
90
  }
91
91
 
92
- return buf ? buf : bytesToUuid(b);
92
+ return buf || bytesToUuid(b);
93
93
  }
94
94
 
95
95
  export default v1;
@@ -12,10 +12,10 @@ function uuidToBytes(uuid) {
12
12
  function stringToBytes(str) {
13
13
  str = unescape(encodeURIComponent(str)); // UTF8 escape
14
14
 
15
- var bytes = new Array(str.length);
15
+ var bytes = [];
16
16
 
17
- for (var i = 0; i < str.length; i++) {
18
- bytes[i] = str.charCodeAt(i);
17
+ for (var i = 0; i < str.length; ++i) {
18
+ bytes.push(str.charCodeAt(i));
19
19
  }
20
20
 
21
21
  return bytes;
@@ -24,12 +24,19 @@ function stringToBytes(str) {
24
24
  export var DNS = '6ba7b810-9dad-11d1-80b4-00c04fd430c8';
25
25
  export var URL = '6ba7b811-9dad-11d1-80b4-00c04fd430c8';
26
26
  export default function (name, version, hashfunc) {
27
- var generateUUID = function generateUUID(value, namespace, buf, offset) {
27
+ function generateUUID(value, namespace, buf, offset) {
28
28
  var off = buf && offset || 0;
29
- if (typeof value == 'string') value = stringToBytes(value);
30
- if (typeof namespace == 'string') namespace = uuidToBytes(namespace);
31
- if (!Array.isArray(value)) throw TypeError('value must be an array of bytes');
32
- if (!Array.isArray(namespace) || namespace.length !== 16) throw TypeError('namespace must be uuid string or an Array of 16 byte values'); // Per 4.3
29
+ if (typeof value === 'string') value = stringToBytes(value);
30
+ if (typeof namespace === 'string') namespace = uuidToBytes(namespace);
31
+
32
+ if (!Array.isArray(value)) {
33
+ throw TypeError('value must be an array of bytes');
34
+ }
35
+
36
+ if (!Array.isArray(namespace) || namespace.length !== 16) {
37
+ throw TypeError('namespace must be uuid string or an Array of 16 byte values');
38
+ } // Per 4.3
39
+
33
40
 
34
41
  var bytes = hashfunc(namespace.concat(value));
35
42
  bytes[6] = bytes[6] & 0x0f | version;
@@ -42,11 +49,11 @@ export default function (name, version, hashfunc) {
42
49
  }
43
50
 
44
51
  return buf || bytesToUuid(bytes);
45
- }; // Function#name is not settable on some platforms (#270)
52
+ } // Function#name is not settable on some platforms (#270)
46
53
 
47
54
 
48
55
  try {
49
- generateUUID.name = name;
56
+ generateUUID.name = name; // eslint-disable-next-line no-empty
50
57
  } catch (err) {} // For CommonJS default export support
51
58
 
52
59
 
@@ -2,10 +2,8 @@ import rng from './rng.js';
2
2
  import bytesToUuid from './bytesToUuid.js';
3
3
 
4
4
  function v4(options, buf, offset) {
5
- var i = buf && offset || 0;
6
-
7
- if (typeof options == 'string') {
8
- buf = options === 'binary' ? new Array(16) : null;
5
+ if (typeof options === 'string') {
6
+ buf = options === 'binary' ? new Uint8Array(16) : null;
9
7
  options = null;
10
8
  }
11
9
 
@@ -16,12 +14,16 @@ function v4(options, buf, offset) {
16
14
  rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided
17
15
 
18
16
  if (buf) {
19
- for (var ii = 0; ii < 16; ++ii) {
20
- buf[i + ii] = rnds[ii];
17
+ var start = offset || 0;
18
+
19
+ for (var i = 0; i < 16; ++i) {
20
+ buf[start + i] = rnds[i];
21
21
  }
22
+
23
+ return buf;
22
24
  }
23
25
 
24
- return buf || bytesToUuid(rnds);
26
+ return bytesToUuid(rnds);
25
27
  }
26
28
 
27
29
  export default v4;
@@ -2,17 +2,18 @@
2
2
  * Convert array of 16 byte values to UUID string format of the form:
3
3
  * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
4
4
  */
5
- var byteToHex = [];
5
+ const byteToHex = [];
6
6
 
7
- for (var i = 0; i < 256; ++i) {
8
- byteToHex[i] = (i + 0x100).toString(16).substr(1);
7
+ for (let i = 0; i < 256; ++i) {
8
+ byteToHex.push((i + 0x100).toString(16).substr(1));
9
9
  }
10
10
 
11
11
  function bytesToUuid(buf, offset) {
12
- var i = offset || 0;
13
- var bth = byteToHex; // join used to fix memory issue caused by concatenation: https://bugs.chromium.org/p/v8/issues/detail?id=3175#c4
12
+ const i = offset || 0;
13
+ const bth = byteToHex; // Note: Be careful editing this code! It's been tuned for performance
14
+ // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434
14
15
 
15
- return [bth[buf[i++]], bth[buf[i++]], bth[buf[i++]], bth[buf[i++]], '-', bth[buf[i++]], bth[buf[i++]], '-', bth[buf[i++]], bth[buf[i++]], '-', bth[buf[i++]], bth[buf[i++]], '-', bth[buf[i++]], bth[buf[i++]], bth[buf[i++]], bth[buf[i++]], bth[buf[i++]], bth[buf[i++]]].join('');
16
+ return (bth[buf[i + 0]] + bth[buf[i + 1]] + bth[buf[i + 2]] + bth[buf[i + 3]] + '-' + bth[buf[i + 4]] + bth[buf[i + 5]] + '-' + bth[buf[i + 6]] + bth[buf[i + 7]] + '-' + bth[buf[i + 8]] + bth[buf[i + 9]] + '-' + bth[buf[i + 10]] + bth[buf[i + 11]] + bth[buf[i + 12]] + bth[buf[i + 13]] + bth[buf[i + 14]] + bth[buf[i + 15]]).toLowerCase();
16
17
  }
17
18
 
18
19
  export default bytesToUuid;
@@ -1,4 +1,5 @@
1
1
  import crypto from 'crypto';
2
+ const rnds8 = new Uint8Array(16);
2
3
  export default function rng() {
3
- return crypto.randomBytes(16);
4
+ return crypto.randomFillSync(rnds8);
4
5
  }