import { lang, t } from "./i18n.ts"; import type { Listing } from "./verify.ts"; /** The line under the title: what the node holds and follows. */ export function statusLine(n: { listings: number; peers: number; regions: string[] }): string { return t("status.line", { listings: n.listings, peers: n.peers, regions: n.regions.length ? n.regions.join(", ") : t("status.noRegions"), }); } export function money(cents: number): string { return new Intl.NumberFormat(lang, { style: "currency", currency: "EUR" }).format(cents / 100); } /** rooms_x2 stores rooms * 2, so 2.5 rooms are 5. */ export function rooms(x2: number): string { return t("card.rooms", { n: (x2 / 2).toLocaleString(lang, { maximumFractionDigits: 1 }) }); } export function date(unix: number): string { return new Date(unix * 1000).toLocaleDateString(lang, { dateStyle: "medium" }); } /** A time of day for today's events, otherwise the day. */ export function when(unix: number): string { const d = new Date(unix * 1000); if (d.toDateString() === new Date(Date.now()).toDateString()) { return d.toLocaleTimeString(lang, { hour: "2-digit", minute: "2-digit" }); } return d.toLocaleDateString(lang, { day: "numeric", month: "short" }); } export function price(l: Listing): string { if (!l.price) return ""; const base = money(l.price.amount_cents); return l.price.period === "month" ? `${base} ${t("card.perMonth")}` : base; } /** A key shortened for display: abcd1234…9f2e */ export function shortKey(hex: string): string { return hex.length > 16 ? `${hex.slice(0, 8)}…${hex.slice(-4)}` : hex; }