Tools / Semver range checker
Semver range checker for npm-style version ranges
Enter a range as you would write it in package.json and a list of versions. Each version is checked the way npm checks it, and the range is expanded into the comparators it stands for.
What the range means
| Version | Result | Why |
|---|
Examples:
How ranges expand
| Range | Means | Note |
|---|---|---|
^1.2.3 | >=1.2.3 <2.0.0-0 | changes that do not touch the first non-zero part |
^0.2.3 | >=0.2.3 <0.3.0-0 | before 1.0.0 the minor version counts as breaking |
^0.0.3 | >=0.0.3 <0.0.4-0 | only that exact patch |
~1.2.3 | >=1.2.3 <1.3.0-0 | patch updates only |
~1 | >=1.0.0 <2.0.0-0 | with only a major version, minor updates too |
1.x | >=1.0.0 <2.0.0-0 | same as 1 or 1.* |
1.2.3 - 2.3 | >=1.2.3 <2.4.0-0 | a partial upper bound includes the whole 2.3 line |
1.2.3 | 1.2.3 | a bare version means exactly that version in npm |
The -0 at the end of an upper bound is the lowest possible pre-release. <2.0.0-0 therefore also excludes 2.0.0-alpha, which would otherwise sort below 2.0.0.
Pre-releases
A version with a pre-release tag, such as 2.0.0-beta.2, matches only if one comparator in the same part of the range names a pre-release of the same major.minor.patch. >=2.0.0-beta.1 <2.1 accepts 2.0.0-beta.2, but >=1.0.0 does not accept 2.0.0-beta.2, although it sorts above 1.0.0. node-semver's includePrerelease option turns this rule off; this page always applies it.
Pre-release parts are compared one by one: numbers numerically, text in ASCII order, and a number sorts before text. So beta.2 comes before beta.11, and 1.0.0-rc.1 before 1.0.0. Build metadata after + is ignored when comparing.
Other package managers differ
Cargo reads a bare 1.2.3 as ^1.2.3, where npm reads it as exactly 1.2.3. Composer's ~1.2 means >=1.2 <2.0.0, where npm's means >=1.2.0 <1.3.0. Python packages use PEP 440 instead of SemVer, with ~= for compatible releases. Check the rules of the tool that reads the range.
How it works and what was checked
The page implements the SemVer 2.0.0 precedence rules and npm's range syntax in its own JavaScript, which runs in this page. It was tested against node-semver, the package npm itself uses: 3,000 version strings, 3,000 ranges and 20,000 version and range pairs gave the same results. npm's "loose" mode, which accepts some malformed versions, is not supported: 1.04.0 is rejected here, as SemVer requires.