add speedtest-tracker integration

This commit is contained in:
Ben Phelps 2022-08-27 03:50:49 +03:00
parent 0076701091
commit ac718c852a
4 changed files with 55 additions and 1 deletions

View file

@ -21,3 +21,15 @@ export function formatBytes(bytes, decimals = 2) {
return parseFloat(bytes / Math.pow(k, i)).toFixed(dm) + " " + sizes[i];
}
export function formatBits(bytes, decimals = 2) {
if (bytes === 0) return "0 Bytes";
const k = 1024;
const dm = decimals < 0 ? 0 : decimals;
const sizes = ["B", "Kb", "Mb", "Gb", "Tb", "Pb", "Eb", "Zb", "Yb"];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat(bytes / Math.pow(k, i)).toFixed(dm) + " " + sizes[i];
}