Last updated
What Is Semantic Versioning?
Semantic Versioning (SemVer) is a versioning scheme that uses three numbers: MAJOR.MINOR.PATCH (e.g., 2.4.1). Each number has a specific meaning: MAJOR changes when you make incompatible API changes, MINOR changes when you add functionality in a backward-compatible manner, and PATCH changes when you make backward-compatible bug fixes.
SemVer Rules
| Change Type | Version Bump | Example |
|---|---|---|
| Breaking API change | MAJOR | 1.5.3 → 2.0.0 |
| New feature (backward-compatible) | MINOR | 1.5.3 → 1.6.0 |
| Bug fix | PATCH | 1.5.3 → 1.5.4 |
| Pre-release | Suffix | 2.0.0-alpha.1 |
| Build metadata | Suffix | 2.0.0+build.123 |
SemVer Range Syntax (npm)
^1.2.3 → >=1.2.3 <2.0.0 (compatible with 1.x.x)
~1.2.3 → >=1.2.3 <1.3.0 (patch updates only)
1.2.3 → exactly 1.2.3
>=1.2.3 → 1.2.3 or higher
1.2.x → any patch version of 1.2
* → any version
1.x → any minor/patch of major 1
// JavaScript: compare versions with semver library
import semver from 'semver';
semver.satisfies('1.5.3', '^1.2.0'); // true
semver.gt('2.0.0', '1.9.9'); // true
semver.inc('1.5.3', 'minor'); // '1.6.0'
semver.valid('1.2.3-alpha.1'); // '1.2.3-alpha.1'
semver.valid('not-a-version'); // null