Semantic Versioning Reference

SemVer 2.0 rules, npm range operators and pre-release precedence explained

Interactive Semantic Versioning 2.0 reference and parser. Validate MAJOR.MINOR.PATCH versions, inspect pre-release and build metadata, compare two versions by precedence, and learn npm range operators like ^, ~, and *.

What do MAJOR, MINOR, and PATCH mean?

MAJOR is incremented for incompatible API changes, MINOR for backward-compatible new features, and PATCH for backward-compatible bug fixes. The format is always three non-negative integers without leading zeros, written MAJOR.MINOR.PATCH.

Semantic Versioning is a contract between a package and everyone who depends on it. The version number itself communicates whether an upgrade is safe. This tool parses a version against the SemVer 2.0 grammar, compares two versions by the official precedence rules, and documents the npm range operators you use in package.json.

How it works

A valid SemVer string is MAJOR.MINOR.PATCH, optionally followed by a pre-release tag (-alpha.1) and build metadata (+build.5). The full grammar is:

1.4.2
1.4.2-beta.3
1.4.2-rc.1+exp.sha.5114f85

The parser validates that all three core numbers are non-negative integers with no leading zeros, then splits any pre-release and build sections.

Precedence is determined by comparing major, minor, and patch numerically. If those are equal, a version with a pre-release tag ranks below one without. Pre-release identifiers are then compared left to right: numeric identifiers compare numerically, alphanumeric ones compare in ASCII sort order, numeric always ranks lower than alphanumeric, and if one runs out of fields first it ranks lower. Build metadata is never compared.

Range operators and tips

The npm operators control which versions a dependency range accepts:

  • ^1.2.3 — compatible with 1.2.3, allows >=1.2.3 <2.0.0.
  • ~1.2.3 — allows patch-level changes, >=1.2.3 <1.3.0.
  • 1.2.x / 1.2.* — any patch within 1.2.
  • >=1.2.0 <2.0.0 — explicit comparator range.

A good habit: publish 0.x releases while the API is unstable, because under ^ and ~ the 0.x rules tighten the allowed range automatically. Once you ship 1.0.0, every breaking change must bump the major number.