mirror of
https://github.com/CompeyDev/fxtwitter-docker.git
synced 2025-04-05 02:20:54 +01:00
Tweak social proof number formatting
This commit is contained in:
parent
5a767f0a6d
commit
761d3aebdb
2 changed files with 13 additions and 7 deletions
|
@ -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();
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
};
|
Loading…
Add table
Reference in a new issue