Files
bruno/packages/bruno-common/src/utils/index.ts
Anoop M D f2a187d5fe feat(#1460): string interpolation (#1461)
* feat(#1460): string interpolation

* chore: deleted file commited accidentally
2024-01-28 18:07:25 +05:30

12 lines
497 B
TypeScript

export const flattenObject = (obj: Record<string, any>, parentKey: string = ''): Record<string, any> => {
return Object.entries(obj).reduce((acc: Record<string, any>, [key, value]: [string, any]) => {
const newKey = parentKey ? (Array.isArray(obj) ? `${parentKey}[${key}]` : `${parentKey}.${key}`) : key;
if (typeof value === 'object' && value !== null) {
Object.assign(acc, flattenObject(value, newKey));
} else {
acc[newKey] = value;
}
return acc;
}, {});
};