compareVersions

Compares the precedence of two SemVer version strings.

The version strings must be validated using isValidVersion before being passed to this function. Note that the build meta data suffix (if any) is being ignored when comparing version numbers.

@safe pure @nogc
int
compareVersions
(
scope string a
,
scope string b
)

Return Value

Type: int

Returns a negative number if a is a lower version than b, 0 if they are equal, and a positive number otherwise.

Examples

assert(compareVersions("1.0.0", "1.0.0") == 0);
assert(compareVersions("1.0.0+b1", "1.0.0+b2") == 0);
assert(compareVersions("1.0.0", "2.0.0") < 0);
assert(compareVersions("1.0.0-beta", "1.0.0") < 0);
assert(compareVersions("1.0.1", "1.0.0") > 0);

Meta