Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/oprypin/tag-cmp
Compare semver-like version strings
https://github.com/oprypin/tag-cmp
semver
Last synced: 21 days ago
JSON representation
Compare semver-like version strings
- Host: GitHub
- URL: https://github.com/oprypin/tag-cmp
- Owner: oprypin
- License: mit
- Created: 2021-01-23T11:14:55.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2024-05-19T15:02:50.000Z (6 months ago)
- Last Synced: 2024-10-08T13:32:51.080Z (about 1 month ago)
- Topics: semver
- Language: JavaScript
- Homepage:
- Size: 826 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# tag-cmp
Compare two semver-like version strings, returning -1, 0, or 1.
This can be used with `Array.sort`.
## Example
```javascript
const {cmpTags} = require("tag-cmp");cmpTags("1.2b1", "1.2") === -1;
arr = ["1.2b1", "1.11", "1.2"];
arr.sort(cmpTags) === ["1.2b1", "1.2", "1.11"];
```## Version precedence
Versions are being compared in [natural sort order][] (i.e. lexicographic with the consideration of multi-digit numbers), with a special exception for "pre-release identifiers" (letters that immediately follow a number).
Example in ascending order:
* `v1.3` (goes first just because others don't have the "v")
* `1.1.2` (lowest minor version)
* `1.2rc1` (precedes the following as a "release candidate" of 1.2)
* `1.2` (actual release)
* `1.2.1` (patch release)
* `1.11` (much later version; `11 > 2` even if `'1' < '2'`)(and so `1.11` would be chosen as the "greatest").
This handling is compatible with [SemVer][], but more general.
There is no attempt to isolate the version number from other text that may be part of the tag name. But that's not a problem if the tags have a matching prefix, e.g. `Release-1.2.3` and `Release-1.2.4`. But, `Foo-3.4.5` would precede these just because `'F' < 'R'`.
[natural sort order]: https://en.wikipedia.org/wiki/Natural_sort_order
[semver]: https://semver.org/