Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions app/(tools)/csv-formatter/components/StatsBar.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use client";

import { formatBytes } from "@/lib/base64-utils";
import { byteLength, delimiterLabel, lineEndingLabel, DELIMITERS, type ParsedCsv } from "@/lib/csv-utils";

export function StatsBar({ parsed, input }: { parsed: ParsedCsv; input: string }) {
Expand Down Expand Up @@ -43,9 +44,3 @@ function StatCell({ label, value, sub }: { label: string; value: string; sub?: s
</div>
);
}

function formatBytes(bytes: number): string {
if (bytes < 1024) return `${bytes} B`;
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
return `${(bytes / (1024 * 1024)).toFixed(2)} MB`;
}
13 changes: 4 additions & 9 deletions app/(tools)/json-formatter/components/StatsBar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use client";

import { useEffect, useState } from "react";
import { formatBytes } from "@/lib/base64-utils";
import { computeStats, gzipSize } from "@/lib/json-utils";

export function StatsBar({ input, output }: { input: string; output: string }) {
Expand All @@ -26,9 +27,9 @@ export function StatsBar({ input, output }: { input: string; output: string }) {
return (
<div className="card p-4 animate-fade-in">
<div className="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-6 gap-3">
<StatCell label="Size" value={fmt(stats.bytes)} />
<StatCell label="Minified" value={`${fmt(stats.bytesMin)}`} sub={`-${savedPct}%`} />
<StatCell label="Gzipped" value={gzip === null ? "…" : fmt(gzip)} />
<StatCell label="Size" value={formatBytes(stats.bytes)} />
<StatCell label="Minified" value={`${formatBytes(stats.bytesMin)}`} sub={`-${savedPct}%`} />
<StatCell label="Gzipped" value={gzip === null ? "…" : formatBytes(gzip)} />
<StatCell label="Depth" value={String(stats.depth)} />
<StatCell label="Keys" value={String(stats.totalKeys)} sub={`${stats.objects} obj · ${stats.arrays} arr`} />
<StatCell
Expand Down Expand Up @@ -56,9 +57,3 @@ function StatCell({ label, value, sub }: { label: string; value: string; sub?: s
</div>
);
}

function fmt(n: number): string {
if (n < 1024) return `${n} B`;
if (n < 1024 * 1024) return `${(n / 1024).toFixed(1)} KB`;
return `${(n / (1024 * 1024)).toFixed(2)} MB`;
}
Loading