MCPcopy Index your code
hub / github.com/code-pushup/cli / formatBytes

Function formatBytes

packages/utils/src/lib/formatting.ts:42–57  ·  view source on GitHub ↗
(bytes: number, decimals = 2)

Source from the content-addressed store, hash-verified

40}
41
42export function formatBytes(bytes: number, decimals = 2) {
43 const positiveBytes = Math.max(bytes, 0);
44
45 // early exit
46 if (positiveBytes === 0) {
47 return '0 B';
48 }
49
50 const k = 1024;
51 const dm = Math.max(decimals, 0);
52 const sizes = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
53
54 const i = Math.floor(Math.log(positiveBytes) / Math.log(k));
55
56 return `${roundDecimals(positiveBytes / Math.pow(k, i), dm)} ${sizes[i]}`;
57}
58
59export function pluralizeToken(token: string, times: number): string {
60 return `${times} ${Math.abs(times) === 1 ? token : pluralize(token)}`;

Callers 10

logPersistedReportFunction · 0.90
parseOpportunityEntryFunction · 0.90
longestChainToTableFunction · 0.90
chainToTreeNodeFunction · 0.90
infoMessageFunction · 0.90
errorMessageFunction · 0.90

Calls 1

roundDecimalsFunction · 0.85

Tested by

no test coverage detected