# SemVer Comparator & Range Checker

> Compare, sort and bump semantic versions and check them against npm ranges like ^1.2.3 or ~2.0. Prereleases, build metadata and caret rules handled as npm does.

- Page: https://notadevblog.com/en/tools/developer/semver/
- German version: https://notadevblog.com/de/tools/developer/semver.md
- Category: Developer

## At a glance

- **Processing:** Locally in your browser, also offline once the page has been opened. Input never leaves your device.
- **Standard:** SemVer 2.0.0 and npm range syntax (^, ~, x, hyphen, ||)
- **Prereleases:** alpha.2 sorts before alpha.10; a prerelease only matches ranges that name one at the same x.y.z

## For agents

WebMCP: the page registers these functions via document.modelContext in browsers that support it.
ES module: https://notadevblog.com/core/semver.js
Every function returns { "ok": true, ... } or { "ok": false, "error": { "code", "message" } }.

### semver_evaluate

Work with Semantic Versioning 2.0.0 versions and npm-style ranges. operation "compare": exactly two versions, comparison is -1, 0 or 1 (first against second) and diff names the first differing part. operation "sort": sorted ascending (order "desc" reverses); invalid versions are left out but listed in parsed. operation "satisfies": needs range; satisfies maps each version to true or false, maxSatisfying and minSatisfying name the highest and lowest match, range is the canonical form (^1.2.3 becomes ">=1.2.3 <2.0.0-0"). operation "bump": exactly one version and bump = major, minor, patch or prerelease (optional preid), like `npm version`. Without operation it is inferred: bump given -> bump, range given -> satisfies, two versions -> compare, else sort. Ranges: ^, ~, x-ranges (1.x, 1.2.*), hyphen ranges (1.2.3 - 2.3.4), comparators (>=1.2 <2), || for alternatives. Rules: build metadata (+...) is ignored in comparisons; numeric prerelease identifiers compare as numbers and sort before alphanumeric ones (alpha.2 < alpha.10); a prerelease only satisfies a range that names a prerelease of the same major.minor.patch (set includePrerelease to lift that); ^0.x only allows patch steps. A v prefix is accepted and flagged as prefix. Leading zeros, missing parts and numbers above 2^53-1 make a version invalid; parsed[].reason says why.

Parameters:
- versions (array): Versions such as "1.2.3" or "v2.0.0-rc.1+build5". In a deep link: comma separated.
- range (string): npm range such as "^1.2.3", ">=1.2 <2" or "1.x || 3.x".
- operation (string: compare | sort | satisfies | bump): Inferred when omitted.
- bump (string: major | minor | patch | prerelease)
- preid (string): Prerelease label for bump = prerelease, e.g. "beta".
- includePrerelease (boolean, default false)
- order (string: asc | desc, default "asc")

Example input: `{"versions":["1.2.3","1.10.0","1.2.10","2.0.0-rc.1","1.2.3-alpha.2"],"range":"^1.2.3"}`

Deep link (options in the query, user data after #): https://notadevblog.com/en/tools/developer/semver/#versions=1.2.3%2C1.10.0%2C1.2.10%2C2.0.0-rc.1%2C1.2.3-alpha.2&range=%5E1.2.3

## How to use

1. **Enter versions:** Put one version per line, for example 1.2.3 or 2.0.0-rc.1. A v prefix is accepted. The table shows how each one is read.
2. **Pick what to do:** Compare two versions, sort a list, test versions against a range or bump one version.
3. **Read the result:** The result appears below. For ranges you also see the canonical form, so you can check what ^ or ~ really allows.

## About this tool

Semantic Versioning gives version numbers a meaning: a major step may break compatibility, a minor step adds features, a patch step fixes bugs. Package managers use it to decide which updates are safe.

The comparator follows semver.org 2.0.0 and the range rules of npm. It is written for this site and has no dependencies.

## Frequently asked questions

### Why is 1.0.0-alpha.10 greater than 1.0.0-alpha.2?

Numeric prerelease identifiers are compared as numbers, so 10 beats 2. Identifiers with letters are compared as text, and a numeric identifier is always lower than an alphanumeric one.

### Does build metadata count in a comparison?

No. 1.0.0+a and 1.0.0+b have the same precedence. The tool reports them as equal and names build as the difference.

### What does ^1.2.3 allow?

Everything from 1.2.3 up to, but not including, 2.0.0. For 0.x versions the caret is stricter: ^0.2.3 stops before 0.3.0 and ^0.0.3 allows only 0.0.3.

### Why does ^1.2.3 not match 1.3.0-beta.1?

npm only lets a prerelease satisfy a range that names a prerelease of the same major, minor and patch, for example >=1.3.0-beta.0. Tick “Include prereleases” to lift the rule.

### Why is “1.2” or “01.2.3” invalid?

SemVer requires all three numbers and forbids leading zeros. Ranges may be partial (1.2 means 1.2.x), versions may not. Numbers above 9007199254740991 are rejected.
