Test Whether a Version Satisfies an npm Range

Test if a specific version like 1.5.3 satisfies an npm semver range like ^1.2.0 or >=1.0.0 <2.0.0. Understand how range satisfaction works.

Range Testing

Detailed Explanation

Testing npm Version Range Satisfaction

The core question in semver range matching is: does version X satisfy range Y? This is what npm install does every time it resolves dependencies.

How Range Satisfaction Works

A version satisfies a range if it falls within the bounds the range defines:

Version Range Satisfies? Why
1.5.3 ^1.2.0 1.5.3 is >=1.2.0 and <2.0.0
2.0.0 ^1.2.0 2.0.0 is not <2.0.0
1.1.9 ^1.2.0 1.1.9 is not >=1.2.0
1.2.0 ~1.2.0 1.2.0 is >=1.2.0 and <1.3.0
1.3.0 ~1.2.0 1.3.0 is not <1.3.0

Step-by-Step Range Testing

To test a range manually:

  1. Expand the range to its comparator form
    • ^1.2.0>=1.2.0 <2.0.0
    • ~1.2.0>=1.2.0 <1.3.0
    • 1.2.x>=1.2.0 <1.3.0
  2. Compare the version against each bound
  3. All bounds must be satisfied (AND logic within a comparator set)
  4. For OR ranges, at least one set must be satisfied

Pre-release Gotcha

npm has a special rule: a pre-release version only matches a range if the range includes a pre-release on the same MAJOR.MINOR.PATCH.

Version Range Satisfies? Why
1.2.3-alpha.1 >=1.2.3-alpha.0 Same base, higher pre-release
1.2.4-alpha.1 >=1.2.3 Different base, pre-release excluded
1.2.3 >=1.2.3 Release version, no restriction

Batch Testing

When evaluating multiple versions against a range (e.g., "which of these 50 versions match ^2.0.0?"), use the Batch Check tab to paste a list and see results highlighted instantly.

Common Testing Scenarios

  • "Will this update break me?" — Test the new version against your range
  • "Which versions can I install?" — Batch check against a list of published versions
  • "Is my range too broad?" — Test edge cases like 0.x or pre-release versions

Use Case

Debugging dependency resolution issues in npm/yarn projects, verifying that a package.json range will accept a specific version before publishing, or understanding why npm installed an unexpected version.

Try It — Semver Calculator

Open full tool