fndash

    lodash-style utility belt for MoonBit: string trimming, strict int parsing, quoted-value extraction, JSON building and percent-encoding

    utils
    string
    json
    urlencode
    helpers
    Download zip
    Author
    Version
    0.1.0
    License
    MIT
    Last updated
    6 hours ago
    Downloads
    3

    #chensuiyi/fndash

    lodash-style utilities · 通用工具函数

    纯函数工具集:字符串裁剪、严格整数解析、引号值提取、JSON 拼装、百分号编码。

    • jobj 接收已编码的值片段:可选字段不出现在输入里,就不会以 null 出现在线上
    • parse_int 严格模式:非纯数字一律 None
    • 准入规则:纯函数、零依赖、有测试,不收带 I/O 的函数

    Pure-function toolkit: string trimming, strict integer parsing, quoted-value extraction, JSON assembly, percent-encoding.

    • jobj takes pre-encoded value fragments: an optional field absent from the input never becomes a null on the wire
    • parse_int is strict: anything non-numeric is None, never a partial value
    • Admission rule: pure, zero-dependency, tested — no I/O functions

    #API

    接口 Interface说明 Description
    trim_spaces(text)去两端空白(容忍 CRLF);Trim both ends, CRLF-tolerant
    parse_int(text)严格整数;Strict digits-only int
    quoted_value(line)首个引号段;First double-quoted segment
    json_escape / jstr / jobj / jarrJSON 拼装;JSON building blocks
    url_encode(text)百分号编码;Percent-encoding

    License: MIT

    discard

    fn discard(f : () -> Unit raise) -> Unit

    Run a side effect whose failure must not abort the caller. Supervision and lifecycle progress are defined to survive a broken disk, a dead peer or a vanished process, so every best-effort step routes through here instead of hand-rolling another try/catch pair.

    jarr

    fn jarr(items : Array[String]) -> String

    Build a JSON array from already-encoded item fragments.

    jobj

    fn jobj(fields : Array[(String, String)]) -> String

    Build a JSON object from already-encoded value fragments, so an optional key simply does not appear instead of turning into a null the platform may reject. Keys are quoted by jstr; values must arrive pre-encoded (e.g. jstr(...) for strings, raw digits for numbers).

    json_escape

    fn json_escape(text : String) -> String

    Escape a string for embedding inside a JSON double-quoted literal: quotes, backslashes and the C/JSON control escapes; other control characters become \u00XX.

    jstr

    fn jstr(text : String) -> String

    A JSON string literal: the text, escaped and wrapped in quotes.

    parse_int

    fn parse_int(text : String) -> Int?

    Strict non-negative integer: every character must be an ASCII digit, empty input rejected. Returns None instead of a partial number.

    quoted_value

    fn quoted_value(line : String) -> String

    Text of the first double-quoted segment in a line, or "" when the line quotes nothing. Built for key = "value" manifest lines.

    trim_spaces

    fn trim_spaces(text : StringView) -> String

    Strip spaces and tabs from both ends (plus a trailing CR, so Windows line endings survive a split("\n")).

    url_encode

    fn url_encode(text : String) -> String

    Percent-encode a value for a URL query string or a form body: everything outside the RFC 3986 unreserved set becomes %XX over UTF-8 bytes.