UNPKG

ctrlshiftleft

Version:

AI-powered toolkit for embedding QA and security testing into development workflows

67 lines (61 loc) 1.72 kB
import fs from 'fs/promises'; import path from 'path'; /** * Check if a source path is valid * @param sourcePath Path to check * @returns True if path exists and is readable */ export async function isValidSourcePath(sourcePath: string): Promise<boolean> { try { const stats = await fs.stat(sourcePath); return stats.isFile() || stats.isDirectory(); } catch (error) { return false; } } /** * Check if a test path is valid * @param testPath Path to check * @returns True if path exists and is readable */ export async function isValidTestPath(testPath: string): Promise<boolean> { try { const stats = await fs.stat(testPath); return stats.isFile() || stats.isDirectory(); } catch (error) { return false; } } /** * Ensure a directory exists, creating it if necessary * @param dirPath Directory path to ensure */ export async function ensureDirectoryExists(dirPath: string): Promise<void> { try { await fs.mkdir(dirPath, { recursive: true }); } catch (error) { // Ignore if directory already exists if ((error as NodeJS.ErrnoException).code !== 'EEXIST') { throw error; } } } /** * Get relative path between two absolute paths * @param from Source path * @param to Target path * @returns Relative path */ export function getRelativePath(from: string, to: string): string { return path.relative(from, to); } /** * Get base name of a file without extension * @param filePath File path * @returns Base name without extension */ export function getBaseName(filePath: string): string { const basename = path.basename(filePath); const extname = path.extname(filePath); return basename.substring(0, basename.length - extname.length); }