feat: finish main layout

This commit is contained in:
GyDi
2021-12-08 23:36:34 +08:00
parent efc1669b3e
commit a1e99e5303
13 changed files with 273 additions and 92 deletions

View File

@@ -0,0 +1,23 @@
const parseTraffic = (num: number) => {
const gb = 1024 ** 3;
const mb = 1024 ** 2;
const kb = 1024;
let t = num;
let u = "B";
if (num < 1000) return [`${Math.round(t)}`, "B/s"];
if (num <= mb) {
t = num / kb;
u = "KB";
} else if (num <= gb) {
t = num / mb;
u = "MB";
} else {
t = num / gb;
u = "GB";
}
if (t >= 100) return [`${Math.round(t)}`, `${u}/s`];
return [`${Math.round(t * 10) / 10}`, `${u}/s`];
};
export default parseTraffic;