2020-01-02 15:13:47 -05:00
|
|
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
2020-02-21 10:36:13 -05:00
|
|
|
const { lstat, lstatSync } = Deno;
|
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> {
|
2019-12-13 09:47:09 -05:00
|
|
|
return lstat(filePath)
|
2019-04-24 07:41:23 -04:00
|
|
|
.then((): boolean => true)
|
2019-12-13 09:47:09 -05:00
|
|
|
.catch((err: Error): boolean => {
|
2020-02-21 10:36:13 -05:00
|
|
|
if (err instanceof Deno.Err.NotFound) {
|
|
|
|
return false;
|
2019-12-13 09:47:09 -05: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 {
|
2019-12-13 09:47:09 -05:00
|
|
|
lstatSync(filePath);
|
2019-03-11 13:14:26 -04:00
|
|
|
return true;
|
2019-12-13 09:47:09 -05:00
|
|
|
} catch (err) {
|
2020-02-21 10:36:13 -05:00
|
|
|
if (err instanceof Deno.Err.NotFound) {
|
|
|
|
return false;
|
2019-12-13 09:47:09 -05:00
|
|
|
}
|
|
|
|
throw err;
|
2019-03-11 13:14:26 -04:00
|
|
|
}
|
|
|
|
}
|