semver

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

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

    #chensuiyi/semver

    Semantic versioning · 语义版本

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

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

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

    • parse is deliberately lenient: any prefix is skipped (v, product names), scanning stops at the first non-version character; pre-release suffixes (1.4.0-beta) 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

    #API

    接口 Interface说明 Description
    parse(text)宽松解析;Lenient extraction of the first triple
    compare(a, b)-1 / 0 / 1
    bump(v, kind)Major / Minor / Patch 递增;Increment one segment
    Semver::to_string1.4.0

    License: 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