rittenhop-dev/versions/5.94.2/node_modules/compare-ver
2024-09-23 19:40:12 -04:00
..
tests first commit 2024-09-23 19:40:12 -04:00
.npmignore first commit 2024-09-23 19:40:12 -04:00
doc.md first commit 2024-09-23 19:40:12 -04:00
index.coffee first commit 2024-09-23 19:40:12 -04:00
index.js first commit 2024-09-23 19:40:12 -04:00
karma.conf.js first commit 2024-09-23 19:40:12 -04:00
package.json first commit 2024-09-23 19:40:12 -04:00
README.md first commit 2024-09-23 19:40:12 -04:00
test.png first commit 2024-09-23 19:40:12 -04:00

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');

//gt
console.log(compareVer.gt("0.0.2","0.0.1")); //1
console.log(compareVer.gt("0.9.1","0.9.1")); //0

//lt
console.log(compareVer.lt("0.0.2","0.0.1")); //-1
console.log(compareVer.lt("0.9.1","0.9.1")); //0

//clean
console.log(compareVer.clean(['1.1.b','1.0.1',12121])); //['1.0.1']

var arr = ["1.7.0","1.7","1.ab.8","1.70.0","1.90","1.9.0","1.8"];
compareVer.sort(arr); //->["1.7","1.7.0","1.8","1.9.0","1.70.0","1.90"]
compareVer.max(arr); //->"1.90"
compareVer.min(arr); //->"1.7"

License

MIT License © lmtdit

End.