Back to Utilities

Semver Checker

Compare semantic versions and validate version range constraints.

Advertisement
Loading...

What this tool does

Semantic Versioning (SemVer) is a versioning scheme that conveys meaning about the underlying changes in a release. A version number is MAJOR.MINOR.PATCH, with optional pre-release (-alpha.1) and build metadata (+build.123) tags. Increment MAJOR for breaking changes, MINOR for new features, PATCH for bug fixes. This tool compares two versions and validates version range constraints like ^1.2.0 or ~1.2.0.

SemVer ranges are used in package.json files (npm), Gemfile (Ruby), requirements.txt (Python with compatible release operator), and many other package managers. Understanding these ranges is essential for managing dependencies safely, especially in production systems where automatic updates can introduce breaking changes.

Usage Example

{
  "dependencies": {
    "react": "^18.2.0",      // >=18.2.0, <19.0.0
    "lodash": "~4.17.0",     // >=4.17.0, <4.18.0
    "typescript": ">=5.0.0", // explicit comparison
    "next": "latest",         // always the newest (dangerous)
  }
}

// Version range meanings
^1.2.3  :=  >=1.2.3 <2.0.0  (compatible changes)
~1.2.3  :=  >=1.2.3 <1.3.0  (patch updates only)
1.2.x   :=  >=1.2.0 <1.3.0
*       :=  >=0.0.0 (any version)

Common Edge Cases

  • Pre-release versions (1.0.0-alpha) are considered lower than the release version (1.0.0). So 1.0.0-alpha < 1.0.0-beta < 1.0.0.
  • Build metadata (+build.123) is ignored in version precedence, so 1.0.0+a is equal to 1.0.0+b for comparison purposes.
  • Versions below 1.0.0 (0.x.y) are considered unstable by convention, so ^0.2.3 means >=0.2.3 <0.3.0 (not <1.0.0). The caret behaves differently for 0.x versions.
  • The semver spec is silent on what constitutes a breaking change, so maintainers must use judgment. API removal, signature changes, and behavior changes are all candidates.
  • Some ecosystems (Python, Rust) use different versioning schemes. PEP 440 in Python uses ~= for compatible release, which is similar to ~ in SemVer but with subtle differences.

FAQ

Should I use ^ or ~ in my dependencies?
Use ^ (caret) for most dependencies to get bug fixes and new features without breaking changes. Use ~ (tilde) only when you need a specific minor version because the library has unstable minor releases.
When should I bump the major version?
Bump MAJOR for any breaking change that requires users to modify their code. This includes removing features, changing function signatures, changing return types, and changing default behavior. New features and deprecations do not require a major bump.
What does "latest" mean in package.json?
The latest tag points to the most recently published version. Using it in production is dangerous because a breaking change in a new release can break your application without warning. Always pin to a specific version or range.
Advertisement