feat: abbreviate likes in mii list component

This commit is contained in:
trafficlunar 2025-04-14 18:41:22 +01:00
parent 6b1cfff9c6
commit 75bd7281e4
3 changed files with 16 additions and 4 deletions

10
src/lib/abbreviation.ts Normal file
View file

@ -0,0 +1,10 @@
export function abbreviateNumber(number: number): string {
if (number < 1000) return number.toString();
const units = ["", "K", "M", "B", "T"]; // very unlikely to go into thousands, let alone millions, but you never know
const order = Math.floor(Math.log10(number) / 3);
const unit = units[order] || "";
const scaled = number / Math.pow(10, order * 3);
return `${scaled.toFixed(scaled < 10 ? 1 : 0)}${unit}`;
}