Security update to Drupal 8.4.6
[yaffs-website] / node_modules / node-uuid / test / compare_v1.js
1 var assert = require('assert'),
2     nodeuuid = require('../uuid'),
3     uuidjs = require('uuid-js'),
4     libuuid = require('uuid').generate,
5     util = require('util'),
6     exec = require('child_process').exec,
7     os = require('os');
8
9 // On Mac Os X / macports there's only the ossp-uuid package that provides uuid
10 // On Linux there's uuid-runtime which provides uuidgen
11 var uuidCmd = os.type() === 'Darwin' ? 'uuid -1' : 'uuidgen -t';
12
13 function compare(ids) {
14   console.log(ids);
15   for (var i = 0; i < ids.length; i++) {
16     var id = ids[i].split('-');
17     id = [id[2], id[1], id[0]].join('');
18     ids[i] = id;
19   }
20   var sorted = ([].concat(ids)).sort();
21
22   if (sorted.toString() !== ids.toString()) {
23     console.log('Warning: sorted !== ids');
24   } else {
25     console.log('everything in order!');
26   }
27 }
28
29 // Test time order of v1 uuids
30 var ids = [];
31 while (ids.length < 10e3) ids.push(nodeuuid.v1());
32
33 var max = 10;
34 console.log('node-uuid:');
35 ids = [];
36 for (var i = 0; i < max; i++) ids.push(nodeuuid.v1());
37 compare(ids);
38
39 console.log('');
40 console.log('uuidjs:');
41 ids = [];
42 for (var i = 0; i < max; i++) ids.push(uuidjs.create(1).toString());
43 compare(ids);
44
45 console.log('');
46 console.log('libuuid:');
47 ids = [];
48 var count = 0;
49 var last = function() {
50   compare(ids);
51 }
52 var cb = function(err, stdout, stderr) {
53   ids.push(stdout.substring(0, stdout.length-1));
54   count++;
55   if (count < max) {
56     return next();
57   }
58   last();
59 };
60 var next = function() {
61   exec(uuidCmd, cb);
62 };
63 next();