Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kipz/deb-version-clj
Compare debian package versions in Clojure
https://github.com/kipz/deb-version-clj
Last synced: about 1 month ago
JSON representation
Compare debian package versions in Clojure
- Host: GitHub
- URL: https://github.com/kipz/deb-version-clj
- Owner: kipz
- License: epl-2.0
- Created: 2022-01-12T12:36:55.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-05-04T13:59:34.000Z (over 1 year ago)
- Last Synced: 2024-10-01T11:47:28.850Z (3 months ago)
- Language: Clojure
- Homepage:
- Size: 33.2 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# deb-version-clj
[![Clojars Project](https://img.shields.io/clojars/v/org.kipz/deb-version-clj.svg)](https://clojars.org/org.kipz/deb-version-clj)
Parse debian-version scheme as per https://www.man7.org/linux/man-pages/man7/deb-version.7.html
**NOTE** the deprecated _ (underscore) is currently supported in version strings
Thanks to https://github.com/knqyf263/go-deb-version from which I've pulled some test-cases.
```clj
[org.kipz/deb-version-clj ""]
```## Usage from Clojure
### Parse a version
```clj
(:require [org.kipz.deb-version.core :refer [parse-version]])
;; returns epoch upstream-version and debian-revision (if present) or nil if invalid
(parse-version "6.0-4.el6.x86_64")
; => ["0", "6.0" "4.el6.x86_64"]
```### Compare two versions
```clj
(:require [org.kipz.deb-version.core :refer [compare-versions]])
(compare-versions "6.0-4.el6.x86_64" "6.0-5.el6.x86_64")
; => 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 ["2:6.0-1.el6.x86_64" "6.0-4.el6.x86_64" "6.0-5.el6.x86_64"])
; => ("6.0-4.el6.x86_64" "6.0-5.el6.x86_64" "2:6.0-1.el6.x86_64")
```### 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.deb-version.core :refer [in-range?]])
(in-range? "2:7.4.052" "> 1:7.4.052")
; => true
(in-range? "7.4.052" "< 1:7.4.052 & > 1.2.3")
; => true
```