2026-03-05 00:04:26 -06:00
|
|
|
export function countryToFlag(code) {
|
|
|
|
|
const fallback = `<span class="fi fi-so"></span>`;
|
|
|
|
|
if (!code) return fallback;
|
|
|
|
|
const cc = String(code).trim().toLowerCase();
|
|
|
|
|
|
|
|
|
|
if (!/^[a-z]{2}$/.test(cc) || cc === "zz") return fallback;
|
|
|
|
|
return `<span class="fi fi-${cc}"></span>`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function formatPing(ms) {
|
|
|
|
|
if (ms === null || ms === undefined) return "measuring…";
|
|
|
|
|
return `${ms} ms`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function formatAgo(ts) {
|
|
|
|
|
const delta = Date.now() - ts;
|
|
|
|
|
const minutes = Math.floor(delta / 60000);
|
|
|
|
|
if (minutes < 1) return "just now";
|
|
|
|
|
if (minutes === 1) return "1 minute ago";
|
|
|
|
|
if (minutes < 60) return `${minutes} minutes ago`;
|
|
|
|
|
const hours = Math.floor(minutes / 60);
|
|
|
|
|
if (hours === 1) return "1 hour ago";
|
|
|
|
|
if (hours < 24) return `${hours} hours ago`;
|
|
|
|
|
const days = Math.floor(hours / 24);
|
|
|
|
|
return `${days}d ago`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function shortId(id = "") {
|
|
|
|
|
if (!id) return "unknown";
|
|
|
|
|
return id.length <= 8 ? id : `${id.slice(0, 6)}…${id.slice(-2)}`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function osBadge(osRaw = "") {
|
|
|
|
|
const os = osRaw.toLowerCase();
|
|
|
|
|
const base = {
|
|
|
|
|
label: osRaw || "Unknown",
|
2026-06-05 22:52:08 -05:00
|
|
|
icon: "fa-solid fa-circle-question",
|
2026-03-05 00:04:26 -06:00
|
|
|
tone: "pill-unknown",
|
|
|
|
|
};
|
2026-05-30 22:44:55 -05:00
|
|
|
if (os.includes("windows 11"))
|
|
|
|
|
return { label: "W11", icon: "fa-brands fa-windows", tone: "pill-win" };
|
|
|
|
|
if (os.includes("windows 10"))
|
|
|
|
|
return { label: "W10", icon: "fa-brands fa-windows", tone: "pill-win" };
|
2026-03-05 00:04:26 -06:00
|
|
|
if (os.includes("windows"))
|
|
|
|
|
return { label: "Windows", icon: "fa-brands fa-windows", tone: "pill-win" };
|
|
|
|
|
if (os.includes("mac") || os.includes("darwin"))
|
|
|
|
|
return { label: "macOS", icon: "fa-brands fa-apple", tone: "pill-mac" };
|
2026-05-30 22:44:55 -05:00
|
|
|
if (os.includes("linux mint"))
|
|
|
|
|
return { label: "Mint", icon: "cv-os-icon cv-os-icon-mint", tone: "pill-mint" };
|
2026-06-05 22:52:08 -05:00
|
|
|
if (os.includes("pop!_os") || os.includes("pop os") || os.includes("pop-os"))
|
|
|
|
|
return { label: "Pop!_OS", icon: "cv-os-icon cv-os-icon-pop", tone: "pill-pop" };
|
2026-03-05 00:04:26 -06:00
|
|
|
if (os.includes("ubuntu"))
|
2026-05-30 22:44:55 -05:00
|
|
|
return { label: "Ubuntu", icon: "fa-brands fa-ubuntu", tone: "pill-ubuntu" };
|
2026-03-05 00:04:26 -06:00
|
|
|
if (os.includes("debian"))
|
2026-05-30 22:44:55 -05:00
|
|
|
return { label: "Debian", icon: "fa-brands fa-debian", tone: "pill-debian" };
|
2026-06-05 22:52:08 -05:00
|
|
|
if (os.includes("manjaro"))
|
|
|
|
|
return { label: "Manjaro", icon: "cv-os-icon cv-os-icon-manjaro", tone: "pill-manjaro" };
|
2026-03-05 00:04:26 -06:00
|
|
|
if (os.includes("arch"))
|
2026-05-30 22:44:55 -05:00
|
|
|
return { label: "Arch", icon: "cv-os-icon cv-os-icon-arch", tone: "pill-arch" };
|
2026-03-05 00:04:26 -06:00
|
|
|
if (os.includes("kali"))
|
2026-06-05 22:52:08 -05:00
|
|
|
return { label: "Kali", icon: "cv-os-icon cv-os-icon-kali", tone: "pill-kali" };
|
2026-03-05 00:04:26 -06:00
|
|
|
if (os.includes("fedora"))
|
2026-05-30 22:44:55 -05:00
|
|
|
return { label: "Fedora", icon: "fa-brands fa-fedora", tone: "pill-fedora" };
|
|
|
|
|
if (os.includes("red hat") || os.includes("rhel"))
|
|
|
|
|
return { label: "RHEL", icon: "fa-brands fa-redhat", tone: "pill-redhat" };
|
2026-06-05 22:52:08 -05:00
|
|
|
if (os.includes("rocky"))
|
|
|
|
|
return { label: "Rocky", icon: "cv-os-icon cv-os-icon-rocky", tone: "pill-rocky" };
|
|
|
|
|
if (os.includes("alma"))
|
|
|
|
|
return { label: "Alma", icon: "cv-os-icon cv-os-icon-alma", tone: "pill-alma" };
|
2026-05-30 22:44:55 -05:00
|
|
|
if (os.includes("centos"))
|
|
|
|
|
return { label: "CentOS", icon: "fa-brands fa-centos", tone: "pill-centos" };
|
2026-06-05 22:52:08 -05:00
|
|
|
if (os.includes("opensuse"))
|
|
|
|
|
return { label: "openSUSE", icon: "fa-brands fa-opensuse", tone: "pill-suse" };
|
|
|
|
|
if (os.includes("suse"))
|
2026-05-30 22:44:55 -05:00
|
|
|
return { label: "SUSE", icon: "fa-brands fa-suse", tone: "pill-suse" };
|
|
|
|
|
if (os.includes("raspbian") || os.includes("raspberry"))
|
|
|
|
|
return { label: "Raspberry Pi", icon: "fa-brands fa-raspberry-pi", tone: "pill-raspi" };
|
|
|
|
|
if (os.includes("freebsd"))
|
|
|
|
|
return { label: "FreeBSD", icon: "fa-brands fa-freebsd", tone: "pill-freebsd" };
|
2026-06-05 22:52:08 -05:00
|
|
|
if (os.includes("nixos") || os.includes("nix os"))
|
|
|
|
|
return { label: "NixOS", icon: "cv-os-icon cv-os-icon-nixos", tone: "pill-nixos" };
|
|
|
|
|
if (os.includes("gentoo"))
|
|
|
|
|
return { label: "Gentoo", icon: "cv-os-icon cv-os-icon-gentoo", tone: "pill-gentoo" };
|
2026-05-30 22:44:55 -05:00
|
|
|
if (os.includes("alpine"))
|
2026-06-05 22:52:08 -05:00
|
|
|
return { label: "Alpine", icon: "cv-os-icon cv-os-icon-alpine", tone: "pill-alpine" };
|
|
|
|
|
if (os.includes("android"))
|
|
|
|
|
return { label: "Android", icon: "fa-brands fa-android", tone: "pill-android" };
|
2026-03-05 00:04:26 -06:00
|
|
|
if (os.includes("linux"))
|
|
|
|
|
return { label: "Linux", icon: "fa-brands fa-linux", tone: "pill-linux" };
|
|
|
|
|
return base;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function archBadge(archRaw = "") {
|
|
|
|
|
const arch = archRaw.toLowerCase();
|
|
|
|
|
if (arch.includes("arm"))
|
|
|
|
|
return { label: archRaw || "ARM", icon: "fa-microchip", tone: "pill-arm" };
|
|
|
|
|
if (arch.includes("64") || arch.includes("x86") || arch.includes("amd"))
|
|
|
|
|
return { label: archRaw || "x64", icon: "fa-microchip", tone: "pill-x64" };
|
|
|
|
|
if (!archRaw)
|
|
|
|
|
return { label: "arch?", icon: "fa-microchip", tone: "pill-unknown" };
|
|
|
|
|
return { label: archRaw, icon: "fa-microchip", tone: "pill-ghost" };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function versionBadge(versionRaw = "") {
|
|
|
|
|
const label = versionRaw ? `v${versionRaw}` : "v0";
|
|
|
|
|
return {
|
|
|
|
|
label,
|
|
|
|
|
icon: "fa-tag",
|
|
|
|
|
tone: versionRaw ? "pill-version" : "pill-unknown",
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function monitorsBadge(count) {
|
|
|
|
|
const n = Number(count) || 1;
|
|
|
|
|
const label = `${n} monitor${n > 1 ? "s" : ""}`;
|
|
|
|
|
return { label, icon: "fa-display", tone: "pill-ghost" };
|
|
|
|
|
}
|