JavaScript Convert size in bytes

function bytesToSize(bytes) { var sizes = [ n/a, bytes, KiB, MiB, GiB, TiB, PiB, EiB, ZiB, YiB]; var i = +Math.floor(Math.log(bytes) / Math.log(1024)); return (bytes / Math.pow(1024, i)).toFixed( i ? 1 : 0 ) + ' ' + sizes[ isNaN(bytes) ? 0 : i+1 ];}