vulcan 0.3.0 → 0.4.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.
- data/bin/vulcan +3 -1
- data/lib/vulcan/cli.rb +22 -3
- data/lib/vulcan/version.rb +1 -1
- data/server/bin/make +1 -3
- data/server/lib/spawner.js +9 -4
- data/server/node_modules/connect-form/node_modules/formidable/Readme.md +13 -2
- data/server/node_modules/connect-form/node_modules/formidable/lib/incoming_form.js +19 -7
- data/server/node_modules/connect-form/node_modules/formidable/lib/multipart_parser.js +12 -1
- data/server/node_modules/connect-form/node_modules/formidable/package.json +1 -1
- data/server/node_modules/connect-form/node_modules/formidable/test/fixture/file/plain.txt +1 -0
- data/server/node_modules/connect-form/node_modules/formidable/test/fixture/http/no-filename/generic.http +13 -0
- data/server/node_modules/connect-form/node_modules/formidable/test/fixture/http/special-chars-in-filename/osx-chrome-13.http +0 -10
- data/server/node_modules/connect-form/node_modules/formidable/test/fixture/http/special-chars-in-filename/xp-chrome-12.http +0 -9
- data/server/node_modules/connect-form/node_modules/formidable/test/fixture/js/no-filename.js +3 -0
- data/server/node_modules/connect-form/node_modules/formidable/test/legacy/simple/test-multipart-parser.js +1 -1
- data/server/node_modules/cradle/lib/cradle.js +0 -1
- data/server/node_modules/cradle/package.json +3 -3
- data/server/node_modules/cradle/test/cache-test.js +6 -7
- data/server/node_modules/cradle/test/cradle-test.js +4 -5
- data/server/node_modules/cradle/test/response-test.js +5 -6
- data/server/node_modules/express/History.md +53 -1
- data/server/node_modules/express/Makefile +3 -9
- data/server/node_modules/express/Readme.md +3 -1
- data/server/node_modules/express/bin/express +65 -66
- data/server/node_modules/express/lib/express.js +1 -1
- data/server/node_modules/express/lib/request.js +23 -9
- data/server/node_modules/express/lib/response.js +3 -2
- data/server/node_modules/express/lib/utils.js +13 -0
- data/server/node_modules/express/lib/view/view.js +2 -1
- data/server/node_modules/express/lib/view.js +19 -16
- data/server/node_modules/express/node_modules/connect/lib/connect.js +1 -1
- data/server/node_modules/express/node_modules/connect/lib/http.js +2 -0
- data/server/node_modules/express/node_modules/connect/lib/middleware/bodyParser.js +135 -31
- data/server/node_modules/express/node_modules/connect/lib/middleware/limit.js +5 -1
- data/server/node_modules/express/node_modules/connect/lib/middleware/session.js +2 -2
- data/server/node_modules/express/node_modules/connect/lib/middleware/static.js +26 -21
- data/server/node_modules/express/node_modules/connect/lib/middleware/staticCache.js +91 -38
- data/server/node_modules/express/node_modules/connect/lib/middleware/vhost.js +1 -1
- data/server/node_modules/express/node_modules/connect/lib/utils.js +11 -4
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/Makefile +14 -0
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/Readme.md +286 -0
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/TODO +3 -0
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/benchmark/bench-multipart-parser.js +70 -0
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/example/post.js +43 -0
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/example/upload.js +48 -0
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/index.js +1 -0
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/lib/file.js +61 -0
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/lib/incoming_form.js +377 -0
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/lib/index.js +3 -0
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/lib/multipart_parser.js +312 -0
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/lib/querystring_parser.js +25 -0
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/lib/util.js +6 -0
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/package.json +22 -0
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/common.js +19 -0
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/file/funkyfilename.txt +1 -0
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/file/plain.txt +1 -0
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/http/no-filename/generic.http +13 -0
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/http/special-chars-in-filename/info.md +3 -0
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/http/special-chars-in-filename/osx-chrome-13.http +26 -0
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/http/special-chars-in-filename/osx-firefox-3.6.http +24 -0
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/http/special-chars-in-filename/osx-safari-5.http +23 -0
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/http/special-chars-in-filename/xp-chrome-12.http +24 -0
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/http/special-chars-in-filename/xp-ie-7.http +22 -0
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/http/special-chars-in-filename/xp-ie-8.http +22 -0
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/http/special-chars-in-filename/xp-safari-5.http +22 -0
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/js/no-filename.js +3 -0
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/js/special-chars-in-filename.js +21 -0
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/multi_video.upload +0 -0
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/multipart.js +72 -0
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/integration/test-fixtures.js +89 -0
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/legacy/common.js +24 -0
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/legacy/integration/test-multipart-parser.js +80 -0
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/legacy/simple/test-file.js +104 -0
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/legacy/simple/test-incoming-form.js +715 -0
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/legacy/simple/test-multipart-parser.js +50 -0
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/legacy/simple/test-querystring-parser.js +45 -0
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/legacy/system/test-multi-video-upload.js +72 -0
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/run.js +2 -0
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/unit/test-incoming-form.js +63 -0
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/tool/record.js +47 -0
- data/server/node_modules/express/node_modules/connect/package.json +7 -6
- data/server/node_modules/express/node_modules/connect/test.js +44 -31
- data/server/node_modules/express/node_modules/mime/mime.js +3 -3
- data/server/node_modules/express/node_modules/mime/package.json +21 -10
- data/server/node_modules/express/node_modules/mime/test.js +2 -3
- data/server/node_modules/express/node_modules/mime/{mime.types → types/mime.types} +0 -0
- data/server/node_modules/express/node_modules/mime/{node.types → types/node.types} +17 -0
- data/server/node_modules/express/node_modules/mkdirp/LICENSE +21 -0
- data/server/node_modules/express/node_modules/mkdirp/README.markdown +21 -0
- data/server/node_modules/express/node_modules/mkdirp/examples/pow.js +6 -0
- data/server/node_modules/express/node_modules/mkdirp/examples/pow.js.orig +6 -0
- data/server/node_modules/express/node_modules/mkdirp/examples/pow.js.rej +19 -0
- data/server/node_modules/express/node_modules/mkdirp/index.js +20 -0
- data/server/node_modules/express/node_modules/mkdirp/package.json +23 -0
- data/server/node_modules/express/node_modules/mkdirp/test/mkdirp.js +28 -0
- data/server/node_modules/express/node_modules/mkdirp/test/race.js +41 -0
- data/server/node_modules/express/node_modules/mkdirp/test/rel.js +32 -0
- data/server/node_modules/express/node_modules/qs/History.md +11 -0
- data/server/node_modules/express/node_modules/qs/Makefile +1 -3
- data/server/node_modules/express/node_modules/qs/Readme.md +2 -4
- data/server/node_modules/express/node_modules/qs/lib/querystring.js +100 -74
- data/server/node_modules/express/node_modules/qs/package.json +9 -2
- data/server/node_modules/express/node_modules/qs/test/mocha.opts +2 -0
- data/server/node_modules/express/node_modules/qs/test/{parse.test.js → parse.js} +1 -2
- data/server/node_modules/express/node_modules/qs/test/{stringify.test.js → stringify.js} +0 -0
- data/server/node_modules/express/package.json +9 -8
- data/server/node_modules/express/testing/foo/app.js +35 -0
- data/server/node_modules/express/testing/foo/package.json +9 -0
- data/server/node_modules/express/testing/foo/public/stylesheets/style.css +8 -0
- data/server/node_modules/express/testing/foo/routes/index.js +10 -0
- data/server/node_modules/express/testing/foo/views/index.jade +2 -0
- data/server/node_modules/express/testing/foo/views/layout.jade +6 -0
- data/server/node_modules/express/testing/index.js +43 -0
- data/server/node_modules/express/testing/public/test.txt +2971 -0
- data/server/node_modules/express/testing/views/page.html +1 -0
- data/server/node_modules/express/testing/views/page.jade +3 -0
- data/server/node_modules/express/testing/views/test.md +1 -0
- data/server/node_modules/express/testing/views/user/index.jade +1 -0
- data/server/node_modules/express/testing/views/user/list.jade +1 -0
- data/server/node_modules/node-uuid/README.md +166 -67
- data/server/node_modules/node-uuid/benchmark/README.md +53 -0
- data/server/node_modules/node-uuid/benchmark/bench.gnu +174 -0
- data/server/node_modules/node-uuid/benchmark/bench.sh +34 -0
- data/server/node_modules/node-uuid/{test → benchmark}/benchmark-native.c +0 -0
- data/server/node_modules/node-uuid/benchmark/benchmark.js +84 -0
- data/server/node_modules/node-uuid/package.json +5 -3
- data/server/node_modules/node-uuid/test/benchmark-native +0 -0
- data/server/node_modules/node-uuid/test/compare_v1.js +63 -0
- data/server/node_modules/node-uuid/test/test.html +3 -0
- data/server/node_modules/node-uuid/test/test.js +214 -57
- data/server/node_modules/node-uuid/uuid.js +225 -56
- data/server/node_modules/restler/README.md +20 -7
- data/server/node_modules/restler/bin/restler +1 -1
- data/server/node_modules/restler/lib/multipartform.js +9 -8
- data/server/node_modules/restler/lib/restler.js +64 -22
- data/server/node_modules/restler/package.json +2 -2
- data/server/node_modules/restler/test/restler.js +22 -2
- data/server/node_modules/restler/test/test_helper.js +20 -1
- data/server/package.json +1 -2
- data/server/web.js +30 -7
- metadata +90 -86
- data/server/node_modules/cradle/node_modules/vows/LICENSE +0 -20
- data/server/node_modules/cradle/node_modules/vows/Makefile +0 -7
- data/server/node_modules/cradle/node_modules/vows/README.md +0 -39
- data/server/node_modules/cradle/node_modules/vows/bin/vows +0 -515
- data/server/node_modules/cradle/node_modules/vows/lib/assert/error.js +0 -27
- data/server/node_modules/cradle/node_modules/vows/lib/assert/macros.js +0 -215
- data/server/node_modules/cradle/node_modules/vows/lib/assert/utils.js +0 -77
- data/server/node_modules/cradle/node_modules/vows/lib/vows/console.js +0 -131
- data/server/node_modules/cradle/node_modules/vows/lib/vows/context.js +0 -55
- data/server/node_modules/cradle/node_modules/vows/lib/vows/coverage/file.js +0 -29
- data/server/node_modules/cradle/node_modules/vows/lib/vows/coverage/fragments/coverage-foot.html +0 -2
- data/server/node_modules/cradle/node_modules/vows/lib/vows/coverage/fragments/coverage-head.html +0 -61
- data/server/node_modules/cradle/node_modules/vows/lib/vows/coverage/report-html.js +0 -54
- data/server/node_modules/cradle/node_modules/vows/lib/vows/coverage/report-json.js +0 -54
- data/server/node_modules/cradle/node_modules/vows/lib/vows/coverage/report-plain.js +0 -38
- data/server/node_modules/cradle/node_modules/vows/lib/vows/extras.js +0 -28
- data/server/node_modules/cradle/node_modules/vows/lib/vows/reporters/dot-matrix.js +0 -67
- data/server/node_modules/cradle/node_modules/vows/lib/vows/reporters/json.js +0 -16
- data/server/node_modules/cradle/node_modules/vows/lib/vows/reporters/silent.js +0 -8
- data/server/node_modules/cradle/node_modules/vows/lib/vows/reporters/spec.js +0 -44
- data/server/node_modules/cradle/node_modules/vows/lib/vows/reporters/watch.js +0 -39
- data/server/node_modules/cradle/node_modules/vows/lib/vows/reporters/xunit.js +0 -90
- data/server/node_modules/cradle/node_modules/vows/lib/vows/suite.js +0 -319
- data/server/node_modules/cradle/node_modules/vows/lib/vows.js +0 -193
- data/server/node_modules/cradle/node_modules/vows/node_modules/eyes/LICENSE +0 -20
- data/server/node_modules/cradle/node_modules/vows/node_modules/eyes/Makefile +0 -4
- data/server/node_modules/cradle/node_modules/vows/node_modules/eyes/README.md +0 -72
- data/server/node_modules/cradle/node_modules/vows/node_modules/eyes/lib/eyes.js +0 -233
- data/server/node_modules/cradle/node_modules/vows/node_modules/eyes/package.json +0 -14
- data/server/node_modules/cradle/node_modules/vows/node_modules/eyes/test/eyes-test.js +0 -55
- data/server/node_modules/cradle/node_modules/vows/package.json +0 -14
- data/server/node_modules/cradle/node_modules/vows/test/assert-test.js +0 -135
- data/server/node_modules/cradle/node_modules/vows/test/fixtures/isolate/failing.js +0 -18
- data/server/node_modules/cradle/node_modules/vows/test/fixtures/isolate/log.js +0 -18
- data/server/node_modules/cradle/node_modules/vows/test/fixtures/isolate/passing.js +0 -17
- data/server/node_modules/cradle/node_modules/vows/test/fixtures/isolate/stderr.js +0 -18
- data/server/node_modules/cradle/node_modules/vows/test/isolate-test.js +0 -140
- data/server/node_modules/cradle/node_modules/vows/test/testInherit.js +0 -133
- data/server/node_modules/cradle/node_modules/vows/test/vows-error-test.js +0 -51
- data/server/node_modules/cradle/node_modules/vows/test/vows-test.js +0 -374
- data/server/node_modules/express/node_modules/mime/index.js +0 -1
- data/server/node_modules/express/node_modules/qs/support/expresso/History.md +0 -128
- data/server/node_modules/express/node_modules/qs/support/expresso/Makefile +0 -53
- data/server/node_modules/express/node_modules/qs/support/expresso/Readme.md +0 -61
- data/server/node_modules/express/node_modules/qs/support/expresso/bin/expresso +0 -856
- data/server/node_modules/express/node_modules/qs/support/expresso/docs/api.html +0 -1080
- data/server/node_modules/express/node_modules/qs/support/expresso/docs/index.html +0 -377
- data/server/node_modules/express/node_modules/qs/support/expresso/docs/index.md +0 -290
- data/server/node_modules/express/node_modules/qs/support/expresso/docs/layout/foot.html +0 -3
- data/server/node_modules/express/node_modules/qs/support/expresso/docs/layout/head.html +0 -42
- data/server/node_modules/express/node_modules/qs/support/expresso/lib/bar.js +0 -4
- data/server/node_modules/express/node_modules/qs/support/expresso/lib/foo.js +0 -16
- data/server/node_modules/express/node_modules/qs/support/expresso/package.json +0 -12
- data/server/node_modules/express/node_modules/qs/support/expresso/test/assert.test.js +0 -91
- data/server/node_modules/express/node_modules/qs/support/expresso/test/async.test.js +0 -12
- data/server/node_modules/express/node_modules/qs/support/expresso/test/bar.test.js +0 -13
- data/server/node_modules/express/node_modules/qs/support/expresso/test/foo.test.js +0 -14
- data/server/node_modules/express/node_modules/qs/support/expresso/test/http.test.js +0 -146
- data/server/node_modules/express/node_modules/qs/support/expresso/test/serial/async.test.js +0 -39
- data/server/node_modules/express/node_modules/qs/support/expresso/test/serial/http.test.js +0 -48
- data/server/node_modules/express/node_modules/qs/support/should/History.md +0 -22
- data/server/node_modules/express/node_modules/qs/support/should/Makefile +0 -6
- data/server/node_modules/express/node_modules/qs/support/should/Readme.md +0 -248
- data/server/node_modules/express/node_modules/qs/support/should/examples/runner.js +0 -53
- data/server/node_modules/express/node_modules/qs/support/should/index.js +0 -2
- data/server/node_modules/express/node_modules/qs/support/should/lib/eql.js +0 -91
- data/server/node_modules/express/node_modules/qs/support/should/lib/should.js +0 -548
- data/server/node_modules/express/node_modules/qs/support/should/package.json +0 -8
- data/server/node_modules/express/node_modules/qs/support/should/test/should.test.js +0 -358
- data/server/node_modules/node-uuid/test/benchmark.js +0 -27
|
@@ -0,0 +1,63 @@
|
|
|
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();
|
|
@@ -1,83 +1,240 @@
|
|
|
1
|
-
if (
|
|
1
|
+
if (!this.uuid) {
|
|
2
|
+
// node.js
|
|
2
3
|
uuid = require('../uuid');
|
|
3
4
|
}
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
//
|
|
7
|
+
// x-platform log/assert shims
|
|
8
|
+
//
|
|
9
|
+
|
|
10
|
+
function _log(msg, type) {
|
|
11
|
+
type = type || 'log';
|
|
7
12
|
|
|
8
|
-
function log(msg) {
|
|
9
13
|
if (typeof(document) != 'undefined') {
|
|
10
|
-
document.write('<div>' + msg + '</div>');
|
|
14
|
+
document.write('<div class="' + type + '">' + msg.replace(/\n/g, '<br />') + '</div>');
|
|
11
15
|
}
|
|
12
16
|
if (typeof(console) != 'undefined') {
|
|
13
|
-
|
|
17
|
+
var color = {
|
|
18
|
+
log: '\033[30m',
|
|
19
|
+
warn: '\033[33m',
|
|
20
|
+
error: '\033[31m'
|
|
21
|
+
}
|
|
22
|
+
console[type](color[type] + msg + color.log);
|
|
14
23
|
}
|
|
15
24
|
}
|
|
16
25
|
|
|
17
|
-
function
|
|
18
|
-
|
|
19
|
-
}
|
|
26
|
+
function log(msg) {_log(msg, 'log');}
|
|
27
|
+
function warn(msg) {_log(msg, 'warn');}
|
|
28
|
+
function error(msg) {_log(msg, 'error');}
|
|
20
29
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
rate('uuid(\'binary\')', t);
|
|
27
|
-
var buf = new uuid.BufferClass(16);
|
|
28
|
-
for (var i = 0, t = Date.now(); i < N; i++) uuid('binary', buf);
|
|
29
|
-
rate('uuid(\'binary\', buffer)', t);
|
|
30
|
-
|
|
31
|
-
var counts = {}, max = 0;
|
|
32
|
-
|
|
33
|
-
var b = new uuid.BufferClass(16);
|
|
34
|
-
for (var i = 0; i < N; i++) {
|
|
35
|
-
id = uuid();
|
|
36
|
-
if (!UUID_FORMAT.test(id)) {
|
|
37
|
-
throw Error(id + ' is not a valid UUID string');
|
|
30
|
+
function assert(res, msg) {
|
|
31
|
+
if (!res) {
|
|
32
|
+
error('FAIL: ' + msg);
|
|
33
|
+
} else {
|
|
34
|
+
log('Pass: ' + msg);
|
|
38
35
|
}
|
|
36
|
+
}
|
|
39
37
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
//
|
|
39
|
+
// Unit tests
|
|
40
|
+
//
|
|
43
41
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
42
|
+
// Verify ordering of v1 ids created with explicit times
|
|
43
|
+
var TIME = 1321644961388; // 2011-11-18 11:36:01.388-08:00
|
|
44
|
+
|
|
45
|
+
function compare(name, ids) {
|
|
46
|
+
ids = ids.map(function(id) {
|
|
47
|
+
return id.split('-').reverse().join('-');
|
|
48
|
+
}).sort();
|
|
49
|
+
var sorted = ([].concat(ids)).sort();
|
|
50
|
+
|
|
51
|
+
assert(sorted.toString() == ids.toString(), name + ' have expected order');
|
|
50
52
|
}
|
|
51
53
|
|
|
54
|
+
// Verify ordering of v1 ids created using default behavior
|
|
55
|
+
compare('uuids with current time', [
|
|
56
|
+
uuid.v1(),
|
|
57
|
+
uuid.v1(),
|
|
58
|
+
uuid.v1(),
|
|
59
|
+
uuid.v1(),
|
|
60
|
+
uuid.v1()
|
|
61
|
+
]);
|
|
62
|
+
|
|
63
|
+
// Verify ordering of v1 ids created with explicit times
|
|
64
|
+
compare('uuids with time option', [
|
|
65
|
+
uuid.v1({msecs: TIME - 10*3600*1000}),
|
|
66
|
+
uuid.v1({msecs: TIME - 1}),
|
|
67
|
+
uuid.v1({msecs: TIME}),
|
|
68
|
+
uuid.v1({msecs: TIME + 1}),
|
|
69
|
+
uuid.v1({msecs: TIME + 28*24*3600*1000}),
|
|
70
|
+
]);
|
|
71
|
+
|
|
72
|
+
assert(
|
|
73
|
+
uuid.v1({msecs: TIME}) != uuid.v1({msecs: TIME}),
|
|
74
|
+
'IDs created at same msec are different'
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
// Verify throw if too many ids created
|
|
78
|
+
var thrown = false;
|
|
79
|
+
try {
|
|
80
|
+
uuid.v1({msecs: TIME, nsecs: 10000});
|
|
81
|
+
} catch (e) {
|
|
82
|
+
thrown = true;
|
|
83
|
+
}
|
|
84
|
+
assert(thrown, 'Exception thrown when > 10K ids created in 1 ms');
|
|
85
|
+
|
|
86
|
+
// Verify clock regression bumps clockseq
|
|
87
|
+
var uidt = uuid.v1({msecs: TIME});
|
|
88
|
+
var uidtb = uuid.v1({msecs: TIME - 1});
|
|
89
|
+
assert(
|
|
90
|
+
parseInt(uidtb.split('-')[3], 16) - parseInt(uidt.split('-')[3], 16) === 1,
|
|
91
|
+
'Clock regression by msec increments the clockseq'
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
// Verify clock regression bumps clockseq
|
|
95
|
+
var uidtn = uuid.v1({msecs: TIME, nsecs: 10});
|
|
96
|
+
var uidtnb = uuid.v1({msecs: TIME, nsecs: 9});
|
|
97
|
+
assert(
|
|
98
|
+
parseInt(uidtnb.split('-')[3], 16) - parseInt(uidtn.split('-')[3], 16) === 1,
|
|
99
|
+
'Clock regression by nsec increments the clockseq'
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
// Verify explicit options produce expected id
|
|
103
|
+
var id = uuid.v1({
|
|
104
|
+
msecs: 1321651533573,
|
|
105
|
+
nsecs: 5432,
|
|
106
|
+
clockseq: 0x385c,
|
|
107
|
+
node: [ 0x61, 0xcd, 0x3c, 0xbb, 0x32, 0x10 ]
|
|
108
|
+
});
|
|
109
|
+
assert(id == 'd9428888-122b-11e1-b85c-61cd3cbb3210', 'Explicit options produce expected id');
|
|
110
|
+
|
|
111
|
+
// Verify adjacent ids across a msec boundary are 1 time unit apart
|
|
112
|
+
var u0 = uuid.v1({msecs: TIME, nsecs: 9999});
|
|
113
|
+
var u1 = uuid.v1({msecs: TIME + 1, nsecs: 0});
|
|
114
|
+
|
|
115
|
+
var before = u0.split('-')[0], after = u1.split('-')[0];
|
|
116
|
+
var dt = parseInt(after, 16) - parseInt(before, 16);
|
|
117
|
+
assert(dt === 1, 'Ids spanning 1ms boundary are 100ns apart');
|
|
118
|
+
|
|
119
|
+
//
|
|
120
|
+
// Test parse/unparse
|
|
121
|
+
//
|
|
122
|
+
|
|
123
|
+
id = '00112233445566778899aabbccddeeff';
|
|
124
|
+
assert(uuid.unparse(uuid.parse(id.substr(0,10))) ==
|
|
125
|
+
'00112233-4400-0000-0000-000000000000', 'Short parse');
|
|
126
|
+
assert(uuid.unparse(uuid.parse('(this is the uuid -> ' + id + id)) ==
|
|
127
|
+
'00112233-4455-6677-8899-aabbccddeeff', 'Dirty parse');
|
|
128
|
+
|
|
129
|
+
//
|
|
130
|
+
// Perf tests
|
|
131
|
+
//
|
|
132
|
+
|
|
133
|
+
var generators = {
|
|
134
|
+
v1: uuid.v1,
|
|
135
|
+
v4: uuid.v4
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
var UUID_FORMAT = {
|
|
139
|
+
v1: /[0-9a-f]{8}-[0-9a-f]{4}-1[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/i,
|
|
140
|
+
v4: /[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/i
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
var N = 1e4;
|
|
144
|
+
|
|
52
145
|
// Get %'age an actual value differs from the ideal value
|
|
53
146
|
function divergence(actual, ideal) {
|
|
54
147
|
return Math.round(100*100*(actual - ideal)/ideal)/100;
|
|
55
148
|
}
|
|
56
149
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
var
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
150
|
+
function rate(msg, t) {
|
|
151
|
+
log(msg + ': ' + (N / (Date.now() - t) * 1e3 | 0) + ' uuids\/second');
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
for (var version in generators) {
|
|
155
|
+
var counts = {}, max = 0;
|
|
156
|
+
var generator = generators[version];
|
|
157
|
+
var format = UUID_FORMAT[version];
|
|
158
|
+
|
|
159
|
+
log('\nSanity check ' + N + ' ' + version + ' uuids');
|
|
160
|
+
for (var i = 0, ok = 0; i < N; i++) {
|
|
161
|
+
id = generator();
|
|
162
|
+
if (!format.test(id)) {
|
|
163
|
+
throw Error(id + ' is not a valid UUID string');
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (id != uuid.unparse(uuid.parse(id))) {
|
|
167
|
+
assert(fail, id + ' is not a valid id');
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Count digits for our randomness check
|
|
171
|
+
if (version == 'v4') {
|
|
172
|
+
var digits = id.replace(/-/g, '').split('');
|
|
173
|
+
for (var j = digits.length-1; j >= 0; j--) {
|
|
174
|
+
var c = digits[j];
|
|
175
|
+
max = Math.max(max, counts[c] = (counts[c] || 0) + 1);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// Check randomness for v4 UUIDs
|
|
181
|
+
if (version == 'v4') {
|
|
182
|
+
// Limit that we get worried about randomness. (Purely empirical choice, this!)
|
|
183
|
+
var limit = 2*100*Math.sqrt(1/N);
|
|
184
|
+
|
|
185
|
+
log('\nChecking v4 randomness. Distribution of Hex Digits (% deviation from ideal)');
|
|
186
|
+
|
|
187
|
+
for (var i = 0; i < 16; i++) {
|
|
188
|
+
var c = i.toString(16);
|
|
189
|
+
var bar = '', n = counts[c], p = Math.round(n/max*100|0);
|
|
190
|
+
|
|
191
|
+
// 1-3,5-8, and D-F: 1:16 odds over 30 digits
|
|
192
|
+
var ideal = N*30/16;
|
|
193
|
+
if (i == 4) {
|
|
194
|
+
// 4: 1:1 odds on 1 digit, plus 1:16 odds on 30 digits
|
|
195
|
+
ideal = N*(1 + 30/16);
|
|
196
|
+
} else if (i >= 8 && i <= 11) {
|
|
197
|
+
// 8-B: 1:4 odds on 1 digit, plus 1:16 odds on 30 digits
|
|
198
|
+
ideal = N*(1/4 + 30/16);
|
|
199
|
+
} else {
|
|
200
|
+
// Otherwise: 1:16 odds on 30 digits
|
|
201
|
+
ideal = N*30/16;
|
|
202
|
+
}
|
|
203
|
+
var d = divergence(n, ideal);
|
|
204
|
+
|
|
205
|
+
// Draw bar using UTF squares (just for grins)
|
|
206
|
+
var s = n/max*50 | 0;
|
|
207
|
+
while (s--) bar += '=';
|
|
208
|
+
|
|
209
|
+
assert(Math.abs(d) < limit, c + ' |' + bar + '| ' + counts[c] + ' (' + d + '% < ' + limit + '%)');
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// Perf tests
|
|
215
|
+
for (var version in generators) {
|
|
216
|
+
log('\nPerformance testing ' + version + ' UUIDs');
|
|
217
|
+
var generator = generators[version];
|
|
218
|
+
var buf = new uuid.BufferClass(16);
|
|
219
|
+
|
|
220
|
+
if (version == 'v4') {
|
|
221
|
+
['mathRNG', 'whatwgRNG', 'nodeRNG'].forEach(function(rng) {
|
|
222
|
+
if (uuid[rng]) {
|
|
223
|
+
var options = {rng: uuid[rng]};
|
|
224
|
+
for (var i = 0, t = Date.now(); i < N; i++) generator(options);
|
|
225
|
+
rate('uuid.' + version + '() with ' + rng, t);
|
|
226
|
+
} else {
|
|
227
|
+
log('uuid.' + version + '() with ' + rng + ': not defined');
|
|
228
|
+
}
|
|
229
|
+
});
|
|
72
230
|
} else {
|
|
73
|
-
|
|
74
|
-
|
|
231
|
+
for (var i = 0, t = Date.now(); i < N; i++) generator();
|
|
232
|
+
rate('uuid.' + version + '()', t);
|
|
75
233
|
}
|
|
76
|
-
var d = divergence(n, ideal);
|
|
77
234
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
while (s--) bar += '=';
|
|
235
|
+
for (var i = 0, t = Date.now(); i < N; i++) generator('binary');
|
|
236
|
+
rate('uuid.' + version + '(\'binary\')', t);
|
|
81
237
|
|
|
82
|
-
|
|
238
|
+
for (var i = 0, t = Date.now(); i < N; i++) generator('binary', buf);
|
|
239
|
+
rate('uuid.' + version + '(\'binary\', buffer)', t);
|
|
83
240
|
}
|
|
@@ -1,80 +1,249 @@
|
|
|
1
|
+
// node-uuid/uuid.js
|
|
2
|
+
//
|
|
3
|
+
// Copyright (c) 2010 Robert Kieffer
|
|
4
|
+
// Dual licensed under the MIT and GPL licenses.
|
|
5
|
+
// Documentation and details at https://github.com/broofa/node-uuid
|
|
1
6
|
(function() {
|
|
2
|
-
|
|
3
|
-
* Generate a RFC4122(v4) UUID
|
|
4
|
-
*
|
|
5
|
-
* Documentation at https://github.com/broofa/node-uuid
|
|
6
|
-
*/
|
|
7
|
+
var _global = this;
|
|
7
8
|
|
|
8
|
-
//
|
|
9
|
-
|
|
9
|
+
// Unique ID creation requires a high quality random # generator, but
|
|
10
|
+
// Math.random() does not guarantee "cryptographic quality". So we feature
|
|
11
|
+
// detect for more robust APIs, normalizing each method to return 128-bits
|
|
12
|
+
// (16 bytes) of random data.
|
|
13
|
+
var mathRNG, nodeRNG, whatwgRNG;
|
|
14
|
+
|
|
15
|
+
// Math.random()-based RNG. All platforms, very fast, unknown quality
|
|
16
|
+
var _rndBytes = new Array(16);
|
|
17
|
+
mathRNG = function() {
|
|
18
|
+
var r, b = _rndBytes, i = 0;
|
|
19
|
+
|
|
20
|
+
for (var i = 0, r; i < 16; i++) {
|
|
21
|
+
if ((i & 0x03) == 0) r = Math.random() * 0x100000000;
|
|
22
|
+
b[i] = r >>> ((i & 0x03) << 3) & 0xff;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return b;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// WHATWG crypto-based RNG - http://wiki.whatwg.org/wiki/Crypto
|
|
29
|
+
// WebKit only (currently), moderately fast, high quality
|
|
30
|
+
if (_global.crypto && crypto.getRandomValues) {
|
|
31
|
+
var _rnds = new Uint32Array(4);
|
|
32
|
+
whatwgRNG = function() {
|
|
33
|
+
crypto.getRandomValues(_rnds);
|
|
10
34
|
|
|
11
|
-
|
|
12
|
-
|
|
35
|
+
for (var c = 0 ; c < 16; c++) {
|
|
36
|
+
_rndBytes[c] = _rnds[c >> 2] >>> ((c & 0x03) * 8) & 0xff;
|
|
37
|
+
}
|
|
38
|
+
return _rndBytes;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Node.js crypto-based RNG - http://nodejs.org/docs/v0.6.2/api/crypto.html
|
|
43
|
+
// Node.js only, moderately fast, high quality
|
|
44
|
+
try {
|
|
45
|
+
var _rb = require('crypto').randomBytes;
|
|
46
|
+
nodeRNG = _rb && function() {
|
|
47
|
+
return _rb(16);
|
|
48
|
+
};
|
|
49
|
+
} catch (e) {}
|
|
50
|
+
|
|
51
|
+
// Select RNG with best quality
|
|
52
|
+
var _rng = nodeRNG || whatwgRNG || mathRNG;
|
|
13
53
|
|
|
14
|
-
//
|
|
15
|
-
var
|
|
16
|
-
|
|
54
|
+
// Buffer class to use
|
|
55
|
+
var BufferClass = typeof(Buffer) == 'function' ? Buffer : Array;
|
|
56
|
+
|
|
57
|
+
// Maps for number <-> hex string conversion
|
|
58
|
+
var _byteToHex = [];
|
|
59
|
+
var _hexToByte = {};
|
|
17
60
|
for (var i = 0; i < 256; i++) {
|
|
18
|
-
|
|
19
|
-
|
|
61
|
+
_byteToHex[i] = (i + 0x100).toString(16).substr(1);
|
|
62
|
+
_hexToByte[_byteToHex[i]] = i;
|
|
20
63
|
}
|
|
21
64
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
var i = 0,
|
|
25
|
-
|
|
26
|
-
|
|
65
|
+
// **`parse()` - Parse a UUID into it's component bytes**
|
|
66
|
+
function parse(s, buf, offset) {
|
|
67
|
+
var i = (buf && offset) || 0, ii = 0;
|
|
68
|
+
|
|
69
|
+
buf = buf || [];
|
|
70
|
+
s.toLowerCase().replace(/[0-9a-f]{2}/g, function(byte) {
|
|
71
|
+
if (ii < 16) { // Don't overflow!
|
|
72
|
+
buf[i + ii++] = _hexToByte[byte];
|
|
73
|
+
}
|
|
27
74
|
});
|
|
75
|
+
|
|
76
|
+
// Zero out remaining bytes if string was short
|
|
77
|
+
while (ii < 16) {
|
|
78
|
+
buf[i + ii++] = 0;
|
|
79
|
+
}
|
|
80
|
+
|
|
28
81
|
return buf;
|
|
29
82
|
}
|
|
30
83
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
84
|
+
// **`unparse()` - Convert UUID byte array (ala parse()) into a string**
|
|
85
|
+
function unparse(buf, offset) {
|
|
86
|
+
var i = offset || 0, bth = _byteToHex;
|
|
87
|
+
return bth[buf[i++]] + bth[buf[i++]] +
|
|
88
|
+
bth[buf[i++]] + bth[buf[i++]] + '-' +
|
|
89
|
+
bth[buf[i++]] + bth[buf[i++]] + '-' +
|
|
90
|
+
bth[buf[i++]] + bth[buf[i++]] + '-' +
|
|
91
|
+
bth[buf[i++]] + bth[buf[i++]] + '-' +
|
|
92
|
+
bth[buf[i++]] + bth[buf[i++]] +
|
|
93
|
+
bth[buf[i++]] + bth[buf[i++]] +
|
|
94
|
+
bth[buf[i++]] + bth[buf[i++]];
|
|
39
95
|
}
|
|
40
96
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
97
|
+
// **`v1()` - Generate time-based UUID**
|
|
98
|
+
//
|
|
99
|
+
// Inspired by https://github.com/LiosK/UUID.js
|
|
100
|
+
// and http://docs.python.org/library/uuid.html
|
|
101
|
+
|
|
102
|
+
// random #'s we need to init node and clockseq
|
|
103
|
+
var _seedBytes = _rng();
|
|
104
|
+
|
|
105
|
+
// Per 4.5, create and 48-bit node id, (47 random bits + multicast bit = 1)
|
|
106
|
+
var _nodeId = [
|
|
107
|
+
_seedBytes[0] | 0x01,
|
|
108
|
+
_seedBytes[1], _seedBytes[2], _seedBytes[3], _seedBytes[4], _seedBytes[5]
|
|
109
|
+
];
|
|
110
|
+
|
|
111
|
+
// Per 4.2.2, randomize (14 bit) clockseq
|
|
112
|
+
var _clockseq = (_seedBytes[6] << 8 | _seedBytes[7]) & 0x3fff;
|
|
113
|
+
|
|
114
|
+
// Previous uuid creation time
|
|
115
|
+
var _lastMSecs = 0, _lastNSecs = 0;
|
|
116
|
+
|
|
117
|
+
// See https://github.com/broofa/node-uuid for API details
|
|
118
|
+
function v1(options, buf, offset) {
|
|
44
119
|
var i = buf && offset || 0;
|
|
120
|
+
var b = buf || [];
|
|
121
|
+
|
|
122
|
+
options = options || {};
|
|
123
|
+
|
|
124
|
+
var clockseq = options.clockseq != null ? options.clockseq : _clockseq;
|
|
125
|
+
|
|
126
|
+
// UUID timestamps are 100 nano-second units since the Gregorian epoch,
|
|
127
|
+
// (1582-10-15 00:00). JSNumbers aren't precise enough for this, so
|
|
128
|
+
// time is handled internally as 'msecs' (integer milliseconds) and 'nsecs'
|
|
129
|
+
// (100-nanoseconds offset from msecs) since unix epoch, 1970-01-01 00:00.
|
|
130
|
+
var msecs = options.msecs != null ? options.msecs : new Date().getTime();
|
|
131
|
+
|
|
132
|
+
// Per 4.2.1.2, use count of uuid's generated during the current clock
|
|
133
|
+
// cycle to simulate higher resolution clock
|
|
134
|
+
var nsecs = options.nsecs != null ? options.nsecs : _lastNSecs + 1;
|
|
135
|
+
|
|
136
|
+
// Time since last uuid creation (in msecs)
|
|
137
|
+
var dt = (msecs - _lastMSecs) + (nsecs - _lastNSecs)/10000;
|
|
45
138
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
b[i++] = r>>>24 & ff;
|
|
51
|
-
r = Math.random()*b32;
|
|
52
|
-
b[i++] = r & ff;
|
|
53
|
-
b[i++] = r>>>8 & ff;
|
|
54
|
-
b[i++] = r>>>16 & 0x0f | 0x40; // See RFC4122 sect. 4.1.3
|
|
55
|
-
b[i++] = r>>>24 & ff;
|
|
56
|
-
r = Math.random()*b32;
|
|
57
|
-
b[i++] = r & 0x3f | 0x80; // See RFC4122 sect. 4.4
|
|
58
|
-
b[i++] = r>>>8 & ff;
|
|
59
|
-
b[i++] = r>>>16 & ff;
|
|
60
|
-
b[i++] = r>>>24 & ff;
|
|
61
|
-
r = Math.random()*b32;
|
|
62
|
-
b[i++] = r & ff;
|
|
63
|
-
b[i++] = r>>>8 & ff;
|
|
64
|
-
b[i++] = r>>>16 & ff;
|
|
65
|
-
b[i++] = r>>>24 & ff;
|
|
66
|
-
|
|
67
|
-
return fmt === undefined ? unparse(b) : b;
|
|
68
|
-
};
|
|
139
|
+
// Per 4.2.1.2, Bump clockseq on clock regression
|
|
140
|
+
if (dt < 0 && options.clockseq == null) {
|
|
141
|
+
clockseq = clockseq + 1 & 0x3fff;
|
|
142
|
+
}
|
|
69
143
|
|
|
144
|
+
// Reset nsecs if clock regresses (new clockseq) or we've moved onto a new
|
|
145
|
+
// time interval
|
|
146
|
+
if ((dt < 0 || msecs > _lastMSecs) && options.nsecs == null) {
|
|
147
|
+
nsecs = 0;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// Per 4.2.1.2 Throw error if too many uuids are requested
|
|
151
|
+
if (nsecs >= 10000) {
|
|
152
|
+
throw new Error('uuid.v1(): Can\'t create more than 10M uuids/sec');
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
_lastMSecs = msecs;
|
|
156
|
+
_lastNSecs = nsecs;
|
|
157
|
+
_clockseq = clockseq;
|
|
158
|
+
|
|
159
|
+
// Per 4.1.4 - Convert from unix epoch to Gregorian epoch
|
|
160
|
+
msecs += 12219292800000;
|
|
161
|
+
|
|
162
|
+
// `time_low`
|
|
163
|
+
var tl = ((msecs & 0xfffffff) * 10000 + nsecs) % 0x100000000;
|
|
164
|
+
b[i++] = tl >>> 24 & 0xff;
|
|
165
|
+
b[i++] = tl >>> 16 & 0xff;
|
|
166
|
+
b[i++] = tl >>> 8 & 0xff;
|
|
167
|
+
b[i++] = tl & 0xff;
|
|
168
|
+
|
|
169
|
+
// `time_mid`
|
|
170
|
+
var tmh = (msecs / 0x100000000 * 10000) & 0xfffffff;
|
|
171
|
+
b[i++] = tmh >>> 8 & 0xff;
|
|
172
|
+
b[i++] = tmh & 0xff;
|
|
173
|
+
|
|
174
|
+
// `time_high_and_version`
|
|
175
|
+
b[i++] = tmh >>> 24 & 0xf | 0x10; // include version
|
|
176
|
+
b[i++] = tmh >>> 16 & 0xff;
|
|
177
|
+
|
|
178
|
+
// `clock_seq_hi_and_reserved` (Per 4.2.2 - include variant)
|
|
179
|
+
b[i++] = clockseq >>> 8 | 0x80;
|
|
180
|
+
|
|
181
|
+
// `clock_seq_low`
|
|
182
|
+
b[i++] = clockseq & 0xff;
|
|
183
|
+
|
|
184
|
+
// `node`
|
|
185
|
+
var node = options.node || _nodeId;
|
|
186
|
+
for (var n = 0; n < 6; n++) {
|
|
187
|
+
b[i + n] = node[n];
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
return buf ? buf : unparse(b);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// **`v4()` - Generate random UUID**
|
|
194
|
+
|
|
195
|
+
// See https://github.com/broofa/node-uuid for API details
|
|
196
|
+
function v4(options, buf, offset) {
|
|
197
|
+
// Deprecated - 'format' argument, as supported in v1.2
|
|
198
|
+
var i = buf && offset || 0;
|
|
199
|
+
|
|
200
|
+
if (typeof(options) == 'string') {
|
|
201
|
+
buf = options == 'binary' ? new BufferClass(16) : null;
|
|
202
|
+
options = null;
|
|
203
|
+
}
|
|
204
|
+
options = options || {};
|
|
205
|
+
|
|
206
|
+
var rnds = options.random || (options.rng || _rng)();
|
|
207
|
+
|
|
208
|
+
// Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
|
|
209
|
+
rnds[6] = (rnds[6] & 0x0f) | 0x40;
|
|
210
|
+
rnds[8] = (rnds[8] & 0x3f) | 0x80;
|
|
211
|
+
|
|
212
|
+
// Copy bytes to buffer, if provided
|
|
213
|
+
if (buf) {
|
|
214
|
+
for (var ii = 0; ii < 16; ii++) {
|
|
215
|
+
buf[i + ii] = rnds[ii];
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
return buf || unparse(rnds);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// Export public API
|
|
223
|
+
var uuid = v4;
|
|
224
|
+
uuid.v1 = v1;
|
|
225
|
+
uuid.v4 = v4;
|
|
70
226
|
uuid.parse = parse;
|
|
71
227
|
uuid.unparse = unparse;
|
|
72
228
|
uuid.BufferClass = BufferClass;
|
|
73
229
|
|
|
230
|
+
// Export RNG options
|
|
231
|
+
uuid.mathRNG = mathRNG;
|
|
232
|
+
uuid.nodeRNG = nodeRNG;
|
|
233
|
+
uuid.whatwgRNG = whatwgRNG;
|
|
234
|
+
|
|
74
235
|
if (typeof(module) != 'undefined') {
|
|
236
|
+
// Play nice with node.js
|
|
75
237
|
module.exports = uuid;
|
|
76
238
|
} else {
|
|
77
|
-
//
|
|
78
|
-
|
|
239
|
+
// Play nice with browsers
|
|
240
|
+
var _previousRoot = _global.uuid;
|
|
241
|
+
|
|
242
|
+
// **`noConflict()` - (browser only) to reset global 'uuid' var**
|
|
243
|
+
uuid.noConflict = function() {
|
|
244
|
+
_global.uuid = _previousRoot;
|
|
245
|
+
return uuid;
|
|
246
|
+
}
|
|
247
|
+
_global.uuid = uuid;
|
|
79
248
|
}
|
|
80
|
-
}
|
|
249
|
+
}());
|