feat: remove sec field

This commit is contained in:
GyDi
2021-12-17 00:39:55 +08:00
parent f736951fc8
commit 8d7ef0dc94
2 changed files with 12 additions and 5 deletions

View File

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