Compares two semantic version strings, including prerelease versions.
The numeric (major.minor.patch) parts compare numerically, with missing
segments treated as zero. Prerelease parts (everything after the first
-) follow semver precedence: a version with a prerelease precedes the
same version without one; prerelease identifiers compare dot-by-dot,
numeric identifiers numerically and below alphanumeric ones, alphanumeric
identifiers in ASCII order, and a shorter identifier set precedes a longer
one that it prefixes.
Parameters
v1: string
First version string (e.g., "5.104.2" or "6.0.0-alpha.1")
v2: string
Second version string (e.g., "5.103.1")
Returns number
Negative if v1 < v2, 0 if equal, positive if v1 > v2
Compares two semantic version strings, including prerelease versions.
The numeric (
major.minor.patch) parts compare numerically, with missing segments treated as zero. Prerelease parts (everything after the first-) follow semver precedence: a version with a prerelease precedes the same version without one; prerelease identifiers compare dot-by-dot, numeric identifiers numerically and below alphanumeric ones, alphanumeric identifiers in ASCII order, and a shorter identifier set precedes a longer one that it prefixes.