mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-30 14:21:04 +00:00
refactor: move formatBytes utility to shared module and remove unused files
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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]}`;
|
||||
};
|
||||
@@ -1 +0,0 @@
|
||||
export * from "./format-bytes";
|
||||
Reference in New Issue
Block a user