10aday › Version Constraint Checker › x, *, hyphen and || ranges
x, *), hyphen ranges and ||: npm range syntax next to Cargo, Composer, pip and RubyGemsShort answer: in npm, 1.x = 1.* = 1 = ≥1.0.0 <2.0.0; 1.2.3 - 2.3.4 includes both ends;
a hyphen range with a partial upper bound (1.2 - 2.3) includes the whole 2.3.x line; || means “or”; a space means “and”.
Cargo has no hyphen ranges and no || and uses a comma for “and”. Composer copies most of npm's syntax but reads
partial versions as exact ones: 1.2 || 3 means “1.2.0 or 3.0.0”, and >1.2 already accepts 1.2.1.
Have a constraint and a list of versions? Paste them into the Version Constraint Checker: it shows, side by side, what npm, Cargo, Composer, pip and RubyGems accept.
pip spells wildcards ==1.*; RubyGems has no wildcard (use ~> 1.0).
| Constraint | npm | Cargo | Composer | pip | RubyGems | |
|---|---|---|---|---|---|---|
*pip and RubyGems: leave the constraint empty | any version | any version | any version | not valid | not valid | try it |
1.xRubyGems reads “1.x” as a pre-release version number | ≥1.0.0 <2.0.0 | ≥1.0.0 <2.0.0 | ≥1.0.0 <2.0.0 | not valid | no release | try it |
1.* | 1.*≥1.0.0 <2.0.0 | 1.*≥1.0.0 <2.0.0 | 1.*≥1.0.0 <2.0.0 | ==1.*≥1.0.0 <2.0.0 | 1.*not valid | try it |
1.2.x | ≥1.2.0 <1.3.0 | ≥1.2.0 <1.3.0 | ≥1.2.0 <1.3.0 | not valid | no release | try it |
1.2.* | 1.2.*≥1.2.0 <1.3.0 | 1.2.*≥1.2.0 <1.3.0 | 1.2.*≥1.2.0 <1.3.0 | ==1.2.*≥1.2.0 <1.3.0 | 1.2.*not valid | try it |
Only npm and Composer have them; Cargo, pip and RubyGems reject 1.2.3 - 2.3.4.
| Constraint | npm | Composer | Cargo | |
|---|---|---|---|---|
1.2.3 - 2.3.4both ends included | ≥1.2.3 ≤2.3.4 | ≥1.2.3 ≤2.3.4 | not valid | try it |
1.2 - 2.3partial upper bound: all of 2.3.x | ≥1.2.0 <2.4.0 | ≥1.2.0 <2.4.0 | not valid | try it |
1 - 2 | ≥1.0.0 <3.0.0 | ≥1.0.0 <3.0.0 | not valid | try it |
Highlighted: Composer reads a partial version as an exact one, and keeps its own tilde rule, so the same string allows different versions.
| Constraint | npm | Composer | Cargo | |
|---|---|---|---|---|
^1.2 || ^3.0 | ≥1.2.0 <2.0.0 or ≥3.0.0 <4.0.0 | ≥1.2.0 <2.0.0 or ≥3.0.0 <4.0.0 | not valid | try it |
1.2 || 3 | ≥1.2.0 <1.3.0 or ≥3.0.0 <4.0.0 | exactly 1.2.0 or exactly 3.0.0 | not valid | try it |
~1.2 || ~2.3 | ≥1.2.0 <1.3.0 or ≥2.3.0 <2.4.0 | ≥1.2.0 <2.0.0 or ≥2.3.0 <3.0.0 | not valid | try it |
| Constraint | npm | Cargo | Composer | pip | RubyGems | |
|---|---|---|---|---|---|---|
>=1.2 <2space = and (npm, Composer) | ≥1.2.0 <2.0.0 | not valid | ≥1.2.0 <2.0.0 | not valid | not valid | try it |
>=1.2, <2comma = and (all but npm) | not valid | ≥1.2.0 <2.0.0 | ≥1.2.0 <2.0.0 | ≥1.2.0 <2.0.0 | ≥1.2.0 <2.0.0 | try it |
>=1.2, !=1.2.3npm and Cargo have no != | not valid | not valid | ≥1.2.0, not 1.2.3 | ≥1.2.0, not 1.2.3 | ≥1.2.0, not 1.2.3 | try it |
npm and Cargo expand a partial version to the whole line it names; Composer and RubyGems pad it with zeros.
| Constraint | npm | Cargo | Composer | pip | RubyGems | |
|---|---|---|---|---|---|---|
>1.2 | ≥1.3.0 | ≥1.3.0 | >1.2.0 | >1.2.0 | >1.2.0 | try it |
<=2.3 | <2.4.0 | <2.4.0 | ≤2.3.0 | ≤2.3.0 | ≤2.3.0 | try it |
Ranges shown for release versions. Pre-releases follow extra rules in each tool; the checker shows them.
1.x, 1.* and a bare 1 all mean ≥1.0.0 <2.0.0 in npm. 1.2.x means ≥1.2.0 <1.3.0. A lone * or x means any release version.
Yes. 1.2.3 - 2.3.4 means ≥1.2.3 ≤2.3.4. If the upper bound is partial, every version it names is included: 1.2 - 2.3 means ≥1.2.0 <2.4.0, so 2.3.9 matches.
npm: a space is “and” (>=1.2 <2), || is “or”. Composer: space or comma for “and”, || for “or”. Cargo, pip and RubyGems: comma for “and”, no “or” at all.
Not in npm or Cargo: a partial version stands for the whole 1.2.x line, so >1.2 starts at 1.3.0. In Composer, >1.2 means >1.2.0, so 1.2.5 matches. Write three numbers to avoid the ambiguity.
^ and ~ into [project] dependencies (Poetry 2, uv)