mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +00:00
refactor: change file name
This commit is contained in:
parent
18bb9e9526
commit
4619198051
6 changed files with 15 additions and 15 deletions
15
src/renderer/utils/format-bytes.ts
Normal file
15
src/renderer/utils/format-bytes.ts
Normal file
|
@ -0,0 +1,15 @@
|
|||
const FORMAT = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
|
||||
|
||||
export const formatBytes = (bytes: number): string => {
|
||||
if (!Number.isFinite(bytes) || isNaN(bytes) || bytes < 0) {
|
||||
return `N/A ${FORMAT[0]}`;
|
||||
}
|
||||
|
||||
const byteKBase = 1024;
|
||||
|
||||
const base = Math.floor(Math.log(bytes) / Math.log(byteKBase));
|
||||
|
||||
const formatedByte = bytes / byteKBase ** base;
|
||||
|
||||
return `${Math.trunc(formatedByte * 10) / 10} ${FORMAT[base]}`;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue