mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-06-16 03:05:11 -04:00
feat(tool): text statistics
This commit is contained in:
parent
2f49631ff7
commit
0a7c3252e3
7 changed files with 67 additions and 1 deletions
11
src/utils/convert.ts
Normal file
11
src/utils/convert.ts
Normal 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];
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue