Nodejs Utililty Methods Size Format

List of utility methods to do Size Format

Description

The list of methods to do Size Format are organized into topic(s).

Method

formatSize(bytes)
function formatSize(bytes) {
  if (bytes > 1024*1024*1024) {
    return Math.round(bytes/1024/1024/1024*100)/100+"GB";
  if (bytes > 1024*1024) {
    return Math.round(bytes/1024/1024*10)/10+"MB";
  if (bytes > 1024) {
    return Math.round(bytes/1024)+"KB";
...
formatSizeUnits(bytes)
function formatSizeUnits(bytes){
     if(bytes == 0) 
        return '0 Bytes';
     var k = 1000,dm = 2,sizes = ['B', 'kB', 'MB', 'GB', 'TB'],
         i = Math.floor(Math.log(bytes) / Math.log(k));
     return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
};
String.prototype.UCFirst = function() {return this.charAt(0).toUpperCase() + this.slice(1);};