import { defaultExceptions } from "./defaultExceptions" export function toCamel(snake: Array, exceptions?: string[], recursionHistory?: string): Array export function toCamel( snake: Record, exceptions?: string[], recursionHistory?: string ): Record export function toCamel(snake: T, exceptions?: string[], recursionHistory?: string): T export function toCamel( snake: Record | Array | unknown, exceptions: string[] = defaultExceptions, recursionHistory?: string ): Record | Array | unknown { return Array.isArray(snake) ? snake.map(o => toCamel(o, exceptions, `${recursionHistory ? recursionHistory + "." : ""}[*]`)) : typeof snake == "object" && snake != null ? Object.entries(snake).reduce>((result, entry) => { const newHistory = `${recursionHistory ? recursionHistory + "." : ""}${entry[0]}` return exceptions.some(e => (e.startsWith("*.") ? newHistory.endsWith(e.substring(2)) : newHistory == e)) ? { ...result, [entry[0]]: entry[1] } : { ...result, [entry[0].replace(/(_[a-z])/g, group => group.toUpperCase().replace("_", ""))]: toCamel(entry[1]), } }, {}) : snake }