Starting points for your own code. Run them in the environment shown below.
Node.js 22+ · ES module (.mjs)
Current inputs apply only to fields used by the example. Selected files are not embedded.
Install dependencies
npm install semver
import { valid, validRange, compare, satisfies } from "semver";
const version = "1.2.3", other = "1.3.0", range = "^1.2.0";
if (!valid(version) || !valid(other) || !validRange(range)) throw new Error("Invalid SemVer");
console.log(compare(version, other)); // -1, 0, or 1
console.log(satisfies(version, range));
Put it to work
Compare versions and test semantic version ranges.
Details that matter
Format and meaning
Uses SemVer and npm range rules, including their prerelease behavior.
Supported scope and limits
Text 1 MB
Split inputs that exceed the limit. If a format or algorithm is unsupported, choose a tool that matches your requirements instead of silently changing the format.