Semver Comparator

Compare two versions, sort a list, see the next major, minor or patch version, or check which versions fit a range written the way package managers write them.

What would you like to do?

Worked examples

Order of pre-releases

1.0.0-alpha, 1.0.0-alpha.1, 1.0.0-beta.2, 1.0.0-beta.11, 1.0.0-rc.1, 1.0.0

Already in order, oldest first

The example order comes from the semantic versioning specification.

Caret range

^0.2.3

>=0.2.3 <0.3.0-0

For 0.x versions the caret stops at the next minor.

Pre-release bump

1.2.3 prerelease with label beta

1.2.4-beta.0

The patch moves on and the label starts at 0.

About Semver Comparator

Semantic versioning writes a release as major.minor.patch, with an optional pre-release such as 2.0.0-beta.1 and optional build details after a plus sign. The ordering rules look obvious but have traps: 1.10.0 is newer than 1.9.0, 1.0.0-rc.1 is older than 1.0.0, and build details never change the order. Package managers add range syntax on top, such as ^1.2.3, ~1.2 and 1.x, with their own rules for what the symbols allow.

This tool compares two versions and names the biggest difference, sorts a list in either direction, shows the next version for every kind of bump, and tests a list of versions against a range. The range is written out as plain comparisons, so you can see exactly what ^0.2.3 or 1.2.3 - 2.3 means. It also applies the rule that a pre-release version only matches a range that mentions the same major, minor and patch with a pre-release, which is the behaviour that surprises people most.

How to use Semver Comparator

  1. Choose to compare two versions, sort a list, check a range or bump a version.
  2. Type the versions. A leading v is accepted.
  3. For a range check, enter the range, such as ^1.2.3 || ~2.0.
  4. Read the result table, and copy what you need.

Common uses

  • Working out whether a dependency update stays inside its range
  • Sorting a list of release tags
  • Deciding the next version number for a release
  • Explaining what a caret or tilde range allows

Frequently asked questions

What does ^1.2.3 allow?

Anything from 1.2.3 up to but not including 2.0.0. The caret allows changes that do not alter the leftmost non-zero part, so ^0.2.3 allows up to but not including 0.3.0, and ^0.0.3 allows only 0.0.3.

What does ~1.2.3 allow?

Patch changes only: from 1.2.3 up to but not including 1.3.0. The form ~1 allows anything from 1.0.0 up to but not including 2.0.0.

How are pre-releases ordered?

A pre-release is older than its release. Identifiers are compared part by part, numbers as numbers and below text, so 1.0.0-alpha is older than 1.0.0-alpha.1, which is older than 1.0.0-beta.

Why does a pre-release not match my range?

A pre-release only satisfies a range if some comparator in it names a pre-release of the same major, minor and patch. So 1.2.4-beta.2 does not satisfy ^1.2.3, which avoids picking up unstable builds by accident.

Is the build metadata used?

No. Everything after the plus sign is ignored when comparing, so 1.0.0+a and 1.0.0+b are equal.