Merge branch 'poljar/seshat-ui-pr' into develop

This commit is contained in:
Damir Jelić 2020-01-27 17:18:17 +01:00
commit e2dd2bd950
13 changed files with 672 additions and 61 deletions

View file

@ -30,6 +30,31 @@ export function formatCount(count) {
return (count / 1000000000).toFixed(1) + "B"; // 10B is enough for anyone, right? :S
}
/**
* Format a count showing the whole number but making it a bit more readable.
* e.g: 1000 => 1,000
*/
export function formatCountLong(count) {
const formatter = new Intl.NumberFormat();
return formatter.format(count)
}
/**
* format a size in bytes into a human readable form
* e.g: 1024 -> 1.00 KB
*/
export function formatBytes(bytes, decimals = 2) {
if (bytes === 0) return '0 Bytes';
const k = 1024;
const dm = decimals < 0 ? 0 : decimals;
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
}
/**
* format a key into groups of 4 characters, for easier visual inspection
*