import { isArray, isObject, mapKeys, mapValues, snakeCase } from 'lodash' type ObjType = Record | unknown[] | unknown export function deepSnakeCaseKeys(obj: T): T { if (isArray(obj)) { return obj.map(deepSnakeCaseKeys) as T } else if (isObject(obj)) { return mapValues( // @ts-ignore This mutates the object, but we don't care about the type here mapKeys(obj, (_value: string, key: string) => snakeCase(key)), deepSnakeCaseKeys ) as T } return obj }