2021-01-11 12:13:41 -05:00
|
|
|
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
|
2019-06-19 00:22:01 -04:00
|
|
|
/**
|
|
|
|
* Test whether or not the given path exists by checking with the file system
|
|
|
|
*/
|
2019-03-11 13:14:26 -04:00
|
|
|
export async function exists(filePath: string): Promise<boolean> {
|
2020-03-20 09:38:34 -04:00
|
|
|
try {
|
2020-06-12 15:23:38 -04:00
|
|
|
await Deno.lstat(filePath);
|
2020-03-20 09:38:34 -04:00
|
|
|
return true;
|
|
|
|
} catch (err) {
|
|
|
|
if (err instanceof Deno.errors.NotFound) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-12-13 09:47:09 -05:00
|
|
|
|
2020-03-20 09:38:34 -04:00
|
|
|
throw err;
|
|
|
|
}
|
2019-03-11 13:14:26 -04:00
|
|
|
}
|
|
|
|
|
2019-06-19 00:22:01 -04:00
|
|
|
/**
|
|
|
|
* Test whether or not the given path exists by checking with the file system
|
|
|
|
*/
|
2019-03-11 13:14:26 -04:00
|
|
|
export function existsSync(filePath: string): boolean {
|
|
|
|
try {
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.lstatSync(filePath);
|
2019-03-11 13:14:26 -04:00
|
|
|
return true;
|
2019-12-13 09:47:09 -05:00
|
|
|
} catch (err) {
|
2020-02-24 15:48:35 -05:00
|
|
|
if (err instanceof Deno.errors.NotFound) {
|
2020-02-21 10:36:13 -05:00
|
|
|
return false;
|
2019-12-13 09:47:09 -05:00
|
|
|
}
|
|
|
|
throw err;
|
2019-03-11 13:14:26 -04:00
|
|
|
}
|
|
|
|
}
|