Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kipz/alpine-version-clj
Parse and compare Alpine/Gentoo package version strings in clojure
https://github.com/kipz/alpine-version-clj
Last synced: about 1 month ago
JSON representation
Parse and compare Alpine/Gentoo package version strings in clojure
- Host: GitHub
- URL: https://github.com/kipz/alpine-version-clj
- Owner: kipz
- License: epl-2.0
- Created: 2022-01-18T14:24:58.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-01-20T10:21:04.000Z (almost 3 years ago)
- Last Synced: 2024-04-24T17:42:22.914Z (8 months ago)
- Language: Clojure
- Size: 19.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# alpine-version-clj
[![Clojars Project](https://img.shields.io/clojars/v/org.kipz/alpine-version-clj.svg)](https://clojars.org/org.kipz/alpine-version-clj)
Parse alpine-version (and gentoo) scheme as per:
* https://wiki.alpinelinux.org/wiki/Package_policies
* https://projects.gentoo.org/pms/8/pms.html#x1-250003.2
* https://gitlab.alpinelinux.org/alpine/apk-tools/-/blob/master/src/version.cThanks to https://github.com/knqyf263/go-apk-version from which I've pulled some test data.
```clj
[org.kipz/alpine-version-clj ""]
```## Usage from Clojure
### Parse a version
```clj
(:require [org.kipz.alpine-version.core :refer [parse-version]])
;; returns nil if can't parse
(parse-version "1.0.2.3_pre1_alpha1_rc")
;=>
{:numbers ("1" "0" "2" "3"),
:revision 0,
:letter "",
:suffixes ({:suffix "pre", :number 1} {:suffix "alpha", :number 1} {:suffix "rc"})}
```### Compare two versions
```clj
(:require [org.kipz.alpine-version.core :refer [compare-versions]])
(compare-versions "2.1a_alpha" "2.1a_pre")
; => true first arg is lower/before second
```### Sorting
As per normal Clojure awesomeness, we can use it as a normal comparator
```clj
(sort compare-versions ["1.2.3-r1" "1.2.3" "0.1.1" "1.3.4_alpha"] )
; => ("0.1.1" "1.2.3" "1.2.3-r1" "1.3.4_alpha")
```### Range checking
Easily check if a version is in a particular range (two ranges are supported optionally separated by an &)
The following operators are allowed: `< > <= >= =`
```clj
(:require [org.kipz.alpine-version.core :refer [in-range?]])
(in-range? "1.2.3-r1" "> 1.2.3")
; => true
(in-range? "1.2.3-r1" "> 1.2.3 & < 1.3.4_alpha" )
; => true
```