MCPcopy Create free account
hub / github.com/fontsource/fontsource / formatFileSize

Function formatFileSize

website/app/components/tools/utils.ts:1–11  ·  view source on GitHub ↗
(bytes: number)

Source from the content-addressed store, hash-verified

1export const formatFileSize = (bytes: number): string => {
2 if (bytes === 0) {
3 return '0 bytes';
4 }
5
6 const k = 1024;
7 const sizes = ['bytes', 'KB', 'MB', 'GB'];
8
9 const i = Math.floor(Math.log(bytes) / Math.log(k));
10 return `${Number.parseFloat((bytes / k ** i).toFixed(2))} ${sizes[i]}`;
11};

Callers 2

ResultsTableFunction · 0.90
FileListFunction · 0.90

Calls 1

logMethod · 0.80

Tested by

no test coverage detected