Skip to content
Constraint Operators
step 1/5

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:

ConstraintMeans
1.2.3Exactly 1.2.3
>=1.2.3At least 1.2.3
<2.0.0Strictly less than 2.0.0
>=1.2.3 <2.0.0Range (AND'd)
^1.2.3Caret: >=1.2.3, <2.0.0
~1.2.3Tilde: >=1.2.3, <1.3.0
^0.2.3Caret with 0.x.x: >=0.2.3, <0.3.0
* or latestAny 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…