mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-19 09:13:57 +00:00
refactor: remove pretty bytes
This commit is contained in:
15
src/renderer/utils/byteFormat.ts
Normal file
15
src/renderer/utils/byteFormat.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
const FORMAT = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
|
||||
|
||||
export const byteFormat = (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]}`;
|
||||
};
|
||||
1
src/renderer/utils/index.ts
Normal file
1
src/renderer/utils/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from "./byteFormat";
|
||||
Reference in New Issue
Block a user