You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233
  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. };