The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/packages/tools/src/convertSubObjectsIntoPaths.ts

16 lines
571 B

export function convertSubObjectsIntoPaths(object: Record<string, any>, parentPath?: string): Record<string, any> {
return Object.fromEntries(
Object.keys(object).flatMap((key) => {
const value = object[key];
const fullKey = parentPath ? `${parentPath}.${key}` : key;
if (typeof value === 'object' && !Array.isArray(value) && value !== null) {
const flattened = convertSubObjectsIntoPaths(value, fullKey);
return Object.keys(flattened).map((newKey) => [newKey, flattened[newKey]]);
}
return [[fullKey, value]];
}) as [string, any][],
);
}