semver #
Description
semver
is a library for processing versions, that use the semver format.
Examples
import semver
fn main() {
ver1 := semver.from('1.2.4') or {
println('Invalid version')
return
}
ver2 := semver.from('2.3.4') or {
println('Invalid version')
return
}
println(ver1.gt(ver2))
println(ver2.gt(ver1))
println(ver1.satisfies('>=1.1.0 <2.0.0'))
println(ver2.satisfies('>=1.1.0 <2.0.0'))
println(ver2.satisfies('>=1.1.0 <2.0.0 || >2.2.0'))
}
false
true
true
false
true
For more details see semver.v
file.
fn build #
fn build(major int, minor int, patch int) Version
build returns a Version
structure with given major
, minor
and patch
versions.
fn coerce #
fn coerce(input string) !Version
- Utilities.coerce converts the
input
version to aVersion
struct. coerce will strip any contents after the parsed version string:
fn from #
fn from(input string) !Version
- Constructor.from returns a
Version
structure parsed frominput
string
.
fn is_valid #
fn is_valid(input string) bool
is_valid returns true
if the input
string
can be converted to a (semantic) Version
struct.
fn (EmptyInputError) msg #
fn (err EmptyInputError) msg() string
fn (InvalidVersionFormatError) msg #
fn (err InvalidVersionFormatError) msg() string
enum Increment #
enum Increment {
major
minor
patch
}
Increment represents the different types of version increments.
struct Version #
struct Version {
pub:
major int
minor int
patch int
prerelease string
metadata string
}
- Structures.
Version
represents a semantic version in semver format.
fn (Version) increment #
fn (ver Version) increment(typ Increment) Version
- Transformation.increment returns a
Version
structure with incremented values.
fn (Version) satisfies #
fn (ver Version) satisfies(input string) bool
- Comparison.satisfies returns
true
if theinput
expression can be validated totrue
when run against thisVersion
.
Examples
assert semver.build(1,0,0).satisfies('<=2.0.0') == true
assert semver.build(1,0,0).satisfies('>=2.0.0') == false
fn (Version) eq #
deprecated: use v1 == v2 instead
fn (v1 Version) eq(v2 Version) bool
eq returns true
if v1
is equal to v2
.
fn (Version) == #
fn (v1 Version) == (v2 Version) bool
== checks if v1
is equal to v2
fn (Version) gt #
deprecated: use v1 > v2 instead
fn (v1 Version) gt(v2 Version) bool
gt returns true
if v1
is greater than v2
.
fn (Version) < #
fn (v1 Version) < (v2 Version) bool
< checks if v1
is less than v2
.
fn (Version) lt #
deprecated: use v1 < v2 instead
fn (v1 Version) lt(v2 Version) bool
lt returns true
if v1
is less than v2
.
fn (Version) ge #
deprecated: use v1 >= v2 instead
fn (v1 Version) ge(v2 Version) bool
ge returns true
if v1
is greater than or equal to v2
.
fn (Version) le #
deprecated: use v1 <= v2 instead
fn (v1 Version) le(v2 Version) bool
le returns true
if v1
is less than or equal to v2
fn (Version) str #
fn (ver Version) str() string
str returns the string
representation of the Version
.