• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env node
2var assert = require('assert');
3
4function usage() {
5  console.log('Usage:');
6  console.log('  uuid');
7  console.log('  uuid v1');
8  console.log('  uuid v3 <name> <namespace uuid>');
9  console.log('  uuid v4');
10  console.log('  uuid v5 <name> <namespace uuid>');
11  console.log('  uuid --help');
12  console.log('\nNote: <namespace uuid> may be "URL" or "DNS" to use the corresponding UUIDs defined by RFC4122');
13}
14
15var args = process.argv.slice(2);
16
17if (args.indexOf('--help') >= 0) {
18  usage();
19  process.exit(0);
20}
21var version = args.shift() || 'v4';
22
23switch (version) {
24  case 'v1':
25    var uuidV1 = require('../v1');
26    console.log(uuidV1());
27    break;
28
29  case 'v3':
30    var uuidV3 = require('../v3');
31
32    var name = args.shift();
33    var namespace = args.shift();
34    assert(name != null, 'v3 name not specified');
35    assert(namespace != null, 'v3 namespace not specified');
36
37    if (namespace == 'URL') namespace = uuidV3.URL;
38    if (namespace == 'DNS') namespace = uuidV3.DNS;
39
40    console.log(uuidV3(name, namespace));
41    break;
42
43  case 'v4':
44    var uuidV4 = require('../v4');
45    console.log(uuidV4());
46    break;
47
48  case 'v5':
49    var uuidV5 = require('../v5');
50
51    var name = args.shift();
52    var namespace = args.shift();
53    assert(name != null, 'v5 name not specified');
54    assert(namespace != null, 'v5 namespace not specified');
55
56    if (namespace == 'URL') namespace = uuidV5.URL;
57    if (namespace == 'DNS') namespace = uuidV5.DNS;
58
59    console.log(uuidV5(name, namespace));
60    break;
61
62  default:
63    usage();
64    process.exit(1);
65}
66