Skip to content

Instantly share code, notes, and snippets.

@rockydd
Forked from anonymous/nubToBytes
Last active August 29, 2015 14:20
Show Gist options
  • Save rockydd/2ca18f239e289167719c to your computer and use it in GitHub Desktop.
Save rockydd/2ca18f239e289167719c to your computer and use it in GitHub Desktop.
Object.defineProperty(Number.prototype,'fileSize',{value:function(a,b,c,d){
if(this == 0){
return "0.0 B";
}else if(this < 0.001){
return this.toExponential(1) + " B";
}else if(this < 1){
return this.toLocaleString() + " B";
}
return (a=a?[1e3,'k','B']:[1024,'K','iB'],b=Math,c=b.log,
d=c(this)/c(a[0])|0,this/b.pow(a[0],d)).toFixed(1)
+' '+(d?(a[1]+'MGTPEZY')[--d]+a[2]:'B');
},writable:false,enumerable:false});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment