2017-09-07 08:19:11 +02:00
|
|
|
export const Rates = {
|
|
|
|
"b/s": Math.pow(1024, 0),
|
|
|
|
"KiB/s": Math.pow(1024, 1),
|
|
|
|
"MiB/s": Math.pow(1024, 2),
|
|
|
|
"GiB/s": Math.pow(1024, 3),
|
|
|
|
"TiB/s": Math.pow(1024, 4),
|
|
|
|
};
|
|
|
|
|
|
|
|
export function convertToBitrate(value, unit) {
|
|
|
|
return value * Rates[unit];
|
|
|
|
}
|
|
|
|
|
2017-08-25 04:49:24 +02:00
|
|
|
export function formatBitrate(bitrate) {
|
2017-09-07 08:19:11 +02:00
|
|
|
if (bitrate > Rates["GiB/s"]) {
|
|
|
|
return `${(bitrate / Rates["GiB/s"]).toFixed(2)} GiB/s`;
|
|
|
|
} else if (bitrate > Rates["MiB/s"]) {
|
|
|
|
return `${(bitrate / Rates["MiB/s"]).toFixed(2)} MiB/s`;
|
|
|
|
} else if (bitrate > Rates["KiB/s"]) {
|
|
|
|
return `${(bitrate / Rates["KiB/s"]).toFixed(2)} KiB/s`;
|
2017-08-25 04:49:24 +02:00
|
|
|
} else {
|
|
|
|
return `${bitrate} b/s`;
|
|
|
|
}
|
|
|
|
}
|