mongocat
Version:
✨ Mongocat 😺 is easy to use, configuration based Denormalization mongoose plugin for read heavy applications. Mongocat reduces write complexity too.
19 lines (17 loc) • 409 B
text/typescript
export const unflattenObj = (data: Record<string, any>) => {
const result: Record<string, any> = {};
for (const i in data) {
const keys = i.split('.');
keys.reduce(function(r, e, j) {
return (
r[e] ||
(r[e] = isNaN(Number(keys[j + 1]))
? keys.length - 1 === j
? data[i]
: {}
: [])
);
}, result);
}
return result;
};