Files
streamyfin_mirror/utils/bitrate.ts
renovate[bot] a146fc8810 chore(deps): update dependency @biomejs/biome to v2.2.0 (#934)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Uruk <contact@uruk.dev>
Co-authored-by: Gauvain <68083474+Gauvino@users.noreply.github.com>
2025-08-18 23:00:33 +02:00

12 lines
366 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 = Number.parseInt(
Math.floor(Math.log(bitrate) / Math.log(1000)).toString(),
10,
);
return `${Math.round((bitrate / 1000 ** i) * 100) / 100} ${sizes[i]}`;
};