mirror of
https://github.com/thelounge/thelounge.git
synced 2024-05-29 03:42:20 +02:00
12 lines
361 B
TypeScript
12 lines
361 B
TypeScript
export default (count: number) => {
|
|
if (count < 1000) {
|
|
return count.toString();
|
|
}
|
|
|
|
const suffixes = ["", "k", "M"];
|
|
const magnitudeIndex = Math.min(Math.floor(Math.log10(count) / 3), suffixes.length - 1);
|
|
const magnitude = 1000 ** magnitudeIndex;
|
|
const roundedCount = (count / magnitude).toFixed(1);
|
|
return roundedCount + suffixes[magnitudeIndex];
|
|
};
|