Semver Calculator
Parse, compare, and bump semantic versions.Runs in this tab.⌘ ↵ runs it
How to use Semver Calculator
- Type a version in Version. A leading v is ignored. The page shows Major, Minor, Patch, and Pre-release when the string matches MAJOR.MINOR.PATCH with an optional -prerelease.
- Click Major, Minor, or Patch under Bump Version. The new version is written back into the field.
- Type a second exact version in Compare With. This checker compares exact versions. The range section in the guide is about npm. The widget does not test ^ or ~ ranges.
What the semver checker accepts
The version field takes MAJOR.MINOR.PATCH with an optional -prerelease suffix. A leading lowercase v and surrounding whitespace are ignored, so v1.2.3 and 1.2.3 compare as equal. Clicking a bump button writes the new version back into the field, so you can chain bumps.
It rejects partial versions (1.2), four-part versions (1.2.3.4), ranges (^1.2.3), an uppercase V, and build metadata on its own (1.0.0+build.5). Two spots where it is more lenient than the SemVer 2.0.0 spec:
- Leading zeros are accepted.
01.02.03reads as 1.2.3; npm’ssemverpackage rejects it. - Everything after the first hyphen is the prerelease, including any
+buildpart.1.0.0-rc.1+build.5shows a prerelease ofrc.1+build.5and compares higher than1.0.0-rc.1, while the spec says build metadata is ignored for precedence.
How comparison and bumping work here
Major, minor and patch are compared as numbers, so 1.10.0 > 1.9.0 (a plain string sort gets this wrong). A release beats any prerelease of the same version.
Prerelease tags are then compared as whole strings. That gives the spec’s answer for the common cases (alpha < alpha.1 < alpha.beta < beta < rc.1) but not when numeric parts have different digit counts. The spec compares numeric identifiers as numbers, so beta.11 is newer than beta.2. This tool reports 1.0.0-beta.2 > 1.0.0-beta.11 and 1.0.0-rc.9 > 1.0.0-rc.10. For those, use the CLI sort below.
Bumps always increment the field and drop the prerelease. npm’s semver -i treats a prerelease differently: bumping it releases the version it was leading up to.
| Current | This tool (major / minor / patch) | semver -i (major / minor / patch) |
|---|---|---|
1.2.3 |
2.0.0 / 1.3.0 / 1.2.4 | 2.0.0 / 1.3.0 / 1.2.4 |
1.2.3-beta.1 |
2.0.0 / 1.3.0 / 1.2.4 | 2.0.0 / 1.3.0 / 1.2.3 |
2.0.0-rc.1 |
3.0.0 / 2.1.0 / 2.0.1 | 2.0.0 / 2.0.0 / 2.0.0 |
To promote 2.0.0-rc.1 to a stable release, remove the suffix rather than clicking Major.
npm range operators: what each one matches
This calculator compares exact versions; it doesn’t test ranges. If you need a semver tester for package.json ranges, this is what npm (via the semver package) expands each operator to:
| Range | Expands to | Matches | Doesn’t match |
|---|---|---|---|
^1.2.3 |
>=1.2.3 <2.0.0-0 |
1.2.3, 1.9.0 | 1.2.0, 2.0.0 |
^0.2.3 |
>=0.2.3 <0.3.0-0 |
0.2.9 | 0.3.0 |
^0.0.3 |
>=0.0.3 <0.0.4-0 |
0.0.3 only | 0.0.4 |
~1.2.3 |
>=1.2.3 <1.3.0-0 |
1.2.9 | 1.3.0 |
~1 |
>=1.0.0 <2.0.0-0 |
1.9.9 | 2.0.0 |
1.2.x, 1.2 |
>=1.2.0 <1.3.0-0 |
1.2.0, 1.2.9 | 1.3.0 |
*, x, "" |
any version | 0.1.0, 9.0.0 | prereleases |
1.2.3 - 2.3.4 |
>=1.2.3 <=2.3.4 |
2.3.4 | 2.3.5 |
1.2 - 2.3 |
>=1.2.0 <2.4.0-0 |
2.3.9 | 2.4.0 |
1.2.3 || 2.x |
either side | 1.2.3, 2.0.0 | 1.2.4 |
Note that a partial version on the right of a hyphen range takes in that whole line: 1.2 - 2.3 includes every 2.3.x.
The ^0.x gotcha
The caret allows changes that don’t touch the leftmost non-zero number. For 1.x that means minor and patch updates, but for 0.x packages it shrinks: ^0.2.3 only accepts 0.2.x patches, and ^0.0.3 accepts exactly 0.0.3. Because npm install saves dependencies with ^ by default, a 0.x dependency never moves to the next minor until you edit the range. That’s intentional (in 0.x, a minor bump may break things), but it surprises people who expect ^ to mean “compatible updates” everywhere.
Prerelease matching rules
By default, a range only matches a prerelease if one of its comparators has a prerelease on the same major.minor.patch:
1.3.0-beta.1does not satisfy^1.2.0.2.0.0-rc.1does not satisfy>=1.0.0, or even*.^1.2.3-beta.2matches1.2.3-beta.4and1.2.4, but not1.2.4-beta.2.
This keeps npm update from pulling in betas you never opted into. To include them, pass --include-prerelease (-p) on the CLI or { includePrerelease: true } in code.
Checking versions from the CLI
# Which versions satisfy a range? Prints the matches; exits 1 if none
npx semver -r '^0.2.3' 0.2.3 0.2.9 0.3.0 1.0.0
# 0.2.3
# 0.2.9
# Sort by precedence, with numeric prerelease parts handled correctly
npx semver 1.0.0 1.0.0-beta.11 1.0.0-beta.2 1.0.0-rc.1
# 1.0.0-beta.2
# 1.0.0-beta.11
# 1.0.0-rc.1
# 1.0.0
# Increment, including prerelease bumps
npx semver -i patch 1.2.3-beta.1 # 1.2.3
npx semver -i prerelease --preid beta 1.2.3 # 1.2.4-beta.0
const semver = require('semver');
semver.satisfies('1.3.0-beta.1', '^1.2.0'); // false
semver.satisfies('1.3.0-beta.1', '^1.2.0', { includePrerelease: true }); // true
semver.validRange('^0.2.3'); // '>=0.2.3 <0.3.0-0'
Once you’ve picked the next version, the changelog formatter gets the release notes into Keep a Changelog shape, and the package.json generator sets the version field for a new package.
Next step
Turn a click-through into an interactive demo
AtriumKit records your web app once in Chrome and turns every click into a step of a demo you can embed or share. There’s a free plan.
Try AtriumKit freeQuestions
Is this a semver checker?
Is this a semver validator?
Is this a semver tester for npm ranges?
Comments
More in DevOps & Config
- .gitignore Generator
- Dockerfile Generator
- Docker Compose Generator
- Nginx Config Generator
- .editorconfig Generator
- .env File Generator
- GitHub Actions Generator
- README Generator
Comments