Skip to content

Instantly share code, notes, and snippets.

@kvasdopil
Forked from tuor4eg/язделяль
Last active April 14, 2018 20:19
Show Gist options
  • Save kvasdopil/7be6652283eb87e058150a760073dd2f to your computer and use it in GitHub Desktop.
Save kvasdopil/7be6652283eb87e058150a760073dd2f to your computer and use it in GitHub Desktop.
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