tree-to-flat-map
Version:
Convert a tree to a flat map with dot-separated keys
18 lines (17 loc) • 637 B
TypeScript
declare type SupportedLeaf = boolean | number | string;
declare type FlatMap<Leaf extends SupportedLeaf> = {
[key: string]: Leaf;
};
declare type _Tree<Leaf extends SupportedLeaf> = Leaf | Readonly<{
[key: string]: _Tree<Leaf>;
}>;
declare type Tree<Leaf extends SupportedLeaf> = Readonly<{
[key: string]: _Tree<Leaf>;
}>;
/** Converts `tree` to a flat map with dot-separated keys. */
export declare const treeToFlatMap: <Leaf extends SupportedLeaf = string>(tree: Readonly<{
[key: string]: _Tree<Leaf>;
}>, { separator }?: Readonly<{
separator?: string | undefined;
}>) => FlatMap<Leaf>;
export {};