Skip to content
Snippets Groups Projects
Commit d5bcf57b authored by Bekerle, Patrizio's avatar Bekerle, Patrizio :fire: Committed by Reiter, Christoph
Browse files

Add function humanFileSize

parent b6fb8055
No related branches found
No related tags found
No related merge requests found
......@@ -28,6 +28,22 @@ export function numberFormat(i18n, number, options) {
return new Intl.NumberFormat(i18n.languages, options).format(number);
}
export function humanFileSize(bytes, si) {
const thresh = si ? 1000 : 1024;
if(Math.abs(bytes) < thresh) {
return bytes + ' B';
}
const units = si
? ['kB','MB','GB','TB','PB','EB','ZB','YB']
: ['KiB','MiB','GiB','TiB','PiB','EiB','ZiB','YiB'];
let u = -1;
do {
bytes /= thresh;
++u;
} while(Math.abs(bytes) >= thresh && u < units.length - 1);
return bytes.toFixed(1)+' '+units[u];
}
/**
* Creates a new i18next instance that is fully initialized.
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment