trc-client-core
Version:
The core of the TRC Client
14 lines (13 loc) • 338 B
JSX
export default function HumanFileSize(bytes) {
var thresh = 1000;
if (bytes < thresh) {
return bytes + ' B';
}
var units = ['kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
var u = -1;
do {
bytes /= thresh;
++u;
} while(bytes >= thresh);
return bytes.toFixed(1) + ' ' + units[u];
}