UNPKG

agentsqripts

Version:

Comprehensive static code analysis toolkit for identifying technical debt, security vulnerabilities, performance issues, and code quality problems

61 lines (55 loc) 1.64 kB
/** * @file File system utilities index * @description Single responsibility: Export all file system utilities */ const fileExists = require('./fileExists'); const readFileContent = require('./readFileContent'); const path = require('path'); const fs = require('fs'); const os = require('os'); /** * Get file extension from path * @param {string} filePath - Path to file * @returns {string} File extension */ function getFileExtension(filePath) { return path.extname(filePath); } /** * Check if file is of specific type * @param {string} filePath - Path to file * @param {string|Array} extensions - Extension(s) to check * @returns {boolean} True if file matches type */ function isFileType(filePath, extensions) { const ext = getFileExtension(filePath).toLowerCase(); const checkExts = Array.isArray(extensions) ? extensions : [extensions]; return checkExts.some(e => ext === (e.startsWith('.') ? e : '.' + e)); } /** * Create temporary file * @param {string} content - File content * @param {string} suffix - File suffix * @returns {string} Path to temp file */ function createTempFile(content = '', suffix = '.tmp') { const tempPath = path.join(os.tmpdir(), `temp-${Date.now()}${suffix}`); fs.writeFileSync(tempPath, content); return tempPath; } /** * Resolve project path * @param {string} relativePath - Relative path from project root * @returns {string} Absolute path */ function resolveProjectPath(relativePath) { return path.resolve(process.cwd(), relativePath); } module.exports = { fileExists, readFileContent, getFileExtension, isFileType, createTempFile, resolveProjectPath };