Liking cljdoc? Tell your friends :D

alpine-version-clj

Clojars Project

Parse alpine-version (and gentoo) scheme as per:

Thanks to https://github.com/knqyf263/go-apk-version from which I've pulled some test data.

[org.kipz/alpine-version-clj "<some version>"]

Usage from Clojure

Parse a version

(: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

(: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

(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: < > <= >= =

(: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

Can you improve this documentation?Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close