compareVersions
Compares two versions by SemVer rules: -1, 0 or 1.
Details #
compareVersions(a, b) returns -1 when a is older than b, 0 when they are the same and 1 when a is newer. Each side is version text or a record from parseVersion. A pre-release sorts before its release (1.0.0-beta is older than 1.0.0), pre-release parts compare one by one (beta.2 is older than beta.11), and build text after + is ignored.
Parameters #
Takes 2 arguments.
{{ compareVersions(text, b) }}
Examples #
compareVersions("1.2.0", "1.10.0")→
-1compareVersions("1.0.0-beta", "1.0.0") < 0→
trueGotchas #
Compare numbers, not text:
1.10.0is newer than1.9.0, which a plain text comparison gets wrong.