MCPcopy Create free account
hub / github.com/xerrors/Yuxi / formatFileSize

Function formatFileSize

web/src/utils/file_utils.js:22–29  ·  view source on GitHub ↗
(bytes)

Source from the content-addressed store, hash-verified

20}
21
22export const formatFileSize = (bytes) => {
23 if (bytes === 0 || bytes === '0') return '0 B'
24 if (!bytes) return '-'
25 const k = 1024
26 const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
27 const i = Math.floor(Math.log(bytes) / Math.log(k))
28 return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i]
29}
30
31export const getDisplayFileName = (pathOrName, fallback = '文件') => {
32 const value = String(pathOrName || '').trim()

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected