Semver Range Explainer
Paste a semver range like ^1.2.3 or ~4.0 to get a plain-English explanation and see which versions match.
Paste a semver range like ^1.2.3 or ~4.0 to get a plain-English explanation and see which versions match.
Semantic Versioning (semver) is a versioning convention using the format MAJOR.MINOR.PATCH (e.g., 1.4.2). MAJOR increments indicate breaking changes, MINOR increments add functionality backwards-compatibly, and PATCH increments fix bugs backwards-compatibly.
npm, yarn, and most package managers use semver range expressions in package.json to specify which versions of a dependency are acceptable. Understanding these ranges helps you avoid unexpected breaking changes.
^1.2.3 accepts >=1.2.3 <2.0.0. This is npm's default.~1.2.3 accepts >=1.2.3 <1.3.0.^1.0.0 || ^2.0.0.The caret (^) allows compatible changes. For ^1.2.3, npm will accept any version >=1.2.3 and <2.0.0. It assumes any version within the same major version is backward-compatible. This is the default behavior when you run npm install package-name.
Tilde (~) is more conservative: ~1.2.3 only accepts patch-level changes (>=1.2.3 <1.3.0). Caret (^) is more permissive: ^1.2.3 accepts minor and patch changes (>=1.2.3 <2.0.0). Use tilde when you want tighter version control, caret for more flexibility.
For applications, use a lockfile (package-lock.json or yarn.lock) with flexible ranges — the lockfile pins exact versions. For libraries, be careful with ranges to avoid forcing duplicate installs on consumers. Exact versions give reproducibility but prevent security patches from being automatically applied.