Merge pull request #17202 from backstage/rugvip/cameltweak

rollbar-backend: fix camelize fix
This commit is contained in:
Patrik Oldsberg
2023-04-03 11:28:34 +02:00
committed by GitHub
2 changed files with 3 additions and 6 deletions
@@ -44,7 +44,7 @@ describe('RollbarApi', () => {
name: 'xyz',
account_id: 1,
status: 'enabled',
extra_nested: { nested_value: [{ value_here: 1 }] },
extra_nested: { nested_value: [{ value_here: 'hello_world' }] },
},
];
@@ -67,7 +67,7 @@ describe('RollbarApi', () => {
name: 'xyz',
accountId: 1,
status: 'enabled',
extraNested: { nestedValue: [{ valueHere: 1 }] },
extraNested: { nestedValue: [{ valueHere: 'hello_world' }] },
},
]);
});
@@ -31,15 +31,12 @@ const baseUrl = 'https://api.rollbar.com/api/1';
const buildUrl = (url: string) => `${baseUrl}${url}`;
function camelize<T extends unknown>(val: T): T {
if (typeof val === 'string') {
return camelCase(val) as T;
}
if (Array.isArray(val)) {
return val.map(camelize) as T;
}
if (val && typeof val === 'object') {
return Object.fromEntries(
Object.entries(val).map(([k, v]) => [camelize(k), camelize(v)]),
Object.entries(val).map(([k, v]) => [camelCase(k), camelize(v)]),
) as T;
}
return val;