Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kipz/rpm-version-clj
Parse and compare rpm package versions in Clojure
https://github.com/kipz/rpm-version-clj
Last synced: about 1 month ago
JSON representation
Parse and compare rpm package versions in Clojure
- Host: GitHub
- URL: https://github.com/kipz/rpm-version-clj
- Owner: kipz
- License: epl-2.0
- Created: 2022-01-19T12:18:48.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-01-19T12:19:40.000Z (almost 3 years ago)
- Last Synced: 2024-08-12T10:44:38.469Z (5 months ago)
- Language: Clojure
- Size: 10.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# rpm-version-clj
[![Clojars Project](https://img.shields.io/clojars/v/org.kipz/rpm-version-clj.svg)](https://clojars.org/org.kipz/rpm-version-clj)
Parse rpm package version scheme as per:
Thanks to https://github.com/anchore/grype from which I've pulled some test data.
```clj
[org.kipz/rpm-version-clj ""]
```## Usage from Clojure
### Parse a version
```clj
(:require [org.kipz.rpm-version.core :refer [parse-version]])
;; returns nil if can't parse
(parse-version "1.2.3-el7_5~snapshot1");=>
{:epoch "0", :version "1.2.3", :release "el7_5~snapshot1"}
```### Compare two versions
```clj
(:require [org.kipz.rpm-version.core :refer [compare-versions]])
(compare-versions "1.2.3-el7_5~snapshot1" "1.2.3-3-el7_5")
; => 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" "1:1" "4.19.0a-1.el7_5" "4.19.0c-1.el7" "1.2.3-el7_5~snapshot1" "1.2.3-3-el7_5"])
; => ["1" "1.2.3-el7_5~snapshot1" "1.2.3-3-el7_5" "4.19.0a-1.el7_5" "4.19.0c-1.el7" "1:1"]
```### 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.rpm-version.core :refer [in-range?]])
(in-range? "1.2.3-el7_5~snapshot1" "< 1")
; => false
(in-range? "1.2.3-el7_5~snapshot1" "<= 1.2.3-3-el7_5")
; => true
```