summaryrefslogtreecommitdiff
path: root/fs/exists.ts
diff options
context:
space:
mode:
authorAxetroy <troy450409405@gmail.com>2019-03-12 01:14:26 +0800
committerRyan Dahl <ry@tinyclouds.org>2019-03-11 13:14:26 -0400
commitef6d93235800161343281972e9bdc1b6b69e310e (patch)
treed41a62d2d769cb66cdee3462bf166b3a0cd3f7b9 /fs/exists.ts
parent8127cfb9ea7ffc35d9486bea37fd4c407dd80268 (diff)
add fs/exists (denoland/deno_std#260)
Original: https://github.com/denoland/deno_std/commit/142a1c6cf890e5c7626c4c934496fae1eee01715
Diffstat (limited to 'fs/exists.ts')
-rw-r--r--fs/exists.ts27
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;
+ }
+}