feat(tool): text statistics

This commit is contained in:
Corentin Thomasset 2022-04-14 01:06:06 +02:00
parent 2f49631ff7
commit 0a7c3252e3
No known key found for this signature in database
GPG key ID: DBD997E935996158
7 changed files with 67 additions and 1 deletions

11
src/utils/convert.ts Normal file
View file

@ -0,0 +1,11 @@
export function formatBytes(bytes: number, decimals = 2) {
if (bytes === 0) {
return '0 Bytes';
}
const k = 1024;
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(decimals)) + ' ' + sizes[i];
}