Reading — step 1 of 5
Read
~1 min readVersioning & Constraints
Constraint Operators
When you specify a dependency, you give a constraint — a range of acceptable versions:
| Constraint | Means |
|---|---|
1.2.3 | Exactly 1.2.3 |
>=1.2.3 | At least 1.2.3 |
<2.0.0 | Strictly less than 2.0.0 |
>=1.2.3 <2.0.0 | Range (AND'd) |
^1.2.3 | Caret: >=1.2.3, <2.0.0 |
~1.2.3 | Tilde: >=1.2.3, <1.3.0 |
^0.2.3 | Caret with 0.x.x: >=0.2.3, <0.3.0 |
* or latest | Any version (use the highest available) |
The caret/tilde rules try to be "conservative": for 1.x.x, caret means "any future minor/patch version is safe (assuming the author follows semver)". For 0.x.x, caret is more restrictive because 0.x.x is considered unstable.
npm uses these by default. cargo uses caret as the implicit operator. Bundler uses ~> (twiddle-wakka) which is like tilde.
For this lesson: implement caret + tilde + range constraint matching.
Discussion
Ask a question, share an insight, or help someone who’s stuck.
Sign in to post a comment or reply.
Loading…