Hyphen Range (A - B) — Inclusive Version Ranges
Learn the hyphen range syntax in semver. 1.2.3 - 2.3.4 means >=1.2.3 <=2.3.4. Partial versions on either side change the behavior.
Detailed Explanation
Hyphen Range Syntax
The hyphen range provides a clean, human-readable way to specify an inclusive range of versions.
Basic Syntax
A - B
translates to >=A <=B.
Examples
| Hyphen Range | Expanded |
|---|---|
1.2.3 - 2.3.4 |
>=1.2.3 <=2.3.4 |
0.0.0 - 1.0.0 |
>=0.0.0 <=1.0.0 |
1.0.0 - 1.5.0 |
>=1.0.0 <=1.5.0 |
Partial Versions in Hyphen Ranges
When either side is a partial version, the behavior changes:
Partial on the low side — missing pieces are treated as 0:
1.2 - 2.3.4→>=1.2.0 <=2.3.41 - 2.3.4→>=1.0.0 <=2.3.4
Partial on the high side — the range is exclusive of the next increment:
1.2.3 - 2.3→>=1.2.3 <2.4.0(not<=2.3.0)1.2.3 - 2→>=1.2.3 <3.0.0(not<=2.0.0)
This asymmetry exists because a partial high version like 2.3 means "any version in the 2.3.x line," which is more naturally expressed as <2.4.0.
When to Use Hyphen Ranges
Hyphen ranges are especially readable for:
- Migration guides: "This tool works with versions
2.0.0 - 3.0.0" - Compatibility matrices in documentation
- Peer dependencies with a known working range
{
"peerDependencies": {
"react": "16.8.0 - 18.99.99"
}
}
Use Case
Specifying peer dependencies or engine compatibility ranges where both a minimum and maximum version are known, such as library authors supporting multiple major versions of a framework.