Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

compare-ver

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

compare-ver

Compares two software version numbers (only number)

  • 2.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3.4K
increased by16.92%
Maintainers
1
Weekly downloads
 
Created
Source

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.

Keywords

FAQs

Package last updated on 25 Jan 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc