Skip to content
My Tiny Utils

Search tools

Type to find a tool, then press Enter to open it.

Semver Range Checker

Check whether a version satisfies an npm semver range like ^1.2.3 or ~2.0, see the range expanded into plain comparators, and test a whole list of versions at once.

Processed locally in your browser — nothing is uploaded.

Semver Range Checker

Desugared range

>=1.2.3 <2.0.0-0

  • ^1.2.3means>=1.2.3 <2.0.0-0Caret range

Satisfies

1.4.0 meets every comparator in >=1.2.3 <2.0.0-0.

About Semver Range Checker

Type a version range the way it appears in a package.json — ^1.2.3, ~2.0, 1.x, >=1.2.0 <2.0.0, 1.2.3 - 2.3.4, or several of them joined with || — and the checker expands it into the plain comparators it stands for, using the same rules as node-semver, the library npm uses. ^1.2.3 becomes >=1.2.3 <2.0.0-0, ~1.2 becomes >=1.2.0 <1.3.0-0, and each piece of the range is labelled caret, tilde, X-range, hyphen range, or comparator.

Then check a version against it, or paste a list of versions — one per line — to see which ones satisfy the range, which don't, and which aren't valid versions at all, with the highest satisfying version picked out (what node-semver's maxSatisfying returns). Each verdict comes with a reason: the comparator a version fails and whether it is too high or too low, or the prerelease rule that excludes it.

How the range syntax works:

  • A space means AND, || means OR. >=1.2.0 <2.0.0 needs both comparators to match; ^1.0.0 || ^2.0.0 matches either.
  • Caret (^) allows changes that don't modify the left-most non-zero number. ^1.2.3 allows anything below 2.0.0, ^0.2.3 stays below 0.3.0, and ^0.0.3 allows only 0.0.3.
  • Tilde (~) allows patch changes when a minor version is given — ~1.2.3 stays below 1.3.0 — and minor changes when it isn't: ~1 is the same as 1.x.
  • X-ranges and partial versions fill in the gaps. 1.x, 1.*, and plain 1 all mean any 1.y.z; * matches any release.
  • Hyphen ranges are inclusive. 1.2.3 - 2.3.4 is >=1.2.3 <=2.3.4; a partial upper bound like - 2.3 allows every 2.3.x.
  • Prereleases are opt-in. A version like 1.3.0-beta.1 only satisfies a range when one of its comparators has a prerelease on the same 1.3.0, so ^1.2.3 doesn't match it but >=1.3.0-beta.0 <2.0.0 does.

Versions follow Semantic Versioning 2.0.0: three numbers without leading zeros, an optional prerelease after a hyphen, and optional build metadata after a plus sign, which is ignored when comparing. A leading v, as in Git tags like v1.4.0, is accepted.

Common uses

  • Check which versions a dependency range in package.json will accept before publishing or upgrading
  • Work out why npm installs 1.9.4 rather than 2.0.0, or why a beta isn't picked up
  • Explain the difference between ^0.2.3 and ^1.2.3 to a teammate
  • Filter a list of released versions or Git tags down to the ones a range allows

Example

Input

Range: ^1.2.3
Versions:
1.2.2
1.4.0
v1.10.1
1.11.0-rc.1
2.0.0

Output

Desugared: >=1.2.3 <2.0.0-0
1.2.2 — doesn't satisfy (fails >=1.2.3)
1.4.0 — satisfies
v1.10.1 — satisfies
1.11.0-rc.1 — doesn't satisfy (prerelease)
2.0.0 — doesn't satisfy (fails <2.0.0-0)
Highest satisfying: 1.10.1

The -0 in <2.0.0-0 is the lowest possible prerelease, so the bound also keeps out 2.0.0 prereleases such as 2.0.0-beta.

Limitations

  • Follows node-semver's default behaviour; its loose mode and the includePrerelease option (npm's --include-prerelease) aren't modelled
  • Dist-tags such as latest or next, Git URLs, and file: or workspace: specifiers aren't version ranges and can't be resolved without the registry or your project
  • Other ecosystems read some of the same symbols differently — Cargo's bare 1.2.3 means ^1.2.3, for example, and Composer, Ruby, and Python have their own range rules
  • In the desugared range, alternatives are separated by " || "; node-semver itself prints a bare ||

Frequently asked questions

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

A caret allows every update that doesn't change the left-most non-zero number, so ^1.2.3 accepts 1.2.3 up to but not including 2.0.0. A tilde allows only patch updates when a minor version is given, so ~1.2.3 accepts 1.2.3 up to but not including 1.3.0. npm writes caret ranges by default when you install a package.

Why doesn't ^0.2.3 accept 0.3.0?

Below 1.0.0, SemVer treats any change as potentially breaking, so the caret only allows changes to the right of the first non-zero number. ^0.2.3 means >=0.2.3 <0.3.0-0, and ^0.0.3 means >=0.0.3 <0.0.4-0, which accepts 0.0.3 and nothing else.

Why doesn't my range match a beta or rc version?

node-semver excludes prereleases unless the range opts in: a version like 1.3.0-beta.1 only satisfies a set of comparators when one of them has a prerelease on the same 1.3.0. So ^1.2.3 rejects 1.3.0-beta.1, while ^1.3.0-beta.0 accepts it. This keeps unstable versions from being installed just because they fall inside a range.

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

0 is the lowest prerelease identifier SemVer allows, so 2.0.0-0 ranks below every other 2.0.0 prerelease. Writing the upper bound as <2.0.0-0 instead of <2.0.0 makes it clear that prereleases of 2.0.0, such as 2.0.0-beta, are outside the range too. node-semver writes caret, tilde, and X-range upper bounds this way.

How are prerelease versions ordered?

By SemVer 2.0.0 precedence: a prerelease ranks below its release (1.0.0-rc.1 < 1.0.0), identifiers are compared one dot-separated part at a time, numeric parts compare as numbers (beta.2 < beta.11), numbers rank below letters (1.0.0-1 < 1.0.0-alpha), and a shorter list ranks lower when the rest is equal (alpha < alpha.1). Build metadata after a + is ignored.

Are my versions sent to a server?

No. Parsing, desugaring, and checking happen in your browser — nothing you enter is uploaded or stored.