UNPKG

878 BPlain TextView Raw
1import {FileSystem, FileSystemReadSync} from "./api";
2import {checkExistsInDir, splitPathToDirAndFile} from "./utils";
3
4export function checkExistsSync(expectedType: 'file' | 'dir', fs: FileSystemReadSync, targetPath: string): boolean {
5 const {name, parentPath} = splitPathToDirAndFile(targetPath);
6 try {
7 let dirContent = fs.loadDirectoryChildrenSync(parentPath);
8 return checkExistsInDir(expectedType, dirContent, name)
9 } catch (error) {
10 return false;
11 }
12}
13
14export async function checkExists(expectedType: 'file' | 'dir', fs: FileSystem, targetPath: string): Promise<boolean> {
15 const {name, parentPath} = splitPathToDirAndFile(targetPath);
16 try {
17 let dirContent = await fs.loadDirectoryChildren(parentPath);
18 return checkExistsInDir(expectedType, dirContent, name)
19 } catch (error) {
20 return false;
21 }
22}