Meta 5ba5058c70
Feature: show process name and path in connections page (#95)
Co-authored-by: MetaCubeX <maze.y2b@github.com>
2022-04-22 18:28:22 +08:00

24 lines
697 B
TypeScript

import { floor } from 'lodash-es'
// eslint-disable-next-line @typescript-eslint/no-empty-function
export function noop () {}
export function partition<T> (arr: T[], fn: (arg: T) => boolean): [T[], T[]] {
const left: T[] = []
const right: T[] = []
for (const item of arr) {
fn(item) ? left.push(item) : right.push(item)
}
return [left, right]
}
export function formatTraffic (num: number) {
const s = ['B', 'KB', 'MB', 'GB', 'TB']
const exp = Math.floor(Math.log(num || 1) / Math.log(1024))
return `${floor(num / Math.pow(1024, exp), 2).toFixed(2)} ${s?.[exp] ?? ''}`
}
export function basePath (path: string) {
return path.replace(/.*[/\\]/, '')
}