util.js 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. 'use strict';
  2. var __importDefault = (this && this.__importDefault) || function (mod) {
  3. return (mod && mod.__esModule) ? mod : { "default": mod };
  4. };
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. // As Errlop uses Editions, we should use a specific Errlop edition
  7. // As otherwise, the circular reference may fail on some machines
  8. // https://github.com/bevry/errlop/issues/2
  9. var errlop_1 = __importDefault(require("errlop"));
  10. /**
  11. * Allow code and level inputs on Errlop.
  12. * We do this instead of a class extension, as class extensions do not interop well on node 0.8, which is our target.
  13. */
  14. function errtion(opts, parent) {
  15. var message = opts.message, code = opts.code, level = opts.level;
  16. var error = new errlop_1.default(message, parent);
  17. if (code)
  18. error.code = code;
  19. if (level)
  20. error.level = level;
  21. return error;
  22. }
  23. exports.errtion = errtion;
  24. /** Converts anything to a string, by returning strings and serialising objects. */
  25. function stringify(value) {
  26. return typeof value === 'string' ? value : JSON.stringify(value);
  27. }
  28. exports.stringify = stringify;
  29. /** Converts a version range like `4 || 6` to `>=4` */
  30. function simplifyRange(range) {
  31. return range.replace(/^([.\-\w]+)(\s.+)?$/, '>=$1');
  32. }
  33. exports.simplifyRange = simplifyRange;