SemanticVersion
The SemanticVersion module provides functions for working with semantic versions
in the major.minor.patch format (e.g., "1.2.3"). Follows the
SemVer specification.
Construction
SemanticVersion
Int -> Int -> Int -> SemanticVersion
Creates a semantic version from major, minor, and patch numbers.
v = SemanticVersion 1 2 3
println (SemanticVersion.to-string v)
# => "1.2.3"
Parsing and Formatting
SemanticVersion.parse
String -> SemanticVersion
Parses a version string into a SemanticVersion.
v = SemanticVersion.parse "1.2.3"
println (SemanticVersion.major v)
# => 1
SemanticVersion.to-string
SemanticVersion -> String
Converts a SemanticVersion to a string in "major.minor.patch" format.
v = SemanticVersion 1 2 3
println (SemanticVersion.to-string v)
# => "1.2.3"
SemanticVersion.debug
SemanticVersion -> String
Converts a SemanticVersion to a debug string representation.
Version Components
SemanticVersion.major
SemanticVersion -> Int
Returns the major version number.
SemanticVersion.minor
SemanticVersion -> Int
Returns the minor version number.
SemanticVersion.patch
SemanticVersion -> Int
Returns the patch version number.
v = SemanticVersion.parse "2.5.10"
println (SemanticVersion.major v) # => 2
println (SemanticVersion.minor v) # => 5
println (SemanticVersion.patch v) # => 10
Comparison
SemanticVersion.compare
SemanticVersion -> SemanticVersion -> Int
Compares two versions. Returns
-1 if the first is less,
0 if equal, 1 if greater.
v1 = SemanticVersion 1 2 0
v2 = SemanticVersion 1 3 0
println (SemanticVersion.compare v1 v2)
# => -1
SemanticVersion.eq?
SemanticVersion -> SemanticVersion -> Bool
Returns
true if two versions are equal.
SemanticVersion.lt? / SemanticVersion.gt?
SemanticVersion -> SemanticVersion -> Bool
Returns
true if the first version is less than / greater than the second.
SemanticVersion.lte? / SemanticVersion.gte?
SemanticVersion -> SemanticVersion -> Bool
Returns
true if the first version is less than or equal / greater than or equal to the second.
v1 = SemanticVersion 2 0 0
v2 = SemanticVersion 1 9 9
println (SemanticVersion.gt? v1 v2) # => true
println (SemanticVersion.gte? v1 v2) # => true
Type Checking
is-semantic-version?
a -> Bool
Returns
true if the value is a SemanticVersion.
v = SemanticVersion 1 0 0
println (is-semantic-version? v) # => true
println (is-semantic-version? 42) # => false