SemVer compare and sort
Compare two semantic versions, including prerelease precedence, or sort a list of versions.
Input
Result
Fill in the input and press Run.
Your input is processed in memory and then discarded. It is not stored or logged. Even so, don't paste live passwords or keys into any online tool.
Use it from code or an agent
curl -s https://setget.net/v1/tools/semver-compare \
-H 'Content-Type: application/json' \
-d '{"input":{"a":"1.0.0-alpha","b":"1.0.0"}}'
import json, urllib.request
body = {'input': {'a': '1.0.0-alpha', 'b': '1.0.0'}}
request = urllib.request.Request("https://setget.net/v1/tools/semver-compare", json.dumps(body).encode(),
{"Content-Type": "application/json"})
print(json.load(urllib.request.urlopen(request))["result"])
const response = await fetch("https://setget.net/v1/tools/semver-compare", {
method: "POST",
headers: {"Content-Type": "application/json"},
body: JSON.stringify({"input":{"a":"1.0.0-alpha","b":"1.0.0"}}),
});
console.log((await response.json()).result);
Tool: run_tool
Arguments:
{
"slug": "semver-compare",
"input": {
"a": "1.0.0-alpha",
"b": "1.0.0"
}
}
{
"input": {
"a": "1.0.0-alpha",
"b": "1.0.0"
}
}
Endpoint: POST /v1/tools/semver-compare. Over MCP: run_tool with slug: "semver-compare".
Machine-readable: input schema, Markdown. Connect an agent.
Inputs
| Name | Type | Required | What it does |
|---|---|---|---|
a |
string | no | The first version. |
b |
string | no | The second version. |
versions |
array | no | A list of versions to sort from lowest to highest. |
descending |
boolean | no | Sort from highest to lowest. Default: false. |
Examples
Input
{
"a": "1.0.0-alpha",
"b": "1.0.0"
}Result
{
"comparison": {
"a": {
"version": "1.0.0-alpha",
"major": 1,
"minor": 0,
"patch": 0,
"prerelease": [
"alpha"
],
"build": []
},
"b": {
"version": "1.0.0",
"major": 1,
"minor": 0,
"patch": 0,
"prerelease": [],
"build": []
},
"result": -1,
"relation": "a < b",
"difference": "prerelease"
},
"sorted": null
}The precedence example from the SemVer specification
Input
{
"versions": [
"1.0.0",
"1.0.0-rc.1",
"1.0.0-beta.11",
"1.0.0-beta.2",
"1.0.0-beta",
"1.0.0-alpha.beta",
"1.0.0-alpha.1",
"1.0.0-alpha"
]
}Result
{
"comparison": null,
"sorted": [
"1.0.0-alpha",
"1.0.0-alpha.1",
"1.0.0-alpha.beta",
"1.0.0-beta",
"1.0.0-beta.2",
"1.0.0-beta.11",
"1.0.0-rc.1",
"1.0.0"
]
}Questions
- Why is 1.0.0-beta.11 higher than 1.0.0-beta.2?
- Numeric prerelease parts are compared as numbers, not as text.
- Does build metadata matter?
- No. Anything after "+" is ignored for precedence, so 1.0.0+a and 1.0.0+b are equal. The difference is then reported as "build".
- Is a leading "v" allowed?
- Yes, v1.2.3 is read as 1.2.3. Everything else must follow SemVer 2.0.0 strictly.
Related tools
- SemVer range testerTest versions against an npm-style range such as ^1.2.3 or >=1.0 <2 and find the highest match.
semver-range - Sort linesSort lines alphabetically, naturally (file2 before file10), by number or by length, or reverse their order.
sort-lines - .gitignore testerCheck which paths a .gitignore file ignores and which line decided each one, using real Git matching rules.
gitignore-test - Cache-Control explainerExplain a Cache-Control header directive by directive and how browsers and CDNs will treat the response.
cache-control-explain - Card number (Luhn) and IBAN validatorCheck a card number with the Luhn checksum and name its network, or check an IBAN by length and mod-97.
luhn-iban-validate - CIDR and subnet calculatorWork out the network, netmask, host range and size of an IPv4 or IPv6 CIDR block, and split it into subnets.
cidr-calc