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 = require('compare-ver');
console.log(compareVer.gt("0.0.2","0.0.1"));
console.log(compareVer.gt("0.9.1","0.9.1"));
console.log(compareVer.lt("0.0.2","0.0.1"));
console.log(compareVer.lt("0.9.1","0.9.1"));
console.log(compareVer.clean(['1.1.b','1.0.1',12121]));
var arr = ["1.7.0","1.7","1.ab.8","1.70.0","1.90","1.9.0","1.8"];
compareVer.sort(arr);
compareVer.max(arr);
compareVer.min(arr);
License
MIT License © lmtdit
End.