File tree Expand file tree Collapse file tree 2 files changed +30
-2
lines changed Expand file tree Collapse file tree 2 files changed +30
-2
lines changed Original file line number Diff line number Diff line change 22
33import { Button } from '@/components/ui/button'
44import { GitHubIcon } from '@/components/icons/github-icon'
5+ import { formatAbbreviatedNumber } from '@/lib/utils/format-number'
56
67const GITHUB_REPO_URL = 'https://github.com/vercel-labs/coding-agent-template'
78
89interface GitHubStarsButtonProps {
910 initialStars ?: number
1011}
1112
12- export function GitHubStarsButton ( { initialStars = 1056 } : GitHubStarsButtonProps ) {
13+ export function GitHubStarsButton ( { initialStars = 1100 } : GitHubStarsButtonProps ) {
1314 return (
1415 < Button asChild variant = "ghost" size = "sm" className = "h-8 px-2 sm:px-3 gap-1.5" >
1516 < a href = { GITHUB_REPO_URL } target = "_blank" rel = "noopener noreferrer" className = "flex items-center" >
1617 < GitHubIcon className = "h-3.5 w-3.5" />
17- < span className = "text-sm" > { initialStars . toLocaleString ( ) } </ span >
18+ < span className = "text-sm" > { formatAbbreviatedNumber ( initialStars ) } </ span >
1819 </ a >
1920 </ Button >
2021 )
Original file line number Diff line number Diff line change 1+ /**
2+ * Formats a number into an abbreviated form (e.g., 1.1k, 2.5M)
3+ *
4+ * @param num - The number to format
5+ * @returns The formatted string
6+ *
7+ * @example
8+ * formatAbbreviatedNumber(1109) // "1.1k"
9+ * formatAbbreviatedNumber(1500) // "1.5k"
10+ * formatAbbreviatedNumber(1000000) // "1M"
11+ * formatAbbreviatedNumber(500) // "500"
12+ */
13+ export function formatAbbreviatedNumber ( num : number ) : string {
14+ if ( num >= 1000000 ) {
15+ const formatted = ( num / 1000000 ) . toFixed ( 1 )
16+ // Remove .0 if present
17+ return formatted . endsWith ( '.0' ) ? `${ Math . floor ( num / 1000000 ) } M` : `${ formatted } M`
18+ }
19+
20+ if ( num >= 1000 ) {
21+ const formatted = ( num / 1000 ) . toFixed ( 1 )
22+ // Remove .0 if present
23+ return formatted . endsWith ( '.0' ) ? `${ Math . floor ( num / 1000 ) } k` : `${ formatted } k`
24+ }
25+
26+ return num . toString ( )
27+ }
You can’t perform that action at this time.
0 commit comments