index.js 645 B

12345678910111213141516171819202122232425262728293031323334
  1. 'use strict';
  2. /**
  3. * Compare semver version numbers
  4. *
  5. * @param {String} a
  6. * @param {String} b
  7. * @api public
  8. */
  9. module.exports = function(a, b) {
  10. var i;
  11. var len;
  12. if (typeof a + typeof b !== 'stringstring') {
  13. return false;
  14. }
  15. a = a.split('.');
  16. b = b.split('.');
  17. i = 0;
  18. len = Math.max(a.length, b.length);
  19. for (; i < len; i++) {
  20. if ((a[i] && !b[i] && parseInt(a[i]) > 0) || (parseInt(a[i]) > parseInt(b[i]))) {
  21. return 1;
  22. } else if ((b[i] && !a[i] && parseInt(b[i]) > 0) || (parseInt(a[i]) < parseInt(b[i]))) {
  23. return -1;
  24. }
  25. }
  26. return 0;
  27. };