diff --git a/docs/app/community/_components/stats.tsx b/docs/app/community/_components/stats.tsx index 5b091ccb..e15c66e0 100644 --- a/docs/app/community/_components/stats.tsx +++ b/docs/app/community/_components/stats.tsx @@ -52,7 +52,7 @@ export default function Stats({ npmDownloads }: { npmDownloads: number }) {
- {parseInt(kFormatter(npmDownloads) as string)}k+ + {kFormatter(npmDownloads) as string}
diff --git a/docs/lib/utils.ts b/docs/lib/utils.ts index 2388e35e..03c9f340 100644 --- a/docs/lib/utils.ts +++ b/docs/lib/utils.ts @@ -9,9 +9,17 @@ export function absoluteUrl(path: string) { return `${process.env.NEXT_PUBLIC_APP_URL}${path}`; } export function kFormatter(num: number) { - return Math.abs(num) > 999 - ? Math.sign(num) * parseFloat((Math.abs(num) / 1000).toFixed(1)) + "k" - : Math.sign(num) * Math.abs(num); + const absNum = Math.abs(num); + const sign = Math.sign(num); + + if (absNum >= 1000000000) { + return sign * parseFloat((absNum / 1000000000).toFixed(1)) + "B+"; + } else if (absNum >= 1000000) { + return sign * parseFloat((absNum / 1000000).toFixed(1)) + "M+"; + } else if (absNum >= 1000) { + return sign * parseFloat((absNum / 1000).toFixed(1)) + "K+"; + } + return sign * absNum; } export const baseUrl =