-
-
Save kvasdopil/7be6652283eb87e058150a760073dd2f 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 const findFile = (node, fn, pathToFile = '') => { | |
const filePath = path.join(pathToFile, node.name); | |
if (node.type === 'directory') { | |
return node.children | |
.map(element => findFile(element, fn, filePath)) | |
.reduce((res, found) => [...res, ...found], []); | |
} | |
if (fn(node)) { | |
return [filePath]; | |
} | |
return []; | |
}; | |
export default (tree, str) => findFile(tree, node => node.type === 'file' && node.name.includes(str)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment