semver-compare.js 930 B

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