HTML 77.2%
TypeScript 10.5%
Python 9.6%
JavaScript 2.5%
1import { fmtInt, num } from '@/lib/format';2import type { EntitySummary } from '@/lib/types';34/* Hardware helpers shared by /hardware, /hardware/frontier and /hardware/[slug]. Attributes are read as published; nothing is inferred. */56export const HW_KINDS = ['gpu', 'accelerator', 'npu', 'cpu', 'soc', 'system', 'server', 'workstation', 'cloud-instance'] as const;7export const HW_KIND_LABELS: Record<string, string> = { gpu: 'GPU', accelerator: 'Accelerator', npu: 'NPU', cpu: 'CPU', soc: 'SoC', system: 'System', server: 'Server', workstation: 'Workstation', 'cloud-instance': 'Cloud instance', computer: 'Computer' };89/** memory_gb may be a number or a list of configurations → [min, max] or null. */10export function memoryRange(v: unknown): [number, number] | null {11 if (Array.isArray(v)) {12 const xs = v.map(num).filter((x): x is number => x !== null);13 return xs.length ? [Math.min(...xs), Math.max(...xs)] : null;14 }15 const n = num(v);16 return n === null ? null : [n, n];17}18export function memoryOptions(v: unknown): number[] {19 if (Array.isArray(v)) return v.map(num).filter((x): x is number => x !== null).sort((a, b) => a - b);20 const n = num(v);21 return n === null ? [] : [n];22}23export function fmtMemory(v: unknown): string {24 const r = memoryRange(v);25 if (!r) return '—';26 return r[0] === r[1] ? `${fmtInt(r[0])} GB` : `${fmtInt(r[0])}–${fmtInt(r[1])} GB`;27}28export function str(v: unknown): string | null {29 return typeof v === 'string' && v.trim() ? v : null;30}31export function list(v: unknown): string[] {32 return Array.isArray(v) ? v.filter((x) => x !== null && x !== undefined).map(String) : [];33}34/** Precision support as published (`precision_support`, `precisions`, `supported_precisions`, `dtypes`). */35export function precisions(a: Record<string, unknown>): string[] {36 for (const k of ['precision_support', 'precisions', 'supported_precisions', 'dtypes']) {37 const l = list(a[k]);38 if (l.length) return l;39 }40 return [];41}42export function interconnect(a: Record<string, unknown>): string | null {43 for (const k of ['interconnect', 'interconnect_bandwidth_gbs', 'nvlink_bandwidth_gbs', 'fabric']) {44 const v = a[k];45 if (typeof v === 'string' && v.trim()) return v;46 if (num(v) !== null) return `${fmtInt(v)} GB/s`;47 }48 return null;49}50export function releaseOf(e: EntitySummary): string | null {51 return str(e.attributes?.release_date) ?? str(e.attributes?.announced_at) ?? null;52}53/** Sort key for a release: "2024", "2024-10" or full date → ms; null when absent. */54export function releaseMs(r: string | null): number | null {55 if (!r) return null;56 const t = new Date(r.length === 4 ? `${r}-07-01T00:00:00Z` : r.length === 7 ? `${r}-15T00:00:00Z` : r.length === 10 ? `${r}T00:00:00Z` : r).getTime();57 return Number.isNaN(t) ? null : t;58}59