mirror of
https://github.com/streamyfin/streamyfin.git
synced 2025-08-20 18:37:18 +02:00
9 lines
350 B
TypeScript
9 lines
350 B
TypeScript
export const formatBitrate = (bitrate?: number | null) => {
|
|
if (!bitrate) return "N/A";
|
|
|
|
const sizes = ["bps", "Kbps", "Mbps", "Gbps", "Tbps"];
|
|
if (bitrate === 0) return "0 bps";
|
|
const i = parseInt(Math.floor(Math.log(bitrate) / Math.log(1000)).toString());
|
|
return Math.round((bitrate / Math.pow(1000, i)) * 100) / 100 + " " + sizes[i];
|
|
};
|