semver-compare.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports["default"] = _default;
  6. // Copy-pasted from:
  7. // https://github.com/substack/semver-compare/blob/master/index.js
  8. //
  9. // Inlining this function because some users reported issues with
  10. // importing from `semver-compare` in a browser with ES6 "native" modules.
  11. //
  12. // Fixes `semver-compare` not being able to compare versions with alpha/beta/etc "tags".
  13. // https://github.com/catamphetamine/libphonenumber-js/issues/381
  14. function _default(a, b) {
  15. a = a.split('-');
  16. b = b.split('-');
  17. var pa = a[0].split('.');
  18. var pb = b[0].split('.');
  19. for (var i = 0; i < 3; i++) {
  20. var na = Number(pa[i]);
  21. var nb = Number(pb[i]);
  22. if (na > nb) return 1;
  23. if (nb > na) return -1;
  24. if (!isNaN(na) && isNaN(nb)) return 1;
  25. if (isNaN(na) && !isNaN(nb)) return -1;
  26. }
  27. if (a[1] && b[1]) {
  28. return a[1] > b[1] ? 1 : a[1] < b[1] ? -1 : 0;
  29. }
  30. return !a[1] && b[1] ? 1 : a[1] && !b[1] ? -1 : 0;
  31. }
  32. //# sourceMappingURL=semver-compare.js.map