semver

    Semantic versioning for MoonBit: lenient parsing, comparison and major/minor/patch bumping

    semver
    version
    compare
    bump
    Download zip
    Author
    Version
    0.3.0
    License
    MIT
    Last updated
    7 hours ago
    Downloads
    9

    #chensuiyi/semver

    Semantic versioning for MoonBit: lenient parsing, comparison, and major/minor/patch bumping.

    #Install

    moon add chensuiyi/semver

    #Features

    • parse is deliberately lenient: any prefix is skipped (v, product names), pre-release suffixes compare as their release triple, text without digits yields all zeros (treat as "unknown version")
    • compare is segment-by-segment ordering: -1, 0, or 1
    • bump increments one segment and zeroes the ones below

    #Scenarios

    • Release orchestration: bump all workspace members in dependency order
    • Runtime version checks: parse --version output, compare against a minimum

    #API

    FunctionDescription
    parse(text)Lenient extraction of the first triple
    compare(a, b)-1 / 0 / 1
    bump(v, kind)Major / Minor / Patch increment

    let found = @semver.parse("mycli 2.28.1") // (2, 28, 1)
    @semver.compare(found, @semver.parse("2.99.0")) < 0
    let next = @semver.bump(found, @semver.Bump::Minor)
    next.to_string() // "2.29.0"

    #Author

    #License

    MIT

    #chensuiyi/semver

    MoonBit 语义版本库:宽松解析、比较、major/minor/patch 递增。

    #安装

    moon add chensuiyi/semver

    #功能

    • parse 刻意宽松:跳过任意前缀(v、产品名),停在首个非版本字符;预发布后缀(1.4.0-beta)按发布三元组比较;无数字得全零(可视为"未知版本")
    • compare 逐段 ordering,返回 -1/0/1
    • bump 递增一段、清零低位段

    #场景

    • 发布编排:按拓扑序给工作区成员统一递增版本
    • 运行时版本检查:解析 --version 输出并与最低要求比较

    #API

    函数说明
    parse(text)宽松解析首个三元组
    compare(a, b)-1 / 0 / 1
    bump(v, kind)递增一段、清零低位段

    #用法示例

    let found = @semver.parse("mycli 2.28.1") // (2, 28, 1)
    @semver.compare(found, @semver.parse("2.99.0")) < 0
    let next = @semver.bump(found, @semver.Bump::Minor)
    next.to_string() // "2.29.0"

    #作者

    陈随易 (@chenbimo)

    #协议

    MIT

    Bump

    pub(all) enum Bump {
    Patch
    Minor
    Major
    }

    Which segment a bump increments.

    Semver

    pub(all) struct Semver {
    major : Int
    minor : Int
    patch : Int
    } derive(Eq,
    Debug
    )

    A semantic version triple.

    Semver::equal

    fn Semver::equal(Semver, Semver) -> Bool

    Semver::not_equal

    fn Semver::not_equal(x : Semver, y : Semver) -> Bool

    Semver::to_repr

    Semver::to_string

    fn Semver::to_string(self : Semver) -> String

    Render back to major.minor.patch.

    bump

    fn bump(version : Semver, kind : Bump) -> Semver

    Increment one segment, zeroing the ones below it.

    compare

    fn compare(a : Semver, b : Semver) -> Int

    Segment-by-segment ordering: -1, 0, or 1.

    parse

    fn parse(text : String) -> Semver

    Extract the first major.minor.patch triple found in text. Lenient by design: any prefix is skipped ("v1.4.0", "bun 1.4.0 (official)"), the scan stops at the first character that is not a digit or a dot, and missing segments read as zero — so pre-release suffixes ("0.3.0-beta.1") compare as their release triple. Text with no digits yields all zeros, which callers can treat as "unknown version".

    Source Files