MCPcopy Create free account
hub / github.com/APIParkLab/APIPark / formatBytes

Function formatBytes

frontend/packages/dashboard/src/utils/dashboard.ts:182–202  ·  view source on GitHub ↗
(bytes: number)

Source from the content-addressed store, hash-verified

180 * @returns 格式化后的字符串,包含单位
181 */
182export function formatBytes(bytes: number) {
183 const KB = 1000 // 千字节
184 const MB = KB * 1000 // 兆字节
185 const GB = MB * 1000 // 吉字节
186 const TB = GB * 1000 // 太字节
187 const PB = TB * 1000 // 拉字节
188
189 if (bytes < KB) {
190 return `${bytes}B` // 直接显示字节
191 } else if (bytes < MB) {
192 return (bytes / KB).toFixed(1) + 'KB' // 转换为千字节
193 } else if (bytes < GB) {
194 return (bytes / MB).toFixed(1) + 'MB' // 转换为兆字节
195 } else if (bytes < TB) {
196 return (bytes / GB).toFixed(1) + 'GB' // 转换为吉字节
197 } else if (bytes < PB) {
198 return (bytes / TB).toFixed(1) + 'TB' // 转换为太字节
199 } else {
200 return (bytes / PB).toFixed(1) + 'PB' // 转换为拉字节
201 }
202}

Callers 2

setRestChartInfoDataFunction · 0.90
setRestChartInfoDataFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected