export function getTimestamp(val: string | number | undefined): number { if (!val) return 0; if (typeof val === "number") return val; const parsed = Date.parse(val); return isNaN(parsed) ? 0 : parsed; } export const parseKeyPath = (key: string): { [entity: string]: string } => { if (!key) { return {}; } const cleanKey = key?.startsWith("/") ? key.slice(1) : key; const parts = cleanKey.split("/"); const result: { [entity: string]: string } = {}; for (let i = 0; i < parts.length; i += 2) { if (parts[i] && parts[i + 1]) { const entityType = parts[i]; const entityName = parts[i + 1]; result[entityType] = entityName; } } return result; }; export const decodeRegistryAuth = ( base64Secret: string, ): { username: string; password: string } => { try { const decoded = atob(base64Secret); const parts = decoded.split(":"); return { username: parts[0] || "", password: parts[1] || "", }; } catch (error) { console.error("Error decoding registry credentials:", error); return { username: "", password: "" }; } }; /** * Converts a storage value from any unit to Gigabytes (G) * Supported units: k, M, G, T, P, E, Ki, Mi, Gi, Ti, Pi, Ei * @param size The numeric size value * @param unit The unit string (e.g., 'M', 'Gi', 'T') * @returns The value converted to Gigabytes (decimal) */ export const convertToGigabytes = (size: number, unit?: string): number => { if (!size) return 0; if (!unit) return size; const decimalUnits: Record = { k: 1e3, M: 1e6, G: 1e9, T: 1e12, P: 1e15, E: 1e18, }; const binaryUnits: Record = { Ki: Math.pow(1024, 1), Mi: Math.pow(1024, 2), Gi: Math.pow(1024, 3), Ti: Math.pow(1024, 4), Pi: Math.pow(1024, 5), Ei: Math.pow(1024, 6), }; const GIGABYTE = 1e9; let bytes: number; if (binaryUnits[unit]) { bytes = size * binaryUnits[unit]; } else if (decimalUnits[unit]) { bytes = size * decimalUnits[unit]; } else { console.warn(`Unknown storage unit: ${unit}, assuming bytes`); bytes = size; } return bytes / GIGABYTE; };