All files / plainweb/src plainweb-fs.ts

91.66% Statements 22/24
85.71% Branches 6/7
100% Functions 3/3
91.66% Lines 22/24

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 281x   4x 4x 4x 3x 4x 1x 1x 4x   4x 4x 4x 4x 4x     4x   2x 2x 2x 1x 1x 1x 2x  
import fs from "node:fs/promises";
 
export async function fileExists(filePath: string) {
  try {
    await fs.access(filePath);
    return true;
  } catch {
    return false;
  }
}
 
export async function directoryExists(dirPath: string) {
  try {
    await fs.access(dirPath);
    return true;
  } catch {
    return false;
  }
}
 
export async function ensureDirectoryExists(dirPath: string): Promise<void> {
  try {
    await fs.access(dirPath);
  } catch {
    await fs.mkdir(dirPath, { recursive: true });
  }
}