The tilde ~
is one of many constraints that can be used to handle versions.
Next Significant Release Operators (~, ^):
The ~
operator is best explained by example: ~1.2
is equivalent to >=1.2 <2.0.0
, while ~1.2.3
is equivalent to >=1.2.3 <1.3.0
The ^
operator behaves very similarly, but it sticks closer to
semantic versioning, and will always allow non-breaking updates. For
example ^1.2.3
is equivalent to >=1.2.3 <2.0.0
as none of the releases
until 2.0 should break backwards compatibility. For pre-1.0 versions
it also acts with safety in mind and treats ^0.3
as >=0.3.0 <0.4.0
Hyphenated Version Range (-)
Inclusive set of versions. Partial versions on the right include are
completed with a wildcard. For example 1.0 - 2.0
is equivalent to
>=1.0.0 <2.1
as the 2.0
becomes 2.0.*
. On the other hand 1.0.0 - 2.1.0
is equivalent to >=1.0.0 <=2.1.0
Wildcard Version Range (.*)
You can specify a pattern with a * wildcard. 1.0.*
is the equivalent
of >=1.0 <1.1
Simple Version Range (>, >=, <, <=, !=)
By using comparison operators you can specify ranges of valid
versions. Valid operators are >, >=, <, <=, !=.
You can define multiple ranges. Ranges separated by a space (
) or
comma (,
) will be treated as a logical AND. A double pipe (||
) will be
treated as a logical OR. AND has higher precedence than OR.
And finally Exact Version Constraint
You can specify the exact version of a package
Example: 1.0.2