SemVer range tester

Test versions against an npm-style range such as ^1.2.3 or >=1.0 <2 and find the highest match.

Input

The range, in npm syntax: ^, ~, x-ranges, hyphen ranges, comparators and ||.
The versions to test.
Let prerelease versions match like ordinary versions.

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-range \
  -H 'Content-Type: application/json' \
  -d '{"input":{"range":"^1.2.3","versions":["1.2.2","1.2.3","1.9.0","2.0.0","1.3.0-beta.1"]}}'
import json, urllib.request

body = {'input': {'range': '^1.2.3', 'versions': ['1.2.2', '1.2.3', '1.9.0', '2.0.0', '1.3.0-beta.1']}}
request = urllib.request.Request("https://setget.net/v1/tools/semver-range", 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-range", {
  method: "POST",
  headers: {"Content-Type": "application/json"},
  body: JSON.stringify({"input":{"range":"^1.2.3","versions":["1.2.2","1.2.3","1.9.0","2.0.0","1.3.0-beta.1"]}}),
});
console.log((await response.json()).result);
Tool: run_tool
Arguments:
{
  "slug": "semver-range",
  "input": {
    "range": "^1.2.3",
    "versions": [
      "1.2.2",
      "1.2.3",
      "1.9.0",
      "2.0.0",
      "1.3.0-beta.1"
    ]
  }
}
{
  "input": {
    "range": "^1.2.3",
    "versions": [
      "1.2.2",
      "1.2.3",
      "1.9.0",
      "2.0.0",
      "1.3.0-beta.1"
    ]
  }
}

Endpoint: POST /v1/tools/semver-range. Over MCP: run_tool with slug: "semver-range". Machine-readable: input schema, Markdown. Connect an agent.

Inputs

NameTypeRequiredWhat it does
range string yes The range, in npm syntax: ^, ~, x-ranges, hyphen ranges, comparators and ||.
versions array yes The versions to test.
include_prerelease boolean no Let prerelease versions match like ordinary versions. Default: false.

Examples

Input
{
  "range": "^1.2.3",
  "versions": [
    "1.2.2",
    "1.2.3",
    "1.9.0",
    "2.0.0",
    "1.3.0-beta.1"
  ]
}
Result
{
  "range": "^1.2.3",
  "normalised": ">=1.2.3 <2.0.0-0",
  "matching": [
    "1.2.3",
    "1.9.0"
  ],
  "not_matching": [
    "1.2.2",
    "2.0.0",
    "1.3.0-beta.1"
  ],
  "invalid": [],
  "highest": "1.9.0"
}

Tilde, hyphen range and "or"

Input
{
  "range": "~1.2 || 2.0.0 - 2.5",
  "versions": [
    "1.2.9",
    "1.3.0",
    "2.5.7",
    "2.6.0"
  ]
}
Result
{
  "range": "~1.2 || 2.0.0 - 2.5",
  "normalised": ">=1.2.0 <1.3.0-0 || >=2.0.0 <2.6.0-0",
  "matching": [
    "1.2.9",
    "2.5.7"
  ],
  "not_matching": [
    "1.3.0",
    "2.6.0"
  ],
  "invalid": [],
  "highest": "2.5.7"
}

Questions

What is the difference between ^ and ~?
^1.2.3 allows changes that keep the first non-zero number (up to, not including, 2.0.0). ~1.2.3 allows only patch updates (below 1.3.0).
Why does a prerelease not match?
As in npm, 1.3.0-beta.1 matches only if the range itself names a prerelease of 1.3.0. Turn on include_prerelease to change that.
What does "<2.0.0-0" mean?
Below every 2.0.0 version, including its prereleases. It is how npm writes an exclusive upper bound.