Very Popular
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485import { ensureDir, path } from '../deps.ts'
/* check whether or not the given path exists as a directory. */export async function existsDir(path: string): Promise<boolean> { try { const fi = await Deno.lstat(path) if (fi.isDirectory) { return true } return false } catch (err) { if (err instanceof Deno.errors.NotFound) { return false } return Promise.reject(err) }}
/* check whether or not the given path exists as a directory. */export function existsDirSync(path: string) { try { const fi = Deno.lstatSync(path) if (fi.isDirectory) { return true } return false } catch (err) { if (err instanceof Deno.errors.NotFound) { return false } throw err }}
/* check whether or not the given path exists as regular file. */export async function existsFile(path: string): Promise<boolean> { try { const fi = await Deno.lstat(path) if (fi.isFile) { return true } return false } catch (err) { if (err instanceof Deno.errors.NotFound) { return false } return Promise.reject(err) }}
/* check whether or not the given path exists as regular file. */export function existsFileSync(path: string) { try { const fi = Deno.lstatSync(path) if (fi.isFile) { return true } return false } catch (err) { if (err instanceof Deno.errors.NotFound) { return false } throw err }}
/** ensure and write a text file. */export async function ensureTextFile(name: string, content: string): Promise<void> { const dir = path.dirname(name) await ensureDir(dir) await Deno.writeTextFile(name, content)}
/** remove the file if it exists. */export async function lazyRemove(name: string): Promise<void> { try { await Deno.remove(name) } catch (err) { if (err instanceof Deno.errors.NotFound) { return } return Promise.reject(err) }}