MCPcopy Create free account
hub / github.com/ZenNotes/zennotes / formatBytes

Function formatBytes

packages/app-core/src/components/AssetsView.tsx:12–22  ·  view source on GitHub ↗
(bytes: number)

Source from the content-addressed store, hash-verified

10import { DocumentIcon, ImageIcon, PaperclipIcon, SearchIcon, TrashIcon } from './icons'
11
12function formatBytes(bytes: number): string {
13 if (bytes < 1024) return `${bytes} B`
14 const units = ['KB', 'MB', 'GB']
15 let value = bytes / 1024
16 let unit = 0
17 while (value >= 1024 && unit < units.length - 1) {
18 value /= 1024
19 unit++
20 }
21 return `${value.toFixed(value >= 10 || unit === 0 ? 0 : 1)} ${units[unit]}`
22}
23
24function formatDate(ms: number): string {
25 const d = new Date(ms)

Callers 1

AssetsViewFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected