Tweak social proof number formatting

This commit is contained in:
dangered wolf 2024-01-07 02:25:51 -05:00
parent 5a767f0a6d
commit 761d3aebdb
No known key found for this signature in database
GPG key ID: 41E4D37680ED8B58
2 changed files with 13 additions and 7 deletions

View file

@ -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();

View file

@ -57,6 +57,12 @@ export async function withTimeout<T>(
}
}
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();
}
};