1
0
mirror of https://github.com/chinchang/web-maker.git synced 2025-07-16 19:46:19 +02:00

refactor logic for existing file check based on paths

This commit is contained in:
Kushagra Gour
2018-10-15 01:11:38 +05:30
parent 6d6fe6773e
commit b91028532f
3 changed files with 36 additions and 8 deletions

View File

@@ -95,3 +95,15 @@ export function doesFileExistInFolder(folder, fileName) {
const details = getChildFileFromName(folder.children, fileName);
return !!details.file;
}
/**
* Returns parent path of passed path
* @param {string} path Path of file to find parent of
*/
export function getParentPath(path) {
const pathPieces = path.split('/');
if (pathPieces.length > 1) {
return pathPieces.slice(0, -1).join('/');
}
return '';
}