From e40b27897bc8b38c5c53b1a527b7ebc57bf92564 Mon Sep 17 00:00:00 2001 From: EGAMAGZ <46827955+EGAMAGZ@users.noreply.github.com> Date: Sun, 9 Mar 2025 23:25:13 -0600 Subject: [PATCH 1/2] refactor: replaced custom byte size calculation with @std/fmt for improved readability --- frontend/routes/package/(_islands)/DependencyGraph.tsx | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/frontend/routes/package/(_islands)/DependencyGraph.tsx b/frontend/routes/package/(_islands)/DependencyGraph.tsx index 359562ce..efcf79a0 100644 --- a/frontend/routes/package/(_islands)/DependencyGraph.tsx +++ b/frontend/routes/package/(_islands)/DependencyGraph.tsx @@ -19,6 +19,7 @@ import type { DependencyGraphKindNpm, DependencyGraphKindRoot, } from "../../../utils/api_types.ts"; +import { format as formatBytes } from "@std/fmt/bytes"; export interface DependencyGraphProps { dependencies: DependencyGraphItem[]; @@ -216,13 +217,6 @@ function createDigraph(dependencies: DependencyGraphItem[]) { }`; } -function bytesToSize(bytes: number) { - const sizes = ["B", "KB", "MB", "GB", "TB"]; - if (bytes == 0) return "0 B"; - const i = Math.floor(Math.log(bytes) / Math.log(1024)); - return (bytes / Math.pow(1024, i)).toFixed(0) + " " + sizes[i]; -} - function renderDependency( dependency: GroupedDependencyGraphKind, size?: number, @@ -244,7 +238,7 @@ function renderDependency( return entrypoint; } }).join("\n") - }\n${bytesToSize(size ?? 0)}`; + }\n${formatBytes(size ?? 0, { maximumFractionDigits: 0}).toUpperCase()}`; color = "#faee4a"; break; } From 7065cc627b1e076a9044e70b40b8ae685a269dc0 Mon Sep 17 00:00:00 2001 From: EGAMAGZ <46827955+EGAMAGZ@users.noreply.github.com> Date: Sun, 9 Mar 2025 23:29:10 -0600 Subject: [PATCH 2/2] style: Formatted code --- frontend/routes/package/(_islands)/DependencyGraph.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/routes/package/(_islands)/DependencyGraph.tsx b/frontend/routes/package/(_islands)/DependencyGraph.tsx index efcf79a0..797108ed 100644 --- a/frontend/routes/package/(_islands)/DependencyGraph.tsx +++ b/frontend/routes/package/(_islands)/DependencyGraph.tsx @@ -238,7 +238,7 @@ function renderDependency( return entrypoint; } }).join("\n") - }\n${formatBytes(size ?? 0, { maximumFractionDigits: 0}).toUpperCase()}`; + }\n${formatBytes(size ?? 0, { maximumFractionDigits: 0 }).toUpperCase()}`; color = "#faee4a"; break; }