Created
December 20, 2015 22:22
-
-
Save felipap/450df185c9e54eac1a2a to your computer and use it in GitHub Desktop.
Compares two semvers.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function cmpSemver(v1, v2) { | |
if (v1 === "") { | |
return v2 === "" ? 0 : -1; | |
} else if (v2 === "") { | |
return 1; | |
} | |
var e1 = v1.match(/^(\d+)\.?(.*)/), e2 = v2.match(/^(\d+)\.?(.*)/); | |
if (parseInt(e1[1]) === parseInt(e2[1])) | |
return cmpVersions(e1[2], e2[2]); | |
return parseInt(e1[1]) > parseInt(e2[1]) ? 1 : -1; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment