mirror of
https://git.stupid.fish/teidesu/scripts.git
synced 2025-07-27 18:22:10 +10:00
23 lines
503 B
TypeScript
23 lines
503 B
TypeScript
import * as fsp from 'node:fs/promises'
|
|
|
|
export async function fileExists(path: string): Promise<boolean> {
|
|
try {
|
|
const stat = await fsp.stat(path)
|
|
return stat.isFile()
|
|
} catch {
|
|
return false
|
|
}
|
|
}
|
|
|
|
export async function directoryExists(path: string): Promise<boolean> {
|
|
try {
|
|
const stat = await fsp.stat(path)
|
|
return stat.isDirectory()
|
|
} catch {
|
|
return false
|
|
}
|
|
}
|
|
|
|
export function sanitizeFilename(filename: string) {
|
|
return filename.replace(/[/\\?%*:|"<>]/g, '_')
|
|
}
|