Skip to content

Semver range checker

Free, no sign-up Runs in your browser

Check whether a version satisfies an npm semver range. Supports ^, ~, x-ranges, hyphen ranges, || and pre-releases, and shows what the range really means.

As in package.json: ^1.2.3, ~1.2, 1.x, >=1.0.0 <2.0.0, 1.2.3 - 2.3.4, or several joined by ||.

One per line, or separated by commas.

Everything you type here stays in your browser. Nothing is sent to HardenKit or to anyone else.

How to use the semver range checker

  1. Type a range as it appears in package.json, for example ^1.2.3 or >=1.0.0 <2.0.0.
  2. Read “The range means” to see the range as plain comparisons.
  3. Paste the versions you want to test, one per line.
  4. Read the table: each version satisfies the range, does not, or is not valid semver.

About this tool

The ranges in package.json decide which versions npm, Yarn and pnpm may install. ^1.2.3 allows changes that do not touch the leftmost non-zero number: anything from 1.2.3 up to, not including, 2.0.0. ~1.2.3 allows patch releases only: up to, not including, 1.3.0. A range is shorthand for a set of plain comparisons, and this tool writes that set out, so ^1.2.3 is shown as >=1.2.3 <2.0.0-0.

The surprises are at the edges. For versions below 1.0.0 the caret is stricter: ^0.2.3 stops before 0.3.0 and ^0.0.3 allows 0.0.3 alone. Pre-releases such as 2.0.0-beta.1 are left out of every range unless the range itself names a pre-release of the same major, minor and patch version. So 1.2.4-beta.1 does not satisfy ^1.2.3, although it sorts between 1.2.3 and 2.0.0.

Ranges matter for security in both directions. A range that is too wide, such as * or >=1.0.0, installs whatever is published next, a hijacked release included. A range that is too narrow can keep you on a vulnerable version after the fix is out. Paste the range and the fixed version of an advisory to see whether a plain reinstall would pick the fix up.

Sources

Questions

What is the difference between ^ and ~ in package.json?

A caret allows minor and patch updates: ^1.2.3 matches 1.2.3 up to, not including, 2.0.0. A tilde allows patch updates only: ~1.2.3 matches 1.2.3 up to, not including, 1.3.0. Below 1.0.0 the caret narrows, so ^0.2.3 behaves like ~0.2.3.

Why does a pre-release version not match my range?

By design. A pre-release such as 1.3.0-beta.1 may break things, so npm only lets it satisfy a range that names a pre-release of the same version, such as >=1.3.0-beta.0. To opt in you have to write the pre-release into the range yourself.

What does the -0 in <2.0.0-0 mean?

It is the lowest possible pre-release of 2.0.0. Writing the upper limit as <2.0.0-0 instead of <2.0.0 makes sure that pre-releases of 2.0.0, which sort below 2.0.0, are shut out too. npm prints ranges this way.

Does this tool behave exactly like npm?

It follows the range grammar of node-semver, the library npm uses, with its default options: strict version parsing and pre-releases excluded. The loose and includePrerelease options are not offered. Dist-tags such as latest and URLs are not ranges and are reported as invalid.

Is 1.2 or v1.2.3 a valid version?

A semantic version has three numbers, so 1.2 is not a version, although it is a valid range meaning any 1.2.x. A leading v is accepted and ignored. Numbers cannot have leading zeros: 1.02.3 is invalid.

Related tools