Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
fix: star count shouldn't round down near the next thousand
theluckystrikee8d9d094f3aa
diff --git a/apps/web/__tests__/unit/github-star-count.test.ts b/apps/web/__tests__/unit/github-star-count.test.tsnew file mode 100644index 000000000..afe17eb0a--- /dev/null+++ b/apps/web/__tests__/unit/github-star-count.test.ts@@ -0,0 +1,26 @@+import { describe, expect, it } from "vitest";+import { formatStarCount } from "@/utils/github";++describe("formatStarCount", () => {+ it("returns an empty string when the count is unavailable", () => {+ expect(formatStarCount(0)).toBe("");+ });++ it("returns counts below 1000 unchanged", () => {+ expect(formatStarCount(999)).toBe("999");+ });++ it("formats thousands with one decimal place", () => {+ expect(formatStarCount(16_420)).toBe("16.4k");+ });++ it("drops a trailing .0", () => {+ expect(formatStarCount(16_000)).toBe("16k");+ expect(formatStarCount(16_049)).toBe("16k");+ });++ it("rounds up to the next whole thousand", () => {+ expect(formatStarCount(16_960)).toBe("17k");+ expect(formatStarCount(19_999)).toBe("20k");+ });+});diff --git a/apps/web/utils/github.ts b/apps/web/utils/github.tsindex 6da86af44..1bdbf890d 100644--- a/apps/web/utils/github.ts+++ b/apps/web/utils/github.ts@@ -25,9 +25,7 @@ export function formatStarCount(count: number): string {if (count === 0) return "";if (count >= 1000) {const formatted = (count / 1000).toFixed(1);- return formatted.endsWith(".0")- ? `${Math.floor(count / 1000)}k`- : `${formatted}k`;+ return `${formatted.replace(/\.0$/, "")}k`;}return count.toString();}