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

/p/moul/x/daily/humanize/v0

Directory · 3 Files
README.md Open

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

Human-facing number formattingBytes, Comma, Ordinal, Plural, Blocks, Truncate.

1import "gno.land/p/moul/x/daily/humanize/v0"
2
3humanize.Bytes(1536)        // "1.5 KiB"
4humanize.Comma(1234567)     // "1,234,567"
5humanize.Ordinal(12)        // "12th"  — not "12nd"
6humanize.Plural(2, "mouse", "mice")  // "2 mice"
7humanize.Blocks(1234)       // "~1,200 blocks"
8humanize.Truncate("ééé", 2) // "é…"

Integer-only, on purpose. No floats anywhere: a rendered value that differed between nodes would be a consensus bug, so the single decimal place in Bytes comes from scaling by 10 and taking a remainder.

Durations are in blocks, never seconds. There is no wall clock on chain, so "about 2 hours" is a lie dressed as precision. Blocks says ~1,200 blocks and lets the caller decide what that means on their chain — and rounds deliberately, because false precision is worse than none.

Ordinal handles the teens (11th/12th/13th, not 11st/12nd/13rd) — the case naive implementations get wrong. Truncate counts runes, so multi-byte text is never sliced mid-character.

Live demo: r/moul/x/daily/humanizedemo · render it at /r/moul/x/daily/humanizedemo/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.