Appearance
Smoke test (clean environment)
This verifies the Quick Start code runs end-to-end in a fresh project.
1) Create a fresh project
bash
mkdir tl-smoke && cd tl-smoke
npm init -y
npm i true-link vite
npm pkg set type=module2) Create index.html
html
<!doctype html>
<html>
<body>
<pre id="out">loading…</pre>
<script type="module" src="/main.js"></script>
</body>
</html>3) Create main.js
js
import { createTrueLink } from "true-link/vanilla";
const out = document.getElementById("out");
const tl = createTrueLink({ pingUrl: "/favicon.ico" });
tl.subscribe((v) => {
if (!v) {
out.textContent = "SSR / null";
return;
}
out.textContent = JSON.stringify(
{
online: v.isOnline,
strength: v.strength,
latency: v.latency,
checking: v.isChecking,
},
null,
2
);
});4) Run
bash
npx vite
# if you want to open from your phone on the same Wi‑Fi:
# npx vite --hostOpen the URL and observe:
strengthstarts as"strong"or"weak"(depending on latency)latencyshows ping time in ms- Go offline (network disconnect) →
strengthbecomes"offline" - Go online → strength returns to
"strong"or"weak"
If this library helps, you can support development.