refactor: move formatBytes utility to shared module and remove unused files

This commit is contained in:
Moyasee
2026-01-30 12:43:21 +02:00
parent bd8bc4f955
commit e28bd32169
3 changed files with 1 additions and 20 deletions

View File

@@ -1,6 +1,6 @@
import { LibraryGame } from "@types";
import { useGameCard } from "@renderer/hooks";
import { formatBytes } from "@renderer/utils";
import { formatBytes } from "@shared";
import {
ClockIcon,
AlertFillIcon,

View File

@@ -1,18 +0,0 @@
/**
* Converts a number of bytes into a human-readable string with appropriate units
* @param bytes - The number of bytes to format
* @param decimals - Number of decimal places (default: 2)
* @returns Formatted string like "1.5 GB", "256 MB", etc.
*/
export const formatBytes = (bytes: number, decimals = 2): string => {
if (bytes === 0) return "0 B";
const k = 1024;
const dm = decimals < 0 ? 0 : decimals;
const sizes = ["B", "KB", "MB", "GB", "TB", "PB"];
const i = Math.floor(Math.log(bytes) / Math.log(k));
const index = Math.min(i, sizes.length - 1);
return `${parseFloat((bytes / Math.pow(k, index)).toFixed(dm))} ${sizes[index]}`;
};

View File

@@ -1 +0,0 @@
export * from "./format-bytes";