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

Switch to common units in humanFileSize

parent d5bcf57b
Branches
No related tags found
No related merge requests found
...@@ -28,14 +28,12 @@ export function numberFormat(i18n, number, options) { ...@@ -28,14 +28,12 @@ export function numberFormat(i18n, number, options) {
return new Intl.NumberFormat(i18n.languages, options).format(number); return new Intl.NumberFormat(i18n.languages, options).format(number);
} }
export function humanFileSize(bytes, si) { export function humanFileSize(bytes, si = false) {
const thresh = si ? 1000 : 1024; const thresh = si ? 1000 : 1024;
if(Math.abs(bytes) < thresh) { if(Math.abs(bytes) < thresh) {
return bytes + ' B'; return bytes + ' B';
} }
const units = si const units = ['kB','MB','GB','TB','PB','EB','ZB','YB'];
? ['kB','MB','GB','TB','PB','EB','ZB','YB']
: ['KiB','MiB','GiB','TiB','PiB','EiB','ZiB','YiB'];
let u = -1; let u = -1;
do { do {
bytes /= thresh; bytes /= thresh;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment