1
1
import { ensureDir , path } from '../deps.ts'
2
2
3
- /* check whether or not the given path exists as a directory */
3
+ /* check whether or not the given path exists as a directory. */
4
4
export async function existsDir ( path : string ) : Promise < boolean > {
5
5
try {
6
6
const fi = await Deno . lstat ( path )
@@ -16,7 +16,7 @@ export async function existsDir(path: string): Promise<boolean> {
16
16
}
17
17
}
18
18
19
- /* check whether or not the given path exists as a directory */
19
+ /* check whether or not the given path exists as a directory. */
20
20
export function existsDirSync ( path : string ) {
21
21
try {
22
22
const fi = Deno . lstatSync ( path )
@@ -32,7 +32,7 @@ export function existsDirSync(path: string) {
32
32
}
33
33
}
34
34
35
- /* check whether or not the given path exists as regular file */
35
+ /* check whether or not the given path exists as regular file. */
36
36
export async function existsFile ( path : string ) : Promise < boolean > {
37
37
try {
38
38
const fi = await Deno . lstat ( path )
@@ -48,7 +48,7 @@ export async function existsFile(path: string): Promise<boolean> {
48
48
}
49
49
}
50
50
51
- /* check whether or not the given path exists as regular file */
51
+ /* check whether or not the given path exists as regular file. */
52
52
export function existsFileSync ( path : string ) {
53
53
try {
54
54
const fi = Deno . lstatSync ( path )
@@ -64,9 +64,21 @@ export function existsFileSync(path: string) {
64
64
}
65
65
}
66
66
67
- /** ensure and write a text file */
67
+ /** ensure and write a text file. */
68
68
export async function ensureTextFile ( name : string , content : string ) : Promise < void > {
69
69
const dir = path . dirname ( name )
70
70
await ensureDir ( dir )
71
71
await Deno . writeTextFile ( name , content )
72
72
}
73
+
74
+ /** remove the file if it exists. */
75
+ export async function lazyRemove ( name : string ) : Promise < void > {
76
+ try {
77
+ await Deno . remove ( name )
78
+ } catch ( err ) {
79
+ if ( err instanceof Deno . errors . NotFound ) {
80
+ return
81
+ }
82
+ return Promise . reject ( err )
83
+ }
84
+ }
0 commit comments