SemVer 2.0.0 library for PicoLisp
"1.0.0"
)1.1.0-alpha.1 -> 1.1.0
)2.2.0+buildmetadata -> 2.0.0
)v
or v.
(ex: v3.3.0 -> 3.3.0
)"1.invalid.0" -> NIL
)v16.6+
, or pil21
vv20.6.29
, see test runsThis library is now declared stable and should be suitable for use in production environments.
Note: Namespaces can be disabled by setting the environment variable
PIL_NAMESPACES=false
semver.l
in your application: (load "semver.l")
Function | Description | Returns | Example |
---|---|---|---|
semver-format |
Formats a version string into a list of integers | List of integers | (1 4 2) |
semver-cmp |
Compares two lists of integers using the spaceship <=> |
List containing NIL, 0 or T | (NIL 0 T) |
semver-compare |
Compares two version strings | NIL, 0, or T | T |
semver-sort |
Sorts a list of version strings | List of integers or strings | ((1 3 0) (1 4 0) (1 6 0)) or ("1.3.0" "1.4.0" "1.6.0") |
semver-satisfies |
Returns whether a version is satisfied by a range | NIL or T | NIL or T |
Invalid versions are returned as NIL
.
Version comparison is always from left to right.
A brief explanation of the result obtained from semver-compare
:
if left < right then return NIL # left is older
if left = right then return 0 # left and right are the same
if left > right then return T # left is newer
(load "semver.l")
(semver-compare "1.4.0" "1.5.0")
-> NIL
(semver-compare "1.5.0" "1.5.0")
-> 0
(semver-compare "1.6.0" "1.5.0")
-> T
(load "semver.l")
(semver-format "1.4.0")
-> (1 4 0)
(car)
corresponds to the major
(cadr)
corresponds to the minor
(caddr)
corresponds to the patch
(load "semver.l")
(semver-cmp (2 3 2) (1 4 2))
-> (T NIL 0)
(semver-cmp (1 5 0) (1 4 2))
-> (0 T NIL)
(semver-cmp (2 3 2) (1 4 2))
-> (T NIL 0)
(load "semver.l")
(semver-sort '("1.4.0" "1.6.0" "1.3.0" "1.4.0-alpha"))
-> ((1 3 0) (1 4 0) (1 4 0) (1 6 0))
(semver-sort '("1.4.0" "1.6.0" "1.3.0" "1.4.0-alpha") T)
-> ("1.3.0" "1.4.0" "1.4.0" "1.6.0")
Arguments:
first
argument is the versionsecond
argument is the minimum version: must be >=
(greater than or equal)third
argument is the maximum version: must be <
(less than)Notes:
NIL
is returnedfirst
argument is NIL
, NIL
is returnedfirst
argument is supplied, T
is returnedthird
argument is NIL
, only the minimum >=
is comparedsecond
argument is NIL
, but the third
is supplied, only the maximum <
is compared(load "semver.l")
(semver-satisfies)
-> NIL
(semver-satisfies NIL NIL "3.0.0")
-> NIL
(semver-satisfies "2.0.0")
-> T
(semver-satisfies "2.0.0" "1.0.0")
-> T
(semver-satisfies "2.0.0" NIL "1.0.0")
-> NIL
(semver-satisfies "2.0.0" NIL "3.0.0")
-> T
(semver-satisfies "1.0.0" "1.0.0" "2.0.0")
-> T
(semver-satisfies "1.6.0" "1.0.0" "2.0.0")
-> T
(semver-satisfies "3.0.0" "1.0.0" "2.0.0")
-> NIL
(semver-satisfies "0.9.0" "1.0.0" "2.0.0")
-> NIL
(semver-satisfies "2.0.0" "1.0.0" "2.0.0")
-> NIL
This library now comes with full unit tests. To run the tests, type:
make check
If you find any bugs or issues, please create an issue.
If you want to improve this library, please make a pull-request.
Copyright (c) 2017-2020 Alexander Williams, Unscramble license@unscramble.jp