Skip to content

Instantly share code, notes, and snippets.

@strogonoff
strogonoff / flatten.ts
Last active April 5, 2023 02:34
Object (un)flattening in TypeScript
// Based on original implementation from Tofandel’s answer: https://stackoverflow.com/a/59787588/247441
/* Aggregates parts (mapped to slash-separated paths) into a nested object.
E.g.:
{ /some/path: A, /foo: B, /some/other/path: C }
gets turned into:
{ foo: B, some: { path: A, other: { path: C } } }
*/