MCPcopy Index your code
hub / github.com/nodejs/node / formatBytes

Function formatBytes

deps/npm/lib/utils/format-bytes.js:4–27  ·  view source on GitHub ↗
(bytes, space = true)

Source from the content-addressed store, hash-verified

2// Only supports up to GB because that's way larger than anything the registry supports anyways.
3
4const formatBytes = (bytes, space = true) => {
5 let spacer = ''
6 if (space) {
7 spacer = ' '
8 }
9
10 if (bytes < 1000) {
11 // B
12 return `${bytes}${spacer}B`
13 }
14
15 if (bytes < 999950) {
16 // kB
17 return `${(bytes / 1000).toFixed(1)}${spacer}kB`
18 }
19
20 if (bytes < 999950000) {
21 // MB
22 return `${(bytes / 1000000).toFixed(1)}${spacer}MB`
23 }
24
25 // GB
26 return `${(bytes / 1000000000).toFixed(1)}${spacer}GB`
27}
28
29module.exports = formatBytes

Callers 2

logTarFunction · 0.70
#prettyViewMethod · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…