compare-version
Compares two software version numbers (only number)
This code just uses Array.shift and recursive, which means that it can run in IE 6+.
Install
$ npm install --save compare-ver
version rules
{num}.{num}. …… {num}.{num}
e.g:
"1.7" < "1.7.1" < "1.7.10" < "1.7.10.01" < "1.7.0.10.010"
"1.0" < "1.0.1" < "2.0" < "2.0.0.1" < "2.0.1"
"1.0.0.0" < "1.0.1.0" < "2.0.0.0" < "2.0.0.1" < "2.0.1.0"
Usage
compareVer.gt(stringA,stringB)
Return number 1 0 -1 -2 -3 -100
- if stringA < stringB then return -1
- if stringA === stringB then return 0
- if stringA > stringB then return 1
- if input error value then return < -1
compareVer.lt(stringA,stringB)
Return number 1 0 -1 -2 -3 -100
- if stringA < stringB then return 1
- if stringA === stringB then return 0
- if stringA > stringB then return -1
- if input error value then return < -1
var compareVer = ; //gtconsole; //1console; //0 //ltconsole; //-1console; //0 //cleanconsole; //['1.0.1'] var arr = "1.7.0""1.7""1.ab.8""1.70.0""1.90""1.9.0""1.8";compareVer; //->["1.7","1.7.0","1.8","1.9.0","1.70.0","1.90"]compareVer; //->"1.90"compareVer; //->"1.7"