A formally verified MoonBit kernel for HTML escaping, filename sanitisation, URL rewriting and joined-list batch operations.
huanguan-Q/textkernel 151 tests × 4 backends 419 proof goals 13 WASM API exports (+ `_start`) zero deps| Routine | What it guarantees |
|---|---|
| escape_html / escape_attr | Output contains no raw < > (nor " ' for attributes); every & starts a complete entity the library emits |
| sanitize_filename | Replaces the nine unsafe characters and lone surrogates, clamps to 120 code units, never returns empty |
| normalize_asset_url | Forces https for configured hosts and appends missing default query params; the tail is carried over verbatim |
| decide_referrer_policy | Picks a Referrer-Policy from a configured host allow-list |
| str_contains | UTF-16 code-unit substring test (the host gate above) |
| split_joined / join_joined | Exact inverse pair for batch calls; slices by code unit so non-BMP characters survive |
| batch_process_custom | Applies an operation in bounded chunks; a non-positive chunk size is clamped to 1, never divided by |
moon fmt --check
moon check --target all --deny-warn # wasm / wasm-gc / js / native, zero warnings
moon test --target all # 151/151 on each backend
moon prove # 191 goals with the stock solver limits
node scripts/prove_gate.mjs # 419 goals, 10x solver limits in CI, machine-int model
moon run src/demo --target native # runnable example
moon package --list # validate package contents without releasing
node scripts/build_wasm.mjs # build wasm/textkernel.wasm
node examples/wasm-node/demo.mjs # call the WASM exports from JavaScript
node examples/wasm-node/render.mjs # downstream consumer examplelet safe = @lib.escape_html("<script>alert(1)</script>")
// <script>alert(1)</script>
let name = @lib.sanitize_filename("report/2026:Q4?.md")
// report_2026_Q4_.md
let items = @lib.split_joined("a|b|c", "|")
let out = @lib.join_joined(@lib.quick_batch_escape_htmls(items), "|")let config = @lib.create_asset_config(
["cdn.internal.example"],
["w=800", "auto=1"],
)
let url = @lib.normalize_asset_url_with_config(
"http://cdn.internal.example/a.png",
config,
)
// https://cdn.internal.example/a.png?w=800&auto=1moonx huanguan-Q/textkernel/src/main@0.1.4 -- --help
moonx huanguan-Q/textkernel/src/main@0.1.4 -- escape-html '<script>x</script>'
moon run src/cli --target native -- sanitize-filename < names.txt| Single value | Joined-list batch (joined, sep) |
|---|---|
| escape_html, escape_attr, sanitize_filename | escape_htmls_joined, escape_attrs_joined, sanitize_filenames_joined |
| normalize_asset_url, decide_referrer_policy, str_contains | normalize_asset_urls_joined |
| escape_html_safe, escape_attr_safe, sanitize_filename_safe | — never-fail variants |
node scripts/build_wasm.mjs # ~23 KB artefact after the CLI entry point; verifies 13 API exports (+ `_start`)
node examples/wasm-node/demo.mjs # assertions across all 13 API exports
node examples/wasm-node/render.mjs # realistic downstream consumer| Policy | Behaviour | Use |
|---|---|---|
| FailFast (compatibility default) | abort | Trusted inputs; preserves historical semantics |
| EmptyOnError | return "" | Trust boundaries where a trap would take down the host |
| Input (UTF-16 code units) | Before | After | Speedup |
|---|---|---|---|
| 20,480 | 6.06 s | 0.49 s | 12x |
| 81,920 | 50.54 s | 0.56 s | 90x |
| 327,680 | 187.8 s / 20 rounds | 0.73 s / 100 rounds | ~1300x per round |
Install
Download zipA formally verified MoonBit kernel for HTML escaping, filename sanitisation, URL rewriting and joined-list batch operations.