querystring

    A small MoonBit library for parsing query strings and reading typed values.

    querystring
    url
    parser
    Download zip
    Author
    Version
    0.1.2
    License
    Apache-2.0
    Last updated
    4 months ago
    Downloads
    44

    #hackwaly/querystring

    A small MoonBit library for parsing URL query strings and reading values as strings, integers, and boolean flags.

    #Installation

    Add hackwaly/querystring to your MoonBit project dependencies, then import the package where you need to parse query strings.

    #Usage

    ///|
    test "read query string values" {
    let query = @querystring.Querystring::Querystring(
    "name=MoonBit&count=42&enabled=true",
    )

    assert_eq(query.string("name"), "MoonBit")
    assert_eq(query.int("count"), 42)
    assert_eq(query.flag("enabled"), true)
    }

    Use optional accessors when a key may be absent.

    ///|
    test "optional values" {
    let query = @querystring.Querystring::Querystring("name=MoonBit")

    assert_true(query.string_opt("name") is Some("MoonBit"))
    assert_true(query.string_opt("missing") is None)
    assert_true(query.int_opt("missing") is None)
    }

    Keys without = are treated as present with an empty value. Empty keys are ignored.

    ///|
    test "empty values" {
    let query = @querystring.Querystring::Querystring("empty=&present&&=ignored")

    assert_eq(query.string("empty"), "")
    assert_eq(query.string("present"), "")
    assert_true(query.string_opt("") is None)
    }

    Querystring

    pub struct Querystring {
    // private fields
    }
    fn Querystring::Querystring(str : StringView) -> Querystring

    Querystring::flag

    fn Querystring::flag(self : Querystring, key : StringView, truthy_values? :
    SortedSet
    [StringView]) -> Bool

    Querystring::int

    fn Querystring::int(self : Querystring, key : StringView) -> Int raise

    Querystring::int_opt

    fn Querystring::int_opt(self : Querystring, key : StringView) -> Int? raise

    Querystring::string

    fn Querystring::string(self : Querystring, key : StringView) -> String raise

    Querystring::string_opt

    fn Querystring::string_opt(self : Querystring, key : StringView) -> String?

    Querystring::stringview

    fn Querystring::stringview(self : Querystring, key : StringView) -> StringView raise

    Querystring::stringview_opt

    fn Querystring::stringview_opt(self : Querystring, key : StringView) -> StringView?

    default_truthy_values

    let default_truthy_values :
    SortedSet
    [StringView]

    Source Files

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io