uuid 3.0.0 → 3.0.1
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/.npmignore +6 -0
- package/.travis.yml +1 -0
- package/HISTORY.md +4 -0
- package/LICENSE.md +1 -1
- package/README.md +19 -17
- package/index.js +8 -0
- package/lib/bytesToUuid.js +23 -0
- package/lib/rng-browser.js +11 -10
- package/lib/rng.js +7 -1
- package/package.json +1 -2
- package/{uuid.js → v1.js} +5 -59
- package/v4.js +29 -0
package/.npmignore
CHANGED
package/.travis.yml
CHANGED
package/HISTORY.md
CHANGED
package/LICENSE.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
The MIT License (MIT)
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) 2010-2016 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
|
@@ -7,34 +7,40 @@ Features:
|
|
|
7
7
|
* Generate RFC4122 version 1 or version 4 UUIDs
|
|
8
8
|
* Runs in node.js and browsers
|
|
9
9
|
* Cryptographically strong random number generation on supporting platforms
|
|
10
|
-
* Small footprint (Want something smaller? [Check this out](https://gist.github.com/982883)
|
|
10
|
+
* Small footprint (Want something smaller? [Check this out](https://gist.github.com/982883)!)
|
|
11
11
|
|
|
12
|
-
## Quickstart -
|
|
12
|
+
## Quickstart - CommonJS (Recommended)
|
|
13
13
|
|
|
14
14
|
```shell
|
|
15
15
|
npm install uuid
|
|
16
16
|
```
|
|
17
17
|
|
|
18
18
|
```javascript
|
|
19
|
-
|
|
19
|
+
// Generate a v1 UUID (time-based)
|
|
20
|
+
const uuidV1 = require('uuid/v1');
|
|
21
|
+
uuidV1(); // -> '6c84fb90-12c4-11e1-840d-7b25c5ee775a'
|
|
20
22
|
|
|
21
|
-
// Generate a v4 (random)
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
// Generate a v1 (time-based) id
|
|
25
|
-
uuid.v1(); // -> '6c84fb90-12c4-11e1-840d-7b25c5ee775a'
|
|
23
|
+
// Generate a v4 UUID (random)
|
|
24
|
+
const uuidV4 = require('uuid/v4');
|
|
25
|
+
uuidV4(); // -> '110ec58a-a0f2-4ac4-8393-c866d813b8d1'
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
-
## Quickstart -
|
|
29
|
-
|
|
30
|
-
** Not recommende for production or even semi-production use. Use a bundling tool instead (i.e. webpack, browserify, rollup, etc)**
|
|
28
|
+
## Quickstart - Pre-packaged for browsers (Not recommended)
|
|
31
29
|
|
|
32
|
-
[wzrd.in](https://github.com/jfhbrook/wzrd.in)
|
|
30
|
+
Browser-ready versions of this module are available via [wzrd.in](https://github.com/jfhbrook/wzrd.in).
|
|
33
31
|
|
|
34
32
|
```html
|
|
35
|
-
<script src="
|
|
33
|
+
<script src="http://wzrd.in/standalone/uuid@latest"></script>
|
|
34
|
+
|
|
35
|
+
<script>
|
|
36
|
+
uuid.v1(); // -> v1 UUID
|
|
37
|
+
uuid.v4(); // -> v4 UUID
|
|
38
|
+
</script>
|
|
36
39
|
```
|
|
37
40
|
|
|
41
|
+
(Note: Do not do this in production. Just don't. wzrd.in is a great service, but if you're deploying a "real" service you should be using a packaging tool like browserify or webpack. If you do go this route you would be well advised to link to a specific version instead of `uuid@latest` to avoid having your code break when we roll out breaking changes.)
|
|
42
|
+
|
|
43
|
+
|
|
38
44
|
## API
|
|
39
45
|
|
|
40
46
|
### uuid(...)
|
|
@@ -79,10 +85,6 @@ Example: In-place generation of two binary IDs
|
|
|
79
85
|
const arr = new Array(32); // -> []
|
|
80
86
|
uuid.v1(null, arr, 0); // -> [02 a2 ce 90 14 32 11 e1 85 58 0b 48 8e 4f c1 15]
|
|
81
87
|
uuid.v1(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]
|
|
82
|
-
|
|
83
|
-
// Optionally use uuid.unparse() to get stringify the ids
|
|
84
|
-
uuid.unparse(buffer); // -> '02a2ce90-1432-11e1-8558-0b488e4fc115'
|
|
85
|
-
uuid.unparse(buffer, 16) // -> '02a31cb0-1432-11e1-8558-0b488e4fc115'
|
|
86
88
|
```
|
|
87
89
|
|
|
88
90
|
### uuid.v4([`options` [, `buffer` [, `offset`]]])
|
package/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert array of 16 byte values to UUID string format of the form:
|
|
3
|
+
* XXXXXXXX-XXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
|
|
4
|
+
*/
|
|
5
|
+
var byteToHex = [];
|
|
6
|
+
for (var i = 0; i < 256; ++i) {
|
|
7
|
+
byteToHex[i] = (i + 0x100).toString(16).substr(1);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function bytesToUuid(buf, offset) {
|
|
11
|
+
var i = offset || 0;
|
|
12
|
+
var bth = byteToHex;
|
|
13
|
+
return bth[buf[i++]] + bth[buf[i++]] +
|
|
14
|
+
bth[buf[i++]] + bth[buf[i++]] + '-' +
|
|
15
|
+
bth[buf[i++]] + bth[buf[i++]] + '-' +
|
|
16
|
+
bth[buf[i++]] + bth[buf[i++]] + '-' +
|
|
17
|
+
bth[buf[i++]] + bth[buf[i++]] + '-' +
|
|
18
|
+
bth[buf[i++]] + bth[buf[i++]] +
|
|
19
|
+
bth[buf[i++]] + bth[buf[i++]] +
|
|
20
|
+
bth[buf[i++]] + bth[buf[i++]];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
module.exports = bytesToUuid;
|
package/lib/rng-browser.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
// Unique ID creation requires a high quality random # generator. In the
|
|
2
|
+
// browser this is a little complicated due to unknown quality of Math.random()
|
|
3
|
+
// and inconsistent support for the `crypto` API. We do the best we can via
|
|
4
|
+
// feature-detection
|
|
2
5
|
var rng;
|
|
3
6
|
|
|
4
7
|
var crypto = global.crypto || global.msCrypto; // for IE 11
|
|
5
8
|
if (crypto && crypto.getRandomValues) {
|
|
6
|
-
// WHATWG crypto
|
|
7
|
-
|
|
8
|
-
var _rnds8 = new Uint8Array(16);
|
|
9
|
+
// WHATWG crypto RNG - http://wiki.whatwg.org/wiki/Crypto
|
|
10
|
+
var rnds8 = new Uint8Array(16);
|
|
9
11
|
rng = function whatwgRNG() {
|
|
10
|
-
crypto.getRandomValues(
|
|
11
|
-
return
|
|
12
|
+
crypto.getRandomValues(rnds8);
|
|
13
|
+
return rnds8;
|
|
12
14
|
};
|
|
13
15
|
}
|
|
14
16
|
|
|
@@ -17,16 +19,15 @@ if (!rng) {
|
|
|
17
19
|
//
|
|
18
20
|
// If all else fails, use Math.random(). It's fast, but is of unspecified
|
|
19
21
|
// quality.
|
|
20
|
-
var
|
|
22
|
+
var rnds = new Array(16);
|
|
21
23
|
rng = function() {
|
|
22
24
|
for (var i = 0, r; i < 16; i++) {
|
|
23
25
|
if ((i & 0x03) === 0) r = Math.random() * 0x100000000;
|
|
24
|
-
|
|
26
|
+
rnds[i] = r >>> ((i & 0x03) << 3) & 0xff;
|
|
25
27
|
}
|
|
26
28
|
|
|
27
|
-
return
|
|
29
|
+
return rnds;
|
|
28
30
|
};
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
module.exports = rng;
|
|
32
|
-
|
package/lib/rng.js
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
+
// Unique ID creation requires a high quality random # generator. In node.js
|
|
2
|
+
// this is prett straight-forward - we use the crypto API.
|
|
3
|
+
|
|
1
4
|
var rb = require('crypto').randomBytes;
|
|
2
|
-
|
|
5
|
+
|
|
6
|
+
function rng() {
|
|
3
7
|
return rb(16);
|
|
4
8
|
};
|
|
9
|
+
|
|
10
|
+
module.exports = rng;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "uuid",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"description": "RFC4122 (v1 and v4) generator",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"uuid",
|
|
@@ -8,7 +8,6 @@
|
|
|
8
8
|
"rfc4122"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"main": "./uuid.js",
|
|
12
11
|
"bin": {
|
|
13
12
|
"uuid": "./bin/uuid"
|
|
14
13
|
},
|
package/{uuid.js → v1.js}
RENAMED
|
@@ -1,28 +1,8 @@
|
|
|
1
1
|
// Unique ID creation requires a high quality random # generator. We feature
|
|
2
2
|
// detect to determine the best RNG source, normalizing to a function that
|
|
3
3
|
// returns 128-bits of randomness, since that's what's usually required
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
// Maps for number <-> hex string conversion
|
|
7
|
-
var _byteToHex = [];
|
|
8
|
-
var _hexToByte = {};
|
|
9
|
-
for (var i = 0; i < 256; ++i) {
|
|
10
|
-
_byteToHex[i] = (i + 0x100).toString(16).substr(1);
|
|
11
|
-
_hexToByte[_byteToHex[i]] = i;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function buff_to_string(buf, offset) {
|
|
15
|
-
var i = offset || 0;
|
|
16
|
-
var bth = _byteToHex;
|
|
17
|
-
return bth[buf[i++]] + bth[buf[i++]] +
|
|
18
|
-
bth[buf[i++]] + bth[buf[i++]] + '-' +
|
|
19
|
-
bth[buf[i++]] + bth[buf[i++]] + '-' +
|
|
20
|
-
bth[buf[i++]] + bth[buf[i++]] + '-' +
|
|
21
|
-
bth[buf[i++]] + bth[buf[i++]] + '-' +
|
|
22
|
-
bth[buf[i++]] + bth[buf[i++]] +
|
|
23
|
-
bth[buf[i++]] + bth[buf[i++]] +
|
|
24
|
-
bth[buf[i++]] + bth[buf[i++]];
|
|
25
|
-
}
|
|
4
|
+
var rng = require('./lib/rng');
|
|
5
|
+
var bytesToUuid = require('./lib/bytesToUuid');
|
|
26
6
|
|
|
27
7
|
// **`v1()` - Generate time-based UUID**
|
|
28
8
|
//
|
|
@@ -30,7 +10,7 @@ function buff_to_string(buf, offset) {
|
|
|
30
10
|
// and http://docs.python.org/library/uuid.html
|
|
31
11
|
|
|
32
12
|
// random #'s we need to init node and clockseq
|
|
33
|
-
var _seedBytes =
|
|
13
|
+
var _seedBytes = rng();
|
|
34
14
|
|
|
35
15
|
// Per 4.5, create and 48-bit node id, (47 random bits + multicast bit = 1)
|
|
36
16
|
var _nodeId = [
|
|
@@ -117,41 +97,7 @@ function v1(options, buf, offset) {
|
|
|
117
97
|
b[i + n] = node[n];
|
|
118
98
|
}
|
|
119
99
|
|
|
120
|
-
return buf ? buf :
|
|
100
|
+
return buf ? buf : bytesToUuid(b);
|
|
121
101
|
}
|
|
122
102
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
// See https://github.com/broofa/node-uuid for API details
|
|
126
|
-
function v4(options, buf, offset) {
|
|
127
|
-
// Deprecated - 'format' argument, as supported in v1.2
|
|
128
|
-
var i = buf && offset || 0;
|
|
129
|
-
|
|
130
|
-
if (typeof(options) == 'string') {
|
|
131
|
-
buf = options == 'binary' ? new Array(16) : null;
|
|
132
|
-
options = null;
|
|
133
|
-
}
|
|
134
|
-
options = options || {};
|
|
135
|
-
|
|
136
|
-
var rnds = options.random || (options.rng || _rng)();
|
|
137
|
-
|
|
138
|
-
// Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
|
|
139
|
-
rnds[6] = (rnds[6] & 0x0f) | 0x40;
|
|
140
|
-
rnds[8] = (rnds[8] & 0x3f) | 0x80;
|
|
141
|
-
|
|
142
|
-
// Copy bytes to buffer, if provided
|
|
143
|
-
if (buf) {
|
|
144
|
-
for (var ii = 0; ii < 16; ++ii) {
|
|
145
|
-
buf[i + ii] = rnds[ii];
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
return buf || buff_to_string(rnds);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
// Export public API
|
|
153
|
-
var uuid = v4;
|
|
154
|
-
uuid.v1 = v1;
|
|
155
|
-
uuid.v4 = v4;
|
|
156
|
-
|
|
157
|
-
module.exports = uuid;
|
|
103
|
+
module.exports = v1;
|
package/v4.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
var rng = require('./lib/rng');
|
|
2
|
+
var bytesToUuid = require('./lib/bytesToUuid');
|
|
3
|
+
|
|
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;
|
|
9
|
+
options = null;
|
|
10
|
+
}
|
|
11
|
+
options = options || {};
|
|
12
|
+
|
|
13
|
+
var rnds = options.random || (options.rng || rng)();
|
|
14
|
+
|
|
15
|
+
// Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
|
|
16
|
+
rnds[6] = (rnds[6] & 0x0f) | 0x40;
|
|
17
|
+
rnds[8] = (rnds[8] & 0x3f) | 0x80;
|
|
18
|
+
|
|
19
|
+
// Copy bytes to buffer, if provided
|
|
20
|
+
if (buf) {
|
|
21
|
+
for (var ii = 0; ii < 16; ++ii) {
|
|
22
|
+
buf[i + ii] = rnds[ii];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return buf || bytesToUuid(rnds);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
module.exports = v4;
|