Skip to content

Instantly share code, notes, and snippets.

@Markonis
Created March 18, 2019 16:10
Show Gist options
  • Save Markonis/f702a33e5b81478dc055bc4ddea6cefc to your computer and use it in GitHub Desktop.
Save Markonis/f702a33e5b81478dc055bc4ddea6cefc to your computer and use it in GitHub Desktop.
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