Created
July 1, 2022 23:07
-
-
Save demipixel/6d92789db75b40eff9bbc514d12fa6b4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export type RelationDepth = { | |
[key: string]: RelationDepth; | |
}; | |
export function getRelations(depth: RelationDepth = {}) { | |
const relations: string[] = []; | |
const recurse = (obj: RelationDepth, path = '') => { | |
Object.keys(obj).forEach((key) => { | |
relations.push(path + key); | |
recurse(obj[key], path + key + '.'); | |
}); | |
}; | |
recurse(depth); | |
return relations; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment