Skip to content

Instantly share code, notes, and snippets.

@sethdavis512
Created October 21, 2018 16:16
Show Gist options
  • Save sethdavis512/0b2a38a0e3f190928e114d83a72d9fee to your computer and use it in GitHub Desktop.
Save sethdavis512/0b2a38a0e3f190928e114d83a72d9fee to your computer and use it in GitHub Desktop.
const flattenFilePath = (pathPart, directoryOrFileContents) => {
return Object.entries(directoryOrFileContents).reduce((flattenedFilePaths, [key, value]) => {
if (typeof value === "object") {
Object.assign(flattenedFilePaths, flattenFilePath(`${pathPart}/${key}`, value))
} else {
flattenedFilePaths[`${pathPart}/${key}`] = value
}
return flattenedFilePaths
}, {})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment