import isObject from 'lodash.isobject'; import lodashCamelCase from 'lodash.camelcase'; import { CamelCase, CamelCasedPropertiesDeep } from 'type-fest'; export const camelCase = (text: T) => lodashCamelCase(text as unknown as string) as CamelCase; export const camelCaseDeep = (value: T): CamelCasedPropertiesDeep => { // Check if it's an array if (Array.isArray(value)) { return value.map(camelCaseDeep) as CamelCasedPropertiesDeep; } // Check if it's an object if (isObject(value)) { const result: Record = {}; for (const key in value) { result[camelCase(key)] = camelCaseDeep(value[key]); } return result as CamelCasedPropertiesDeep; } return value as CamelCasedPropertiesDeep; };