Skip to content

Instantly share code, notes, and snippets.

@NickyYo
Created April 30, 2018 10:46

Revisions

  1. NickyYo created this gist Apr 30, 2018.
    6 changes: 6 additions & 0 deletions bytesToSize.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    bytesToSize(bytes: any) {
    var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
    if (bytes == 0) return '0 Byte';
    var i = Math.floor(Math.log(bytes) / Math.log(1024));
    return Math.round(bytes / Math.pow(1024, i)) + ' ' + sizes[i];
    };