Semver
implements semantic versions for Carp.
Semantic versions are composed of a major, minor, and patch version, and might optionally have a tag.
Installation
(load "https://github.com/carpentry-org/semver@0.2.0")
<
(Fn [(Ref Semver a), (Ref Semver a)] Bool)
(< a b)
compares two semantic versions for precedence per SemVer 2.0.0 §11:
major, minor, and patch numerically, then — when those are equal — by
pre-release tag. A version with a pre-release tag (e.g. 1.0.0-rc.1) has lower
precedence than the corresponding release (1.0.0). Build metadata is ignored.
compare
(Fn [(Ref Semver a), (Ref Semver a)] Int)
(compare a b)
compares two versions under SemVer 2.0.0 precedence, returning
-1 when a ranks below b, 1 when it ranks above, and 0 when the two are
of equal precedence. Handy as an explicit three-way comparator.
inc-major
(Fn [(Ref Semver a)] Semver)
(inc-major s)
returns s with its major version incremented and its minor
and patch reset, e.g. 1.2.3 becomes 2.0.0.
A pre-release of a major release is only released rather than bumped, so
2.0.0-rc.1 becomes 2.0.0 — but 1.2.0-alpha still becomes 2.0.0, since it
is a pre-release of 1.2.0 rather than of 1.0.0. The result never carries a
tag.
inc-minor
(Fn [(Ref Semver a)] Semver)
(inc-minor s)
returns s with its minor version incremented and its patch
reset, e.g. 1.2.3 becomes 1.3.0.
A pre-release of a minor release is only released rather than bumped, so
1.2.0-alpha becomes 1.2.0 — but 1.2.3-alpha still becomes 1.3.0, since it
is a pre-release of 1.2.3 rather than of 1.2.0. The result never carries a
tag.
inc-patch
(Fn [(Ref Semver a)] Semver)
(inc-patch s)
returns s with its patch version incremented, e.g. 1.2.3
becomes 1.2.4.
Since 1.2.3-alpha.1 is a pre-release of 1.2.3, incrementing the patch of a
pre-release only releases it, yielding 1.2.3. Build metadata is not a
pre-release, so 1.2.3+build.5 still becomes 1.2.4. The result never carries a
tag.
set-tag!
(Fn [(Ref Semver a), (Maybe String)] ())
sets the tag property of a Semver in place.
str
(Fn [(Ref Semver a)] String)
(str s)
converts a semantic version to a string, e.g. 1.2.3 or 1.2.3-tag.
update-major
(Fn [Semver, (Ref (Fn [Int] Int a) b)] Semver)
updates the major property of a Semver using a function f.
update-minor
(Fn [Semver, (Ref (Fn [Int] Int a) b)] Semver)
updates the minor property of a Semver using a function f.
update-patch
(Fn [Semver, (Ref (Fn [Int] Int a) b)] Semver)
updates the patch property of a Semver using a function f.
update-tag
(Fn [Semver, (Ref (Fn [(Maybe String)] (Maybe String) a) b)] Semver)
updates the tag property of a Semver using a function f.