first commit
This commit is contained in:
13
lib/format.ts
Normal file
13
lib/format.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* Byte cinsinden değeri okunabilir formata çevirir.
|
||||
* Örn: 3221225472 → "3 GB", 524288000 → "500 MB"
|
||||
*/
|
||||
export function formatBytes(bytes: number): string {
|
||||
if (bytes === 0) return "0 MB";
|
||||
const mb = bytes / (1024 * 1024);
|
||||
if (mb >= 1024) {
|
||||
const gb = mb / 1024;
|
||||
return gb % 1 === 0 ? `${gb} GB` : `${gb.toFixed(1)} GB`;
|
||||
}
|
||||
return mb % 1 === 0 ? `${mb} MB` : `${mb.toFixed(1)} MB`;
|
||||
}
|
||||
Reference in New Issue
Block a user