uuid-bin.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. "use strict";
  2. var _assert = _interopRequireDefault(require("assert"));
  3. var _v = _interopRequireDefault(require("./v1.js"));
  4. var _v2 = _interopRequireDefault(require("./v3.js"));
  5. var _v3 = _interopRequireDefault(require("./v4.js"));
  6. var _v4 = _interopRequireDefault(require("./v5.js"));
  7. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  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 --help');
  16. console.log('\nNote: <namespace uuid> may be "URL" or "DNS" to use the corresponding UUIDs defined by RFC4122');
  17. }
  18. const args = process.argv.slice(2);
  19. if (args.indexOf('--help') >= 0) {
  20. usage();
  21. process.exit(0);
  22. }
  23. const version = args.shift() || 'v4';
  24. switch (version) {
  25. case 'v1':
  26. console.log((0, _v.default)());
  27. break;
  28. case 'v3':
  29. {
  30. const name = args.shift();
  31. let namespace = args.shift();
  32. (0, _assert.default)(name != null, 'v3 name not specified');
  33. (0, _assert.default)(namespace != null, 'v3 namespace not specified');
  34. if (namespace === 'URL') {
  35. namespace = _v2.default.URL;
  36. }
  37. if (namespace === 'DNS') {
  38. namespace = _v2.default.DNS;
  39. }
  40. console.log((0, _v2.default)(name, namespace));
  41. break;
  42. }
  43. case 'v4':
  44. console.log((0, _v3.default)());
  45. break;
  46. case 'v5':
  47. {
  48. const name = args.shift();
  49. let namespace = args.shift();
  50. (0, _assert.default)(name != null, 'v5 name not specified');
  51. (0, _assert.default)(namespace != null, 'v5 namespace not specified');
  52. if (namespace === 'URL') {
  53. namespace = _v4.default.URL;
  54. }
  55. if (namespace === 'DNS') {
  56. namespace = _v4.default.DNS;
  57. }
  58. console.log((0, _v4.default)(name, namespace));
  59. break;
  60. }
  61. default:
  62. usage();
  63. process.exit(1);
  64. }