1// Package humanizedemo is a small gnoweb demo of the human-facing formatters2// provided by the [p/moul/x/daily/humanize](/p/moul/x/daily/humanize/v0)3// library: byte sizes, thousands separators, ordinals and block counts.4//5// It contains no formatting logic of its own. Stateless, so Render is6// deterministic.7package humanizedemo89import (10 "strconv"11 "strings"1213 "gno.land/p/moul/x/daily/humanize/v0"14)1516var sizes = []int64{0, 999, 1024, 1536, 1048576, 1073741824}17var counts = []int64{0, 1000, 1234567}18var ordinals = []int64{1, 2, 3, 11, 12, 13, 21, 101}19var blocks = []int64{0, 1, 15, 1234}2021// Render renders the demo for gnoweb.22func Render(path string) string {23 var b strings.Builder24 b.WriteString("# Humanize\n\n")25 b.WriteString("Integer-only formatting for people, demoing the ")26 b.WriteString("[`p/moul/x/daily/humanize`](/p/moul/x/daily/humanize/v0) library.\n\n")2728 b.WriteString("## Bytes\n\n| n | rendered |\n|---|---|\n")29 for _, n := range sizes {30 row(&b, strconv.FormatInt(n, 10), humanize.Bytes(n))31 }3233 b.WriteString("\n## Thousands\n\n| n | rendered |\n|---|---|\n")34 for _, n := range counts {35 row(&b, strconv.FormatInt(n, 10), humanize.Comma(n))36 }3738 b.WriteString("\n## Ordinals\n\n")39 parts := []string{}40 for _, n := range ordinals {41 parts = append(parts, humanize.Ordinal(n))42 }43 b.WriteString("`" + strings.Join(parts, "` · `") + "`\n")44 b.WriteString("\n> 11th/12th/13th, not 11st/12nd/13rd — the teens are the trap.\n")4546 b.WriteString("\n## Block counts\n\n| blocks | rendered |\n|---|---|\n")47 for _, n := range blocks {48 row(&b, strconv.FormatInt(n, 10), humanize.Blocks(n))49 }50 b.WriteString("\n> Deliberately vague, and in **blocks**: there is no wall clock ")51 b.WriteString("on chain, so \"about 2 hours\" would be a lie dressed as precision.\n")52 return b.String()53}5455func row(b *strings.Builder, a, c string) {56 b.WriteString("| `")57 b.WriteString(a)58 b.WriteString("` | ")59 b.WriteString(c)60 b.WriteString(" |\n")61}62Render(path string) string
Signatures reconstructed verbatim from vm/qfuncs — interface params keep their inline definitions.
vm/qrender output, sanitized (docs/render-security.md) and displayed in an empty-sandbox iframe — scripts, forms and popups cannot run. Links stay inert in-preview; right-click to open.