func Compare
Compare returns -1, 0, or +1 as a < b, a == b, or a > b under semver precedence. Unparseable inputs sort after everything valid (and equal to each other), so Compare never panics.
Package semver is an on-chain port of the core of golang.org/x/mod/semver (and the spirit of github.com/Masterminds/s...
gno.land/p/moul/x/daily/semver/v0Semantic Versioning 2.0.0 parser + comparator — Parse, Compare, and the
Version type (with Canonical).
An on-chain port of the core of Go's golang.org/x/mod/semver
(and the spirit of Masterminds/semver).
Parses vMAJOR.MINOR.PATCH[-prerelease][+build] and compares with correct
precedence: numeric fields compare numerically (so 1.2.3 < 1.2.10), a
pre-release ranks below its release (1.0.0-alpha < 1.0.0), numeric pre-release
identifiers rank below alphanumeric ones, and build metadata is ignored. Pure
and deterministic — no avl, no chain imports, no ambient state.
1import "gno.land/p/moul/x/daily/semver/v0"
2
3v, err := semver.Parse("v1.0.0-rc.1+ci.7") // Version{Major:1, Pre:["rc","1"], …}
4semver.Compare("1.2.3", "1.2.10") // -1
5v.Canonical() // "1.0.0-rc.1+ci.7"
Live demo: r/moul/x/daily/semverdemo
· render it at /r/moul/x/daily/semverdemo/v0.
Part of moul/gno-contracts — moul's versioned gno.land contracts. See the repository for the full catalog, build/test tooling, and usage.
🧪 Highly experimental — potentially vibe-coded. Not audited; may break, change, or be removed at any time. Do not use with anything of value. Full disclaimer: DISCLAIMER.
Package semver is an on-chain port of the core of golang.org/x/mod/semver (and the spirit of github.com/Masterminds/semver): parse "vMAJOR.MINOR.PATCH [-prerelease][+build]" strings and compare them with correct Semantic Versioning 2.0.0 precedence. Pure and deterministic — no time, randomness, goroutines, or I/O.
This package holds only the pure parsing/comparison API. For a live, stateful gnoweb demo that imports it and keeps an on-chain "submitted versions" board, see r/moul/x/daily/semverdemo(/r/moul/x/daily/semverdemo/v0).
Compare returns -1, 0, or +1 as a < b, a == b, or a > b under semver precedence. Unparseable inputs sort after everything valid (and equal to each other), so Compare never panics.
Parse reads "vMAJOR.MINOR.PATCH[-prerelease][+build]". The leading 'v' is optional. Numeric fields must be non-empty digit runs without leading zeros.
Version is a parsed semantic version. Build metadata is retained for display but, per the spec, is ignored when comparing precedence.