Semver Range Checker

What ^1.2.3 or ~1.2 means in plain words, and which versions it allows.

Meaning and matches

Examples

Range forms

Questions

What is the difference between ^ and ~?

^1.2.3 allows any 1.x.x from 1.2.3 up, so new features but not 2.0.0. ~1.2.3 allows only 1.2.x from 1.2.3 up, so bug fixes only. npm uses ^ by default.

Why does ^0.2.3 not allow 0.3.0?

Below 1.0.0, the first non-zero number is treated as the major version, because any 0.x release may break things. So ^0.2.3 means below 0.3.0, and ^0.0.3 means exactly 0.0.3 up to below 0.0.4.

Why is 1.3.0-beta.1 not matched by ^1.2.3?

npm only allows a pre-release if the range names a pre-release of the same version, like ^1.3.0-beta.0. This stops you getting unstable versions by accident.

Which range syntax is supported?

The same as npm: ^ and ~, x and * wildcards (1.x, 1.2.*), partial versions (1.2), hyphen ranges (1.2.3 - 2.3.4), comparators (>=, <, and so on), spaces for AND and || for OR.

Does build metadata like +build.5 matter?

No. Build metadata after a + is ignored when comparing versions, as the SemVer spec says.