From 761d3aebdb5b985861cc3f2ed680e815c6a55feb Mon Sep 17 00:00:00 2001 From: dangered wolf Date: Sun, 7 Jan 2024 02:25:51 -0500 Subject: [PATCH] Tweak social proof number formatting --- src/helpers/socialproof.ts | 8 ++++---- src/helpers/utils.ts | 12 +++++++++--- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/helpers/socialproof.ts b/src/helpers/socialproof.ts index ecb0a13..7e74c41 100644 --- a/src/helpers/socialproof.ts +++ b/src/helpers/socialproof.ts @@ -11,16 +11,16 @@ export const getSocialProof = (status: APITwitterStatus): string | null => { ) { let authorText = ''; if (status.replies > 0) { - authorText += `${formatNumber(status.replies)} 💬 `; + authorText += `💬 ${formatNumber(status.replies)} `; } if (status.reposts > 0) { - authorText += `${formatNumber(status.reposts)} 🔁 `; + authorText += `🔁 ${formatNumber(status.reposts)} `; } if (status.likes > 0) { - authorText += `${formatNumber(status.likes)} ❤️ `; + authorText += `❤️ ${formatNumber(status.likes)} `; } if (status.views && status.views > 0) { - authorText += `${formatNumber(status.views)} 👁️ `; + authorText += `👁️ ${formatNumber(status.views)} `; } authorText = authorText.trim(); diff --git a/src/helpers/utils.ts b/src/helpers/utils.ts index 4602e85..7827bbf 100644 --- a/src/helpers/utils.ts +++ b/src/helpers/utils.ts @@ -57,6 +57,12 @@ export async function withTimeout( } } -const numberFormat = new Intl.NumberFormat('en-US'); - -export const formatNumber = (num: number) => numberFormat.format(num); +export const formatNumber = (num: number) => { + if (num >= 1e6) { + return (num / 1e6).toFixed(2) + 'M'; + } else if (num >= 1e3) { + return (num / 1e3).toFixed(1) + 'K'; + } else { + return num.toString(); + } +}; \ No newline at end of file