| 1 |
import * as assert from 'node:assert/strict'; |
| 2 |
import v1 from './v1.js'; |
| 3 |
import v3 from './v3.js'; |
| 4 |
import v4 from './v4.js'; |
| 5 |
import v5 from './v5.js'; |
| 6 |
import v6 from './v6.js'; |
| 7 |
import v7 from './v7.js'; |
| 8 |
function usage() { |
| 9 |
console.log('Usage:'); |
| 10 |
console.log(' uuid'); |
| 11 |
console.log(' uuid v1'); |
| 12 |
console.log(' uuid v3 <name> <namespace uuid>'); |
| 13 |
console.log(' uuid v4'); |
| 14 |
console.log(' uuid v5 <name> <namespace uuid>'); |
| 15 |
console.log(' uuid v6'); |
| 16 |
console.log(' uuid v7'); |
| 17 |
console.log(' uuid --help'); |
| 18 |
console.log('\nNote: <namespace uuid> may be "URL" or "DNS" to use the corresponding UUIDs defined by RFC9562'); |
| 19 |
} |
| 20 |
const args = process.argv.slice(2); |
| 21 |
if (args.indexOf('--help') >= 0) { |
| 22 |
usage(); |
| 23 |
process.exit(0); |
| 24 |
} |
| 25 |
const version = args.shift() || 'v4'; |
| 26 |
switch (version) { |
| 27 |
case 'v1': |
| 28 |
console.log(v1()); |
| 29 |
break; |
| 30 |
case 'v3': { |
| 31 |
const name = args.shift(); |
| 32 |
let namespace = args.shift(); |
| 33 |
assert.ok(name != null, 'v3 name not specified'); |
| 34 |
assert.ok(namespace != null, 'v3 namespace not specified'); |
| 35 |
if (namespace === 'URL') { |
| 36 |
namespace = v3.URL; |
| 37 |
} |
| 38 |
if (namespace === 'DNS') { |
| 39 |
namespace = v3.DNS; |
| 40 |
} |
| 41 |
console.log(v3(name, namespace)); |
| 42 |
break; |
| 43 |
} |
| 44 |
case 'v4': |
| 45 |
console.log(v4()); |
| 46 |
break; |
| 47 |
case 'v5': { |
| 48 |
const name = args.shift(); |
| 49 |
let namespace = args.shift(); |
| 50 |
assert.ok(name != null, 'v5 name not specified'); |
| 51 |
assert.ok(namespace != null, 'v5 namespace not specified'); |
| 52 |
if (namespace === 'URL') { |
| 53 |
namespace = v5.URL; |
| 54 |
} |
| 55 |
if (namespace === 'DNS') { |
| 56 |
namespace = v5.DNS; |
| 57 |
} |
| 58 |
console.log(v5(name, namespace)); |
| 59 |
break; |
| 60 |
} |
| 61 |
case 'v6': |
| 62 |
console.log(v6()); |
| 63 |
break; |
| 64 |
case 'v7': |
| 65 |
console.log(v7()); |
| 66 |
break; |
| 67 |
default: |
| 68 |
usage(); |
| 69 |
process.exit(1); |
| 70 |
} |