mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-16 18:56:22 +00:00
21 lines
484 B
TypeScript
21 lines
484 B
TypeScript
export function convertKeysToCamelCase(obj: any): any {
|
|
if (!obj || typeof obj !== 'object') {
|
|
return obj;
|
|
}
|
|
|
|
if (Array.isArray(obj)) {
|
|
return obj.map(convertKeysToCamelCase);
|
|
}
|
|
|
|
const camelCaseObj: { [key: string]: any } = {};
|
|
|
|
for (const key of Object.keys(obj)) {
|
|
const camelCaseKey = key.replace(/_([a-z])/g, (_, letter) =>
|
|
letter.toUpperCase(),
|
|
);
|
|
camelCaseObj[camelCaseKey] = convertKeysToCamelCase(obj[key]);
|
|
}
|
|
|
|
return camelCaseObj;
|
|
}
|