About semver comparator
Compare two versions, sort a list and test whether a version satisfies a range.
Why not compare as text
As text, 1.10.0 sorts before 1.9.0. Semantic comparison treats each part as a number, so 1.10.0 is correctly newer.
A worked example
Comparing 1.10.0 and 1.9.0 shows that 1.10.0 is newer, although a text sort would put it first. A pre-release such as 2.0.0-rc.1 is older than 2.0.0. Sorting [1.2.0, 1.10.0, 1.9.5] gives 1.2.0, 1.9.5, 1.10.0.
Testing ranges
- Check whether 3.1.4 satisfies >=3.0.0 <4.0.0, which it does.
- Pre-release versions only match a range if it also names a pre-release.
- Use the result to decide if an upgrade will be accepted by your package.json.
Build metadata
The part after a plus sign, such as +build.5, is ignored when comparing versions, so 1.0.0+a and 1.0.0+b are considered equal in precedence.
