Semver comparator
Enter two versions to see which one is newer and what kind of change it is. Enter a range such as ^1.2.3 and a list of versions to see which ones match, with the range expanded into plain comparators.
Runs in your browser: nothing you enter is sent anywhere.
How to use it
- Type two versions in A and B. The result shows which is higher and where they first differ.
- Type a range, or click an example.
- List versions to test, one per line. Each is marked as matching or not, and the highest match is shown.
How ranges are read
| Written |
Means |
^1.2.3 |
>=1.2.3 <2.0.0-0 |
~1.2.3 |
>=1.2.3 <1.3.0-0 |
1.2.x or 1.2 |
>=1.2.0 <1.3.0-0 |
1.2.3 - 2.3.4 |
>=1.2.3 <=2.3.4 |
>=1.0.0 <2.0.0 |
both must hold |
1.x || >=3.1.0 |
either may hold |
* or empty |
any release version |
Example
With the range ^1.2.3, the versions 1.2.2 and 2.0.0 do not match, while 1.2.3 and 1.9.0 do. 1.3.0-beta.1 does not match either, because the range names no prerelease.
Tips
Versions may start with v (as in tags such as v1.4.2); the v is dropped. Leading zeros such as 01.2.3 are not valid SemVer.
Frequently asked questions
How does SemVer decide which version is higher?
It compares major, then minor, then patch as numbers, so 1.10.0 is higher than 1.9.0. A version with a prerelease tag is lower than the same version without one, so 1.0.0-rc.1 is lower than 1.0.0. Build metadata after + is ignored.
How are prerelease tags ordered?
Dot-separated identifiers are compared one by one. Numbers compare as numbers and are lower than words, words compare in ASCII order, and a shorter list is lower when all earlier identifiers are equal. So 1.0.0-alpha < 1.0.0-alpha.1 < 1.0.0-alpha.beta < 1.0.0-beta < 1.0.0-beta.2 < 1.0.0-beta.11 < 1.0.0-rc.1.
What do ^ and ~ mean?
^1.2.3 allows changes that keep the left-most non-zero part: >=1.2.3 <2.0.0. ^0.2.3 means >=0.2.3 <0.3.0 and ^0.0.3 means only 0.0.3. ~1.2.3 allows patch changes: >=1.2.3 <1.3.0. These are npm's rules.
Why does 1.3.0-beta.1 not match ^1.2.0?
In npm, a prerelease version only satisfies a range if the range itself contains a prerelease of the same major.minor.patch. This stops a beta of a future version from being installed by accident. Ranges like >=1.3.0-beta.0 <2.0.0 do match it.
Why is the upper bound written as <2.0.0-0?
2.0.0-0 is the lowest possible prerelease of 2.0.0. Using it as the exclusive bound keeps every 2.0.0 prerelease out of a ^1.x range, which matches what npm does.