blob: cc4f6573646c66e0e90f3a533babbecfb598e678 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
type ExitsCallback = (exists: boolean) => void;
/* Deprecated in node api */
export function exists(path: string, callback: ExitsCallback): void {
new Promise(async (resolve, reject) => {
try {
await Deno.lstat(path);
resolve();
} catch (err) {
reject(err);
}
})
.then(() => {
callback(true);
})
.catch(() => {
callback(false);
});
}
export function existsSync(path: string): boolean {
try {
Deno.lstatSync(path);
return true;
} catch (err) {
if (err instanceof Deno.errors.NotFound) {
return false;
}
throw err;
}
}
|