Something went wrong. Try again.
A URI parser and formatter for Zig, modelled on Python's hyperlink package, with LDAP URLs, file: URIs and sdns:// DNS stamps beside it.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216<!DOCTYPE html><!--SPDX-FileCopyrightText: © 2026 Jeffrey C. Ollie <jeff@ocjtech.us>SPDX-License-Identifier: MIT--><html lang="en"> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>zig-uri in the browser</title> <style> :root { color-scheme: light dark; --bg: #fdfdfc; --fg: #1b1b19; --muted: #6b6b66; --line: #dededa; --field: #ffffff; --accent: #2a5db0; --bad: #a52a2a; } @media (prefers-color-scheme: dark) { :root { --bg: #17181a; --fg: #e6e6e3; --muted: #9a9a94; --line: #33353a; --field: #1f2124; --accent: #7aa7ee; --bad: #e08c8c; } } * { box-sizing: border-box; } body { margin: 0 auto; padding: 2rem 1.25rem 4rem; max-width: 54rem; background: var(--bg); color: var(--fg); font: 16px/1.55 system-ui, -apple-system, "Segoe UI", sans-serif; } h1 { font-size: 1.5rem; margin: 0 0 0.25rem; } h2 { font-size: 1rem; margin: 2rem 0 0.5rem; text-transform: lowercase; letter-spacing: 0.04em; color: var(--muted); } p.lede { margin: 0 0 1.5rem; color: var(--muted); } code, input, td.value, .out { font-family: ui-monospace, "SFMono-Regular", "Cascadia Code", Menlo, monospace; } label { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 0.25rem; } input[type="text"] { width: 100%; padding: 0.55rem 0.7rem; font-size: 0.95rem; color: var(--fg); background: var(--field); border: 1px solid var(--line); border-radius: 6px; } input[type="text"]:focus { outline: 2px solid var(--accent); outline-offset: -1px; } .row { display: flex; gap: 0.75rem; flex-wrap: wrap; margin-bottom: 1rem; } .row > div { flex: 1 1 14rem; } table { border-collapse: collapse; width: 100%; font-size: 0.9rem; } th, td { text-align: left; padding: 0.3rem 0.5rem 0.3rem 0; border-bottom: 1px solid var(--line); vertical-align: top; } th { width: 8.5rem; font-weight: 500; color: var(--muted); } td.value { white-space: pre-wrap; word-break: break-all; } .absent { color: var(--muted); font-style: italic; } .out { display: block; padding: 0.55rem 0.7rem; background: var(--field); border: 1px solid var(--line); border-radius: 6px; font-size: 0.9rem; word-break: break-all; min-height: 1.55em; } .out + .out { margin-top: 0.4rem; } .error { color: var(--bad); } .toggles { display: flex; gap: 1rem; flex-wrap: wrap; font-size: 0.85rem; margin-bottom: 0.6rem; } .toggles label { display: inline-flex; gap: 0.35rem; align-items: center; margin: 0; color: var(--fg); } footer { margin-top: 3rem; font-size: 0.8rem; color: var(--muted); } a { color: var(--accent); } </style> </head> <body> <h1>zig-uri in the browser</h1> <p class="lede"> The Zig library compiled to WebAssembly and driven from <code>uri.js</code>. Everything below is computed by the same parser the Zig tests exercise. </p>
<div class="row"> <div> <label for="input">URI reference</label> <input id="input" type="text" spellcheck="false" value="https://user:secret@Example.COM:443/a/./b/../c%2Fd?q=1&flag#top" /> </div> <div> <label for="href">resolve this against it</label> <input id="href" type="text" spellcheck="false" value="../sibling?x=2" /> </div> </div>
<h2>components</h2> <table id="components"></table>
<h2>text</h2> <div class="toggles"> <label><input type="checkbox" id="iri" /> IRI form</label> <label><input type="checkbox" id="password" /> include password</label> <label><input type="checkbox" id="dropPort" /> normalize: drop default port</label> <label><input type="checkbox" id="rootPath" /> normalize: root empty path</label> </div> <span class="out" id="text"></span> <span class="out" id="normalized"></span> <span class="out" id="resolved"></span> <span class="out" id="ascii"></span> <span class="out" id="unicodeForm"></span>
<footer id="status">loading uri.wasm…</footer>
<script type="module"> import { init, Uri, hasUnicode, UriError } from "./uri.js";
const $ = (id) => document.getElementById(id); const fields = [ "scheme", "username", "password", "host", "hostKind", "port", "rooted", "path", "query", "fragment", ];
/** Show a value the way the JavaScript API actually hands it over. */ function show(value) { if (value === null) return { text: "null", absent: true }; if (Array.isArray(value)) { if (value.length === 0) return { text: "[]", absent: true }; return { text: JSON.stringify(value), absent: false }; } return { text: JSON.stringify(value), absent: false }; }
function render() { const table = $("components"); const options = { form: $("iri").checked ? "iri" : "uri", withPassword: $("password").checked, }; const normalizeOptions = { ...options, dropDefaultPort: $("dropPort").checked, rootEmptyPath: $("rootPath").checked, };
let u; try { u = Uri.parse($("input").value); } catch (error) { table.innerHTML = ""; for (const id of ["text", "normalized", "resolved", "ascii", "unicodeForm"]) { $(id).textContent = ""; $(id).classList.remove("error"); } $("text").textContent = `${error.code ?? error.message}`; $("text").classList.add("error"); return; }
table.innerHTML = ""; for (const name of fields) { const { text, absent } = show(u[name]); const row = table.insertRow(); const heading = document.createElement("th"); heading.textContent = name; row.append(heading); const cell = row.insertCell(); cell.className = absent ? "value absent" : "value"; cell.textContent = text; }
line("text", () => `toString() → ${u.toString(options)}`); line("normalized", () => `normalize() → ${u.normalize(normalizeOptions).toString(options)}`); line("resolved", () => `resolve() → ${u.resolve($("href").value).toString(options)}`); if (hasUnicode()) { line("ascii", () => `toUri() → ${u.toUri().toString({ ...options, form: "uri" })}`); line("unicodeForm", () => `toIri() → ${u.toIri().toString({ ...options, form: "iri" })}`); } else { $("ascii").textContent = "toUri()/toIri() need a module built with -Dunicode=true"; $("unicodeForm").textContent = ""; } }
/** Run one derivation, showing a `UriError` in place rather than throwing. */ function line(id, compute) { const element = $(id); try { element.textContent = compute(); element.classList.remove("error"); } catch (error) { element.textContent = error instanceof UriError ? `${error.code}` : String(error); element.classList.add("error"); } }
try { await init(); $("status").textContent = `uri.wasm loaded — Unicode support is ${hasUnicode() ? "on" : "off"}.`; for (const element of document.querySelectorAll("input")) { element.addEventListener("input", render); } render(); } catch (error) { $("status").textContent = `could not load uri.wasm: ${error}`; $("status").classList.add("error"); } </script> </body></html>