version-comparator
v1.1.1
Published
Function to compare two version strings (e.g. "1.6.1" is smaller than "1.7"). Developed in order to answer http://stackoverflow.com/a/6832721/50079.
Downloads
11
Readme
Version compare
Compares two software version numbers (e.g. "1.7.1" or "1.2b").
Forked from: https://github.com/Rombecchi/version-compare
@param {string} v1 The first version to be compared.
@param {string} v2 The second version to be compared.
@param {object} [options] Optional flags that affect comparison behavior:
- lexicographical: (true/[false]) compares each part of the version strings lexicographically instead of naturally; this allows suffixes such as "b" or "dev" but will cause "1.10" to be considered smaller than "1.2".
- zeroExtend: ([true]/false) changes the result if one version string has less parts than the other. In this case the shorter string will be padded with "zero" parts instead of being considered smaller.
@returns {number|NaN}
0 if the versions are equal
a negative integer if v1 < v2
a positive integer if v1 > v2
NaN if either version string is in the wrong format
UPDATE 1.1 (10-04-2018)
- [x] added defaults to lexicographical (false) and zeroExtend (true)
- [x] added alpha/beta versioning as valid parts
- [x] empty v1 or v2 param is assumed as version "0"
- [x] version not compared with lex options can accept a single char (ex: "1.10a" > "1.10")