summaryrefslogtreecommitdiff
path: root/std/node/_fs/_fs_exists.ts
diff options
context:
space:
mode:
authorAli Hasani <a.hassssani@gmail.com>2020-05-03 23:44:38 +0430
committerGitHub <noreply@github.com>2020-05-03 15:14:38 -0400
commit5cc0f056d1af6f76c6ad81a6cd68dcaabba60f35 (patch)
tree4a32cb418ca84aba47e05e6dc6c98e8ef724fcd0 /std/node/_fs/_fs_exists.ts
parent7e32269f3f230c5b714bbf70aa59d74f9a867373 (diff)
[std/node] add the ability to path argument to be URL type (#5055)
Diffstat (limited to 'std/node/_fs/_fs_exists.ts')
-rw-r--r--std/node/_fs/_fs_exists.ts9
1 files changed, 6 insertions, 3 deletions
diff --git a/std/node/_fs/_fs_exists.ts b/std/node/_fs/_fs_exists.ts
index c3bea0d4e..e6e6e4f2e 100644
--- a/std/node/_fs/_fs_exists.ts
+++ b/std/node/_fs/_fs_exists.ts
@@ -1,13 +1,15 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
+import { fromFileUrl } from "../path.ts";
type ExitsCallback = (exists: boolean) => void;
/**
- * TODO: Also accept 'path' parameter as a Node polyfill Buffer or URL type once these
+ * TODO: Also accept 'path' parameter as a Node polyfill Buffer type once these
* are implemented. See https://github.com/denoland/deno/issues/3403
* Deprecated in node api
*/
-export function exists(path: string, callback: ExitsCallback): void {
+export function exists(path: string | URL, callback: ExitsCallback): void {
+ path = path instanceof URL ? fromFileUrl(path) : path;
Deno.lstat(path)
.then(() => {
callback(true);
@@ -19,7 +21,8 @@ export function exists(path: string, callback: ExitsCallback): void {
* TODO: Also accept 'path' parameter as a Node polyfill Buffer or URL type once these
* are implemented. See https://github.com/denoland/deno/issues/3403
*/
-export function existsSync(path: string): boolean {
+export function existsSync(path: string | URL): boolean {
+ path = path instanceof URL ? fromFileUrl(path) : path;
try {
Deno.lstatSync(path);
return true;