forked from Ninjalama/streamyfin_mirror
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>
12 lines
366 B
TypeScript
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]}`;
|
|
};
|