Skip to content
Version Number Analysis and Comparison for Clojure(Script)
Clojure
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src/cljx/version_clj
test/cljx/version_clj fix parsing of large numbers. (closes #2) Jan 20, 2015
.gitignore add .nrepl-port to .gitignore Jan 4, 2015
.travis.yml
README.md Fix link to comparison tests Nov 5, 2015
project.clj Version 0.1.3-SNAPSHOT Jan 20, 2015

README.md

version-clj

version-clj is a Clojure & ClojureScript library for analysis and comparison of artifact version numbers.

Build Status endorse

It originated as a comparison mechanism in lein-ancient, a plugin to detect outdated dependencies in your packages.

Usage

Leiningen (via Clojars)

Clojars Project

REPL

(use 'version-clj.core)

(version->seq "1.0.0-SNAPSHOT")
;; => [(1 0 0) ("snapshot")]
(version->seq "9.1-0-1.1-jdbc4")
;; => [(9 (1 0 1) 1) ("jdbc" 4)]

(version-compare "1.0" "1.0.0")
;; => 0
(version-compare "1.0-alpha5" "1.0-alpha14")
;; => -1
(version-compare "1.0-milestone" "1.0.0-final")
;; => -1

Version Sequence Creation

A version seq is a pair of version-information and qualifier-information. In general, a version string is split using dots (.) and dashes (-), but it is assumed that the last result of the dot-split represents qualifiers (except for its first element which is put into the version data seq). For example, the algorithm might produce the following steps:

   "9.1-0-1.1-alpha4"
=> ("9" "1-0-1" "1-alpha4")                                ;; split by dots
=> (("9" "1-0-1") ("1-alpha4"))                            ;; group into version/qualifier data
=> ((("9") ("1" "0" "1")) (("1" "alpha4")))                ;; split by dashes
=> (((("9")) (("1") ("0") ("1"))) ((("1") ("alpha" "4")))) ;; split by letter/integer changes
=> [(9 (1 0 1)) (1 ("alpha" 4))]                           ;; normalize
=> [(9 (1 0 1) 1) (("alpha" 4))]                           ;; rearrange remaining version data
=> [(9 (1 0 1) 1) ("alpha" 4)]                             ;; normalize qualifiers again

This should create results that represent an intuitive reading of version numbers.

Version Comparison

Version seqs are compared by extending them to the same length (using zero/nil) followed by an element-wise comparison.

  • Integers are compared numerically.
  • Strings are compared using a table of well-known qualifiers or lexicographically.
  • A well-known qualifier is newer than an unknown one.
  • Subsequences are compared like they represent versions of their own.
  • An integer is newer than a string.

The order of well-known qualifiers is case-insensitive and given as:

  "alpha"     == "a"
< "beta"      == "b"
< "milestone" == "m"
< "rc"        == "cr"
< "snapshot"
< "final"     == "stable" == ""

Have a look at the respective unit tests to see the comparison mechanism in action.

License

Copyright © 2013 Yannick Scherer

Distributed under the Eclipse Public License, the same as Clojure.

You can’t perform that action at this time.