2020-04-06 23:43:14 -04:00
|
|
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
|
|
|
|
|
|
|
type ExitsCallback = (exists: boolean) => void;
|
|
|
|
|
2020-04-20 05:29:37 -04:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
* Deprecated in node api
|
|
|
|
*/
|
2020-04-06 23:43:14 -04:00
|
|
|
export function exists(path: string, callback: ExitsCallback): void {
|
2020-04-20 05:29:37 -04:00
|
|
|
Deno.lstat(path)
|
2020-04-06 23:43:14 -04:00
|
|
|
.then(() => {
|
|
|
|
callback(true);
|
|
|
|
})
|
2020-04-20 05:29:37 -04:00
|
|
|
.catch(() => callback(false));
|
2020-04-06 23:43:14 -04:00
|
|
|
}
|
|
|
|
|
2020-04-20 05:29:37 -04:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2020-04-06 23:43:14 -04:00
|
|
|
export function existsSync(path: string): boolean {
|
|
|
|
try {
|
|
|
|
Deno.lstatSync(path);
|
|
|
|
return true;
|
|
|
|
} catch (err) {
|
|
|
|
if (err instanceof Deno.errors.NotFound) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
}
|