Created
March 18, 2019 16:10
-
-
Save Markonis/f702a33e5b81478dc055bc4ddea6cefc 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 function setPaths<T>( | |
space: T, path: string[] = [], | |
clone: boolean = true) { | |
if (!space) return space; | |
let result = clone ? cloneDeep(space) : space; | |
for (const key in result) { | |
if (result.hasOwnProperty(key)) { | |
const childPath = path.concat([key]); | |
const element = result[key] as any; | |
if (isEndpoint(element)) { | |
element.path = childPath; | |
} else { | |
setPaths(element, childPath, false); | |
} | |
} | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment