refactor: reorganize project structure and improve user command handling
This commit is contained in:
parent
5cfcb3ba0c
commit
49d6b51de6
7 changed files with 64 additions and 26 deletions
13
lib/files.ts
Normal file
13
lib/files.ts
Normal file
|
@ -0,0 +1,13 @@
|
|||
export const formatSize = (bytes: number): string => {
|
||||
const units = ["B", "KB", "MB", "GB", "TB"];
|
||||
let size = bytes;
|
||||
let unit = units[0];
|
||||
for (let i = 0; i < units.length; i++) {
|
||||
if (size < 1024 || i === units.length - 1) {
|
||||
unit = units[i];
|
||||
break;
|
||||
}
|
||||
size /= 1024;
|
||||
}
|
||||
return `${size % 1 === 0 ? size : size.toFixed(2)} ${unit}`;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue