Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

v0 source pure

Package semver is an on-chain port of the core of golang.org/x/mod/semver (and the spirit of github.com/Masterminds/s...

Readme View source

gno.land/p/moul/x/daily/semver/v0

Semantic Versioning 2.0.0 parser + comparatorParse, 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.

Overview

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).

Functions 2

func Compare

1func Compare(a, b string) int
source

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.

func Parse

1func Parse(s string) (Version, error)
source

Parse reads "vMAJOR.MINOR.PATCH[-prerelease][+build]". The leading 'v' is optional. Numeric fields must be non-empty digit runs without leading zeros.

Types 1

type Version

struct
1type Version struct {
2	Major, Minor, Patch int
3	Pre                 []string // pre-release identifiers (dot-separated)
4	Build               string   // build metadata (after '+')
5	Orig                string   // original input
6}
source

Version is a parsed semantic version. Build metadata is retained for display but, per the spec, is ignored when comparing precedence.

Methods on Version

func Canonical

method on Version
1func (v Version) Canonical() string
source

Canonical renders the parsed version back to a canonical string.

Imports 2

  • errors stdlib
  • strings stdlib

Source Files 3