uuid 2.0.2 → 3.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/misc/compare.js DELETED
@@ -1,62 +0,0 @@
1
- var assert = require('assert'),
2
- nodeuuid = require('../'),
3
- uuidjs = require('uuid-js'),
4
- util = require('util'),
5
- exec = require('child_process').exec,
6
- os = require('os');
7
-
8
- // On Mac Os X / macports there's only the ossp-uuid package that provides uuid
9
- // On Linux there's uuid-runtime which provides uuidgen
10
- var uuidCmd = os.type() === 'Darwin' ? 'uuid -1' : 'uuidgen -t';
11
-
12
- function compare(ids) {
13
- console.log(ids);
14
- for (var i = 0; i < ids.length; i++) {
15
- var id = ids[i].split('-');
16
- id = [id[2], id[1], id[0]].join('');
17
- ids[i] = id;
18
- }
19
- var sorted = ([].concat(ids)).sort();
20
-
21
- if (sorted.toString() !== ids.toString()) {
22
- console.log('Warning: sorted !== ids');
23
- } else {
24
- console.log('everything in order!');
25
- }
26
- }
27
-
28
- // Test time order of v1 uuids
29
- var ids = [];
30
- while (ids.length < 10e3) ids.push(nodeuuid.v1());
31
-
32
- var max = 10;
33
- console.log('node-uuid:');
34
- ids = [];
35
- for (var i = 0; i < max; i++) ids.push(nodeuuid.v1());
36
- compare(ids);
37
-
38
- console.log('');
39
- console.log('uuidjs:');
40
- ids = [];
41
- for (var i = 0; i < max; i++) ids.push(uuidjs.create(1).toString());
42
- compare(ids);
43
-
44
- console.log('');
45
- console.log('libuuid:');
46
- ids = [];
47
- var count = 0;
48
- var last = function() {
49
- compare(ids);
50
- }
51
- var cb = function(err, stdout, stderr) {
52
- ids.push(stdout.substring(0, stdout.length-1));
53
- count++;
54
- if (count < max) {
55
- return next();
56
- }
57
- last();
58
- };
59
- var next = function() {
60
- exec(uuidCmd, cb);
61
- };
62
- next();
package/misc/perf.js DELETED
@@ -1,102 +0,0 @@
1
- var assert = require('assert');
2
-
3
- var uuid = require('../');
4
-
5
- var log = console.log;
6
-
7
- var generators = {
8
- v1: uuid.v1,
9
- v4: uuid.v4
10
- };
11
-
12
- var UUID_FORMAT = {
13
- v1: /[0-9a-f]{8}-[0-9a-f]{4}-1[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/i,
14
- v4: /[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/i
15
- };
16
-
17
- var N = 1e4;
18
-
19
- // Get %'age an actual value differs from the ideal value
20
- function divergence(actual, ideal) {
21
- return Math.round(100*100*(actual - ideal)/ideal)/100;
22
- }
23
-
24
- function rate(msg, t) {
25
- log(msg + ': ' + (N / (Date.now() - t) * 1e3 | 0) + ' uuids\/second');
26
- }
27
-
28
- for (var version in generators) {
29
- var counts = {}, max = 0;
30
- var generator = generators[version];
31
- var format = UUID_FORMAT[version];
32
-
33
- log('\nSanity check ' + N + ' ' + version + ' uuids');
34
- for (var i = 0, ok = 0; i < N; i++) {
35
- id = generator();
36
- if (!format.test(id)) {
37
- throw Error(id + ' is not a valid UUID string');
38
- }
39
-
40
- if (id != uuid.unparse(uuid.parse(id))) {
41
- assert(fail, id + ' is not a valid id');
42
- }
43
-
44
- // Count digits for our randomness check
45
- if (version == 'v4') {
46
- var digits = id.replace(/-/g, '').split('');
47
- for (var j = digits.length-1; j >= 0; j--) {
48
- var c = digits[j];
49
- max = Math.max(max, counts[c] = (counts[c] || 0) + 1);
50
- }
51
- }
52
- }
53
-
54
- // Check randomness for v4 UUIDs
55
- if (version == 'v4') {
56
- // Limit that we get worried about randomness. (Purely empirical choice, this!)
57
- var limit = 2*100*Math.sqrt(1/N);
58
-
59
- log('\nChecking v4 randomness. Distribution of Hex Digits (% deviation from ideal)');
60
-
61
- for (var i = 0; i < 16; i++) {
62
- var c = i.toString(16);
63
- var bar = '', n = counts[c], p = Math.round(n/max*100|0);
64
-
65
- // 1-3,5-8, and D-F: 1:16 odds over 30 digits
66
- var ideal = N*30/16;
67
- if (i == 4) {
68
- // 4: 1:1 odds on 1 digit, plus 1:16 odds on 30 digits
69
- ideal = N*(1 + 30/16);
70
- } else if (i >= 8 && i <= 11) {
71
- // 8-B: 1:4 odds on 1 digit, plus 1:16 odds on 30 digits
72
- ideal = N*(1/4 + 30/16);
73
- } else {
74
- // Otherwise: 1:16 odds on 30 digits
75
- ideal = N*30/16;
76
- }
77
- var d = divergence(n, ideal);
78
-
79
- // Draw bar using UTF squares (just for grins)
80
- var s = n/max*50 | 0;
81
- while (s--) bar += '=';
82
-
83
- assert(Math.abs(d) < limit, c + ' |' + bar + '| ' + counts[c] + ' (' + d + '% < ' + limit + '%)');
84
- }
85
- }
86
- }
87
-
88
- // Perf tests
89
- for (var version in generators) {
90
- log('\nPerformance testing ' + version + ' UUIDs');
91
- var generator = generators[version];
92
- var buf = new uuid.BufferClass(16);
93
-
94
- for (var i = 0, t = Date.now(); i < N; i++) generator();
95
- rate('uuid.' + version + '()', t);
96
-
97
- for (var i = 0, t = Date.now(); i < N; i++) generator('binary');
98
- rate('uuid.' + version + '(\'binary\')', t);
99
-
100
- for (var i = 0, t = Date.now(); i < N; i++) generator('binary', buf);
101
- rate('uuid.' + version + '(\'binary\', buffer)', t);
102
- }
package/rng-browser.js DELETED
@@ -1,31 +0,0 @@
1
-
2
- var rng;
3
-
4
- if (global.crypto && crypto.getRandomValues) {
5
- // WHATWG crypto-based RNG - http://wiki.whatwg.org/wiki/Crypto
6
- // Moderately fast, high quality
7
- var _rnds8 = new Uint8Array(16);
8
- rng = function whatwgRNG() {
9
- crypto.getRandomValues(_rnds8);
10
- return _rnds8;
11
- };
12
- }
13
-
14
- if (!rng) {
15
- // Math.random()-based (RNG)
16
- //
17
- // If all else fails, use Math.random(). It's fast, but is of unspecified
18
- // quality.
19
- var _rnds = new Array(16);
20
- rng = function() {
21
- for (var i = 0, r; i < 16; i++) {
22
- if ((i & 0x03) === 0) r = Math.random() * 0x100000000;
23
- _rnds[i] = r >>> ((i & 0x03) << 3) & 0xff;
24
- }
25
-
26
- return _rnds;
27
- };
28
- }
29
-
30
- module.exports = rng;
31
-
package/rng.js DELETED
@@ -1,4 +0,0 @@
1
- var rb = require('crypto').randomBytes;
2
- module.exports = function() {
3
- return rb(16);
4
- };
package/test/mocha.opts DELETED
@@ -1 +0,0 @@
1
- --ui qunit
package/test/test.js DELETED
@@ -1,105 +0,0 @@
1
- var assert = require('assert');
2
-
3
- var uuid = require('../');
4
-
5
- // Verify ordering of v1 ids created with explicit times
6
- var TIME = 1321644961388; // 2011-11-18 11:36:01.388-08:00
7
-
8
- function compare(name, ids) {
9
- test(name, function() {
10
- // avoid .map for older browsers
11
- for (var i=0 ; i<ids.length ; ++i) {
12
- ids[i] = ids[i].split('-').reverse().join('-');
13
- }
14
- ids = ids.sort();
15
- var sorted = ([].concat(ids)).sort();
16
-
17
- assert(sorted.toString() == ids.toString(), name + ' have expected order');
18
- });
19
- }
20
-
21
- // Verify ordering of v1 ids created using default behavior
22
- compare('uuids with current time', [
23
- uuid.v1(),
24
- uuid.v1(),
25
- uuid.v1(),
26
- uuid.v1(),
27
- uuid.v1()
28
- ]);
29
-
30
- // Verify ordering of v1 ids created with explicit times
31
- compare('uuids with time option', [
32
- uuid.v1({msecs: TIME - 10*3600*1000}),
33
- uuid.v1({msecs: TIME - 1}),
34
- uuid.v1({msecs: TIME}),
35
- uuid.v1({msecs: TIME + 1}),
36
- uuid.v1({msecs: TIME + 28*24*3600*1000})
37
- ]);
38
-
39
- test('msec', function() {
40
- assert(
41
- uuid.v1({msecs: TIME}) != uuid.v1({msecs: TIME}),
42
- 'IDs created at same msec are different'
43
- );
44
- });
45
-
46
- test('exception thrown when > 10k ids created in 1ms', function() {
47
- // Verify throw if too many ids created
48
- var thrown = false;
49
- try {
50
- uuid.v1({msecs: TIME, nsecs: 10000});
51
- } catch (e) {
52
- thrown = true;
53
- }
54
- assert(thrown, 'Exception thrown when > 10K ids created in 1 ms');
55
- });
56
-
57
- test('clock regression by msec', function() {
58
- // Verify clock regression bumps clockseq
59
- var uidt = uuid.v1({msecs: TIME});
60
- var uidtb = uuid.v1({msecs: TIME - 1});
61
- assert(
62
- parseInt(uidtb.split('-')[3], 16) - parseInt(uidt.split('-')[3], 16) === 1,
63
- 'Clock regression by msec increments the clockseq'
64
- );
65
- });
66
-
67
- test('clock regression by nsec', function() {
68
- // Verify clock regression bumps clockseq
69
- var uidtn = uuid.v1({msecs: TIME, nsecs: 10});
70
- var uidtnb = uuid.v1({msecs: TIME, nsecs: 9});
71
- assert(
72
- parseInt(uidtnb.split('-')[3], 16) - parseInt(uidtn.split('-')[3], 16) === 1,
73
- 'Clock regression by nsec increments the clockseq'
74
- );
75
- });
76
-
77
- test('explicit options product expected id', function() {
78
- // Verify explicit options produce expected id
79
- var id = uuid.v1({
80
- msecs: 1321651533573,
81
- nsecs: 5432,
82
- clockseq: 0x385c,
83
- node: [ 0x61, 0xcd, 0x3c, 0xbb, 0x32, 0x10 ]
84
- });
85
- assert(id == 'd9428888-122b-11e1-b85c-61cd3cbb3210', 'Explicit options produce expected id');
86
- });
87
-
88
- test('ids spanning 1ms boundary are 100ns apart', function() {
89
- // Verify adjacent ids across a msec boundary are 1 time unit apart
90
- var u0 = uuid.v1({msecs: TIME, nsecs: 9999});
91
- var u1 = uuid.v1({msecs: TIME + 1, nsecs: 0});
92
-
93
- var before = u0.split('-')[0], after = u1.split('-')[0];
94
- var dt = parseInt(after, 16) - parseInt(before, 16);
95
- assert(dt === 1, 'Ids spanning 1ms boundary are 100ns apart');
96
- });
97
-
98
- test('parse/unparse', function() {
99
- var id = '00112233445566778899aabbccddeeff';
100
- assert(uuid.unparse(uuid.parse(id.substr(0,10))) ==
101
- '00112233-4400-0000-0000-000000000000', 'Short parse');
102
- assert(uuid.unparse(uuid.parse('(this is the uuid -> ' + id + id)) ==
103
- '00112233-4455-6677-8899-aabbccddeeff', 'Dirty parse');
104
- });
105
-