From c72d0897f7b37843109c86f61d97eba05ba3ca0d Mon Sep 17 00:00:00 2001 From: dujinkim Date: Fri, 13 Jun 2025 07:08:01 +0000 Subject: (대표님) 20250613 16시 08분 b-rfq, document 등 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/utils.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'lib/utils.ts') diff --git a/lib/utils.ts b/lib/utils.ts index c09589d5..33b5a0c2 100644 --- a/lib/utils.ts +++ b/lib/utils.ts @@ -182,4 +182,16 @@ export function formatDateToQuarter(dateString: string | null | undefined): stri } return `${year} ${quarter}Q` +} + +export function formatBytes(bytes: number, decimals: number = 2): string { + if (bytes === 0) return "0 Bytes" + + const k = 1024 + const dm = decimals < 0 ? 0 : decimals + const sizes = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"] + + const i = Math.floor(Math.log(bytes) / Math.log(k)) + + return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + " " + sizes[i] } \ No newline at end of file -- cgit v1.2.3