Skip to content

Instantly share code, notes, and snippets.

@mholtzhausen
Created November 26, 2019 12:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mholtzhausen/0c7b3641cbc7e007613989be5959cbf1 to your computer and use it in GitHub Desktop.
Save mholtzhausen/0c7b3641cbc7e007613989be5959cbf1 to your computer and use it in GitHub Desktop.
Bytes represented in human readable form
module.exports = (bytes, siUnits = false, m, l, d, e) => (m = Math, l = m.log, d = siUnits ? 1024 : 1e3, e = l(bytes) / l(d) | 0, `${bytes / m.pow(d, e).toFixed(2)} ${e ? `${'KMGTPEZY'[--e]}${siUnits ? 'iB' : 'B'}` : 'Bytes'}`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment