zafarkhaja/jsemver

prerelease comparison not correct

Closed this issue · 1 comments

For two versions:
1.0.0-b9
1.0.0-b10

The comparison result is not correct – the result gives b9 greater than b10.

1.0.0-b10 < 1.0.0-b9

This is the intended behavior because alphanumeric pre-release identifiers are compared lexically. Please refer to p.11 of the SemVer 2 for the comparison rules

...
Precedence for two pre-release versions with the same major, minor, and patch version MUST be determined by comparing each dot separated identifier from left to right until a difference is found as follows: identifiers consisting of only digits are compared numerically and identifiers with letters or hyphens are compared lexically in ASCII sort order.
...

If you need the numbers to be compared numerically you have to make them identifiers by themselves

1.0.0-b.9 < 1.0.0-b.10