The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { isPlainObject } from "./data.ts"; |
| 2 | |
| 3 | export const camelCaseKey = (key: string) => |
| 4 | key.replace(/^_+/, "").replace(/_([a-z])/g, (_, letter: string) => letter.toUpperCase()); |
| 5 | |
| 6 | export const toCamelCase = <T>(value: unknown): T => { |
| 7 | if (Array.isArray(value)) { |
| 8 | return value.map((item) => toCamelCase(item)) as T; |
| 9 | } |
| 10 | if (isPlainObject(value)) { |
| 11 | return Object.fromEntries( |
| 12 | Object.entries(value).map(([key, nested]) => [camelCaseKey(key), toCamelCase(nested)]), |
| 13 | ) as T; |
| 14 | } |
| 15 | return value as T; |
| 16 | }; |