boonya/rtsp-video-recorder

View on GitHub
src/helpers/directoryExists.ts

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
import fs from 'fs';

export default function directoryExists(path: string) {
    try {
        const stats = fs.lstatSync(path);
        if (!stats.isDirectory()) {
            throw new TypeError(`${path} exists but it is not a directory.`);
        }
        return true;
    } catch (err) {
        if (err instanceof TypeError) {
            throw err;
        }
        return false;
    }
}