uuid 3.1.0 → 3.3.2

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/lib/v35.js ADDED
@@ -0,0 +1,57 @@
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
+ // Function#name is not settable on some platforms (#270)
47
+ try {
48
+ generateUUID.name = name;
49
+ } catch (err) {
50
+ }
51
+
52
+ // Pre-defined namespaces, per Appendix C
53
+ generateUUID.DNS = '6ba7b810-9dad-11d1-80b4-00c04fd430c8';
54
+ generateUUID.URL = '6ba7b811-9dad-11d1-80b4-00c04fd430c8';
55
+
56
+ return generateUUID;
57
+ };
package/package.json CHANGED
@@ -1,7 +1,12 @@
1
1
  {
2
2
  "name": "uuid",
3
- "version": "3.1.0",
3
+ "version": "3.3.2",
4
4
  "description": "RFC4122 (v1, v4, and v5) UUIDs",
5
+ "commitlint": {
6
+ "extends": [
7
+ "@commitlint/config-conventional"
8
+ ]
9
+ },
5
10
  "keywords": [
6
11
  "uuid",
7
12
  "guid",
@@ -12,14 +17,25 @@
12
17
  "uuid": "./bin/uuid"
13
18
  },
14
19
  "devDependencies": {
15
- "mocha": "3.1.2"
20
+ "@commitlint/cli": "7.0.0",
21
+ "@commitlint/config-conventional": "7.0.1",
22
+ "eslint": "4.19.1",
23
+ "husky": "0.14.3",
24
+ "mocha": "5.2.0",
25
+ "runmd": "1.0.1",
26
+ "standard-version": "4.4.0"
16
27
  },
17
28
  "scripts": {
18
- "test": "mocha test/test.js"
29
+ "commitmsg": "commitlint -E GIT_PARAMS",
30
+ "test": "mocha test/test.js",
31
+ "md": "runmd --watch --output=README.md README_js.md",
32
+ "release": "standard-version",
33
+ "prepare": "runmd --output=README.md README_js.md"
19
34
  },
20
35
  "browser": {
21
36
  "./lib/rng.js": "./lib/rng-browser.js",
22
- "./lib/sha1.js": "./lib/sha1-browser.js"
37
+ "./lib/sha1.js": "./lib/sha1-browser.js",
38
+ "./lib/md5.js": "./lib/md5-browser.js"
23
39
  },
24
40
  "repository": {
25
41
  "type": "git",
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
-