summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/uuid/v1.js
diff options
context:
space:
mode:
Diffstat (limited to 'deps/npm/node_modules/uuid/v1.js')
-rw-r--r--deps/npm/node_modules/uuid/v1.js37
1 files changed, 14 insertions, 23 deletions
diff --git a/deps/npm/node_modules/uuid/v1.js b/deps/npm/node_modules/uuid/v1.js
index d84c0f4523..613f67e2e8 100644
--- a/deps/npm/node_modules/uuid/v1.js
+++ b/deps/npm/node_modules/uuid/v1.js
@@ -6,12 +6,20 @@ var bytesToUuid = require('./lib/bytesToUuid');
// Inspired by https://github.com/LiosK/UUID.js
// and http://docs.python.org/library/uuid.html
-var _nodeId;
-var _clockseq;
+// random #'s we need to init node and clockseq
+var _seedBytes = rng();
+
+// Per 4.5, create and 48-bit node id, (47 random bits + multicast bit = 1)
+var _nodeId = [
+ _seedBytes[0] | 0x01,
+ _seedBytes[1], _seedBytes[2], _seedBytes[3], _seedBytes[4], _seedBytes[5]
+];
+
+// Per 4.2.2, randomize (14 bit) clockseq
+var _clockseq = (_seedBytes[6] << 8 | _seedBytes[7]) & 0x3fff;
// Previous uuid creation time
-var _lastMSecs = 0;
-var _lastNSecs = 0;
+var _lastMSecs = 0, _lastNSecs = 0;
// See https://github.com/broofa/node-uuid for API details
function v1(options, buf, offset) {
@@ -19,26 +27,8 @@ function v1(options, buf, offset) {
var b = buf || [];
options = options || {};
- var node = options.node || _nodeId;
- var clockseq = options.clockseq !== undefined ? options.clockseq : _clockseq;
- // node and clockseq need to be initialized to random values if they're not
- // specified. We do this lazily to minimize issues related to insufficient
- // system entropy. See #189
- if (node == null || clockseq == null) {
- var seedBytes = rng();
- if (node == null) {
- // Per 4.5, create and 48-bit node id, (47 random bits + multicast bit = 1)
- node = _nodeId = [
- seedBytes[0] | 0x01,
- seedBytes[1], seedBytes[2], seedBytes[3], seedBytes[4], seedBytes[5]
- ];
- }
- if (clockseq == null) {
- // Per 4.2.2, randomize (14 bit) clockseq
- clockseq = _clockseq = (seedBytes[6] << 8 | seedBytes[7]) & 0x3fff;
- }
- }
+ var clockseq = options.clockseq !== undefined ? options.clockseq : _clockseq;
// UUID timestamps are 100 nano-second units since the Gregorian epoch,
// (1582-10-15 00:00). JSNumbers aren't precise enough for this, so
@@ -99,6 +89,7 @@ function v1(options, buf, offset) {
b[i++] = clockseq & 0xff;
// `node`
+ var node = options.node || _nodeId;
for (var n = 0; n < 6; ++n) {
b[i + n] = node[n];
}