Created
March 7, 2020 20:36
-
-
Save xargr/33e55c66e5ba33f0b512558b0ab2f3e6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const bytesToSize = bytes => { | |
var sizes = ["Bytes", "KB", "MB", "GB", "TB"]; | |
if (bytes == 0) return "0 Byte"; | |
var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024))); | |
return Math.round(bytes / Math.pow(1024, i), 2) + " " + sizes[i]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment