/** * Deep renames all keys in an object to lowercase * @param obj - The object to transform * @returns A new object with all keys converted to lowercase */ function deepLowerCaseKeys(obj: any): T { if (!obj || typeof obj !== "object") { return obj; } // Handle arrays if (Array.isArray(obj)) { return obj.map((item) => deepLowerCaseKeys(item)) as unknown as T; } // Handle objects return Object.keys(obj).reduce( (result, key) => { const value = obj[key]; const lowercaseKey = key.toLowerCase(); result[lowercaseKey] = typeof value === "object" && value !== null ? deepLowerCaseKeys(value) : value; return result; }, {} as Record ) as T; } export default deepLowerCaseKeys;