Compare two semantic version strings (semver) and see whether the first is greater than, less than, or equal to the second.
Comparison rules
Numeric major.minor.patch segments are compared left to right. When those match, a version without a prerelease tag is considered newer than one with a prerelease (for example 1.0.0 > 1.0.0-beta). Optional +build metadata is parsed but ignored for ordering.
When to use it
Check dependency compatibility, gate CI promotions, or debug why a package resolver picked one release over another ā without installing a CLI semver tool.
Limitations
Non-semver strings (calendar versions, plain integers) are rejected. Prerelease ordering uses simple string comparison, not full semver prerelease precedence for complex identifiers.
Example
Comparing 2.1.0 with 2.0.9 reports greater, with major diff 0, minor diff 1, and patch diff 1.