compare
Compares two semantic version strings according to SemVer 2.0.0 specification
Supports:
- Core version: MAJOR.MINOR.PATCH
- Pre-release: -alpha, -beta.1, -rc.1, etc.
- Build metadata: +build, +sha.abc123 (ignored in comparison per spec)
- Optional ‘v’ prefix
Available since v1.9.0
Import
Section titled “Import”Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
version1 | string | First version string |
version2 | string | Second version string |
Returns
Section titled “Returns”number — -1 if version1 < version2, 0 if equal, 1 if version1 > version2
Examples
Section titled “Examples”Compare two semver versions
Section titled “Compare two semver versions”Returns -1, 0, or 1 based on SemVer ordering.
Prerelease is lower than release
Section titled “Prerelease is lower than release”A prerelease version is always less than the release.
