MCPcopy Create free account
hub / github.com/DavidWells/analytics / formatBytes

Function formatBytes

scripts/getSize.js:21–32  ·  view source on GitHub ↗
(bytes, decimals = 2)

Source from the content-addressed store, hash-verified

19}
20
21function formatBytes(bytes, decimals = 2) {
22 if (bytes === 0) return '0 Bytes';
23
24 const k = 1024;
25 const dm = decimals < 0 ? 0 : decimals;
26 const sizes = ['bytes', 'kb', 'mb', 'gb', 'tb', 'pb'];
27
28 const i = Math.floor(Math.log(bytes) / Math.log(k));
29 const type = sizes[i]
30 const space = type === 'bytes' ? ' ' : ''
31 return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + space + type;
32}
33
34async function getSizeInfo(code, filename) {
35 const raw = code.length < 5000

Callers 1

getSizeInfoFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected