All cheatsheets

Cheatsheets

Semver

Semantic-versioning format and npm range operators.

Visualize

Version ranges

Which published versions ^, ~, and exact actually accept.

1.2.0
1.2.3
installed
1.2.9
1.3.0
1.9.5
2.0.0
2.3.1

^1.2.3>=1.2.3 <2.0.0 — patch & minor updates

24 entries

Version format7

MAJOR.MINOR.PATCH

e.g. 2.4.1 — semantic version structure

MAJOR

Breaking changes (incompatible API)

MINOR

New features, backwards-compatible

PATCH

Backwards-compatible bug fixes

1.0.0-beta.1

Pre-release version (lower precedence than 1.0.0)

1.0.0+build.5

Build metadata (ignored in precedence comparisons)

0.x.y

Pre-1.0 — anything may change at any time

Ranges (npm)9

^1.2.3

Compatible: >=1.2.3 <2.0.0 (minor/patch updates allowed)

~1.2.3

Approximately: >=1.2.3 <1.3.0 (patch updates only)

1.2.x / 1.2.*

Any patch of 1.2 (equivalent to ~1.2.0)

1.x

Any minor/patch of 1 (>=1.0.0 <2.0.0)

* / latest

Any version / newest dist-tag

>=1.2.3 <2.0.0

Explicit comparator range

1.2.3 - 1.5.0

Hyphen range (inclusive on both ends: >=1.2.3 <=1.5.0)

1.2.3 || >=2.0.0

OR — match either range

^0.2.3

Special: >=0.2.3 <0.3.0 (0.x pins the minor, not the major)

Pinning & lockfiles2

"react": "18.2.0"

Exact pin — only this one version, no updates

package.json vs package-lock.json

Range declaration vs exact installed snapshot

npm tooling6

npm version patch|minor|major

Bump version + git tag

npm version prerelease --preid=beta

Cut a beta pre-release

npm outdated

Show packages with newer versions

npm update

Update within the allowed ranges

npm dist-tag add pkg@1.2.3 latest

Point a dist-tag at a version

npx semver 1.2.3 -r "^1.0.0"

Test if a version satisfies a range