14 lines
415 B
TypeScript
14 lines
415 B
TypeScript
/**
|
|
* 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`;
|
|
}
|