Skip to content

Semver Calculator

Embed

Paste this where you want Semver Calculator on your site. Adjust the height to fit.

<iframe src="https://www.browserutils.dev/embed/semver-calculator/" width="100%" height="500" frameborder="0" loading="lazy" title="Semver Calculator"></iframe>
<p style="font-size:12px;margin:4px 0 0"><a href="https://www.browserutils.dev/tools/semver-calculator/">Semver Calculator</a> by BrowserUtils</p>

Parse, compare, and bump semantic versions.Runs in this tab.

Major
1
Minor
2
Patch
3
1.2.3 < 1.3.0 (1.3.0 is newer)

How to use Semver Calculator

  1. 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.
  2. Click Major, Minor, or Patch under Bump Version. The new version is written back into the field.
  3. 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.03 reads as 1.2.3; npm’s semver package rejects it.
  • Everything after the first hyphen is the prerelease, including any +build part. 1.0.0-rc.1+build.5 shows a prerelease of rc.1+build.5 and compares higher than 1.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.1 does not satisfy ^1.2.0.
  • 2.0.0-rc.1 does not satisfy >=1.0.0, or even *.
  • ^1.2.3-beta.2 matches 1.2.3-beta.4 and 1.2.4, but not 1.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

Questions

Is this a semver checker?
It parses one exact version and compares it with a second exact version. The Version field accepts MAJOR.MINOR.PATCH and an optional -prerelease, with an optional leading v. The page opens on 1.2.3 compared with 1.3.0.
Is this a semver validator?
A string is accepted when it is MAJOR.MINOR.PATCH with an optional -prerelease. Ranges such as ^1.2.3, a partial version such as 1.2, and a bare +build are rejected. The message under the field says to enter a valid semver string. Leading zeros are accepted here even though the SemVer spec rejects them. The guide lists the other lenient cases.
Is this a semver tester for npm ranges?
It does not evaluate ^, ~, or other npm ranges. The guide has a range table so you can read what npm does. The three buttons only bump the exact version in the field.

More in DevOps & Config

All 16 devops & config