Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions apps/web/src/components/chat/DiffStatLabel.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { describe, expect, it } from "vite-plus/test";

import { formatCompactDiffCount } from "./DiffStatLabel";

describe("formatCompactDiffCount", () => {
it("promotes counts when rounding reaches the next suffix", () => {
expect(formatCompactDiffCount(999_499)).toBe("999k");
expect(formatCompactDiffCount(999_500)).toBe("1m");
expect(formatCompactDiffCount(999_499_999)).toBe("999m");
expect(formatCompactDiffCount(999_500_000)).toBe("1b");
});
});
6 changes: 3 additions & 3 deletions apps/web/src/components/chat/DiffStatLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ export function hasNonZeroStat(stat: { additions: number; deletions: number }):
return stat.additions > 0 || stat.deletions > 0;
}

function formatCompactDiffCount(value: number): string {
export function formatCompactDiffCount(value: number): string {
if (value < 1000) return String(value);
if (value < 1_000_000) {
if (value < 999_500) {
const k = value / 1000;
return `${k < 10 ? k.toFixed(1).replace(/\.0$/, "") : Math.round(k)}k`;
}
if (value < 1_000_000_000) {
if (value < 999_500_000) {
const m = value / 1_000_000;
return `${m < 10 ? m.toFixed(1).replace(/\.0$/, "") : Math.round(m)}m`;
}
Expand Down
Loading