--- /dev/null
+export function formatSize(bytes: number, decimals = 1): string {
+ const base = 1024;
+
+ // Shortcut so we won"t divide by zero
+ if (bytes === 0)
+ return "0 B";
+
+ const units = ["B", "KiB", "MiB", "GiB", "TiB", "EiB", "PiB"];
+
+ // Find the most appropriate unit
+ const unit = Math.floor(Math.log(bytes) / Math.log(base));
+
+ // Format the number
+ const size = parseFloat((bytes / Math.pow(base, unit)).toFixed(decimals));
+
+ return `${size} ${units[unit]}`;
+}
+
+export function formatHostname(url: string): string {
+ try {
+ return new URL(url).hostname;
+ } catch {
+ return url;
+ }
+}