From 14e4fed321634dc014ad2f15cafef3ed0123855e Mon Sep 17 00:00:00 2001 From: Mohamed Bassem Date: Sun, 23 Feb 2025 22:50:12 +0000 Subject: feat: Add a setting page to manage assets. Fixes #730 --- apps/web/lib/utils.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'apps/web/lib/utils.ts') diff --git a/apps/web/lib/utils.ts b/apps/web/lib/utils.ts index 230c9eef..292a6d62 100644 --- a/apps/web/lib/utils.ts +++ b/apps/web/lib/utils.ts @@ -8,6 +8,18 @@ export function cn(...inputs: ClassValue[]) { export type OS = "macos" | "ios" | "windows" | "android" | "linux" | null; +export function formatBytes(bytes: number, decimals = 2) { + 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]; +} + export function getOS() { if (typeof window === "undefined") return; const userAgent = window.navigator.userAgent.toLowerCase(); -- cgit v1.2.3-70-g09d2