feat: supports show connection detail

This commit is contained in:
GyDi
2023-08-05 16:52:14 +08:00
parent ab6374e278
commit 54e491d8bf
6 changed files with 173 additions and 176 deletions

View File

@@ -1,6 +1,7 @@
const UNITS = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
const parseTraffic = (num: number) => {
const parseTraffic = (num?: number) => {
if (typeof num !== "number") return ["NaN", ""];
if (num < 1000) return [`${Math.round(num)}`, "B"];
const exp = Math.min(Math.floor(Math.log2(num) / 10), UNITS.length - 1);
const dat = num / Math.pow(1024, exp);

View File

@@ -0,0 +1,6 @@
export const truncateStr = (str?: string, prefixLen = 16, maxLen = 56) => {
if (!str || str.length <= maxLen) return str;
return (
str.slice(0, prefixLen) + " ... " + str.slice(-(maxLen - prefixLen - 5))
);
};