diff options
Diffstat (limited to 'fs/exists.ts')
| -rw-r--r-- | fs/exists.ts | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/fs/exists.ts b/fs/exists.ts new file mode 100644 index 000000000..aa961037d --- /dev/null +++ b/fs/exists.ts @@ -0,0 +1,27 @@ +// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. +/** + * Test whether or not the given path exists by checking with the file system + * @export + * @param {string} filePath + * @returns {Promise<boolean>} + */ +export async function exists(filePath: string): Promise<boolean> { + return Deno.stat(filePath) + .then(() => true) + .catch(() => false); +} + +/** + * Test whether or not the given path exists by checking with the file system + * @export + * @param {string} filePath + * @returns {boolean} + */ +export function existsSync(filePath: string): boolean { + try { + Deno.statSync(filePath); + return true; + } catch { + return false; + } +} |
