From 503dfb18fa887816064b23a55a19756517ac2944 Mon Sep 17 00:00:00 2001 From: Ayush A Sri <66489925+ayushdoesdev@users.noreply.github.com> Date: Sun, 8 Nov 2026 12:32:34 +0530 Subject: [PATCH 1/2] Handle non-finite values in compact number formatting --- frontend/src/lib/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/lib/utils.ts b/frontend/src/lib/utils.ts index 15f08ef..f077955 100644 --- a/frontend/src/lib/utils.ts +++ b/frontend/src/lib/utils.ts @@ -6,7 +6,7 @@ export function cn(...inputs: ClassValue[]) { } export function formatNumber(n: number | null | undefined): string { - if (n == null) return "—"; + if (n == null || !Number.isFinite(n)) return "—"; return new Intl.NumberFormat("en-US", { notation: "compact" }).format(n); } From 266d97e7caeca8c56f63d1e8293ab95f71d3d0fc Mon Sep 17 00:00:00 2001 From: Ayush A Sri <66489925+ayushdoesdev@users.noreply.github.com> Date: Sun, 8 Nov 2026 12:32:37 +0530 Subject: [PATCH 2/2] Test compact number formatting edge cases --- frontend/src/lib/utils.test.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/frontend/src/lib/utils.test.ts b/frontend/src/lib/utils.test.ts index 3fe64fb..7906be6 100644 --- a/frontend/src/lib/utils.test.ts +++ b/frontend/src/lib/utils.test.ts @@ -1,11 +1,22 @@ import { describe, expect, it } from "vitest"; -import { cn, formatScore, statusBadge } from "@/lib/utils"; +import { cn, formatNumber, formatScore, statusBadge } from "@/lib/utils"; describe("utils", () => { it("merges class names", () => { expect(cn("px-2", "px-4")).toContain("px-4"); }); + it("formats finite numbers compactly and handles invalid values", () => { + expect(formatNumber(1200)).toBe("1.2K"); + expect(formatNumber(0)).toBe("0"); + expect(formatNumber(-1200)).toBe("-1.2K"); + expect(formatNumber(null)).toBe("—"); + expect(formatNumber(undefined)).toBe("—"); + expect(formatNumber(Number.NaN)).toBe("—"); + expect(formatNumber(Number.POSITIVE_INFINITY)).toBe("—"); + expect(formatNumber(Number.NEGATIVE_INFINITY)).toBe("—"); + }); + it("formats scores", () => { expect(formatScore(87.4)).toBe("87"); expect(formatScore(null)).toBe("—");