UNPKG

agentsqripts

Version:

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

31 lines (24 loc) 877 B
/** * @file Find common directory path * @description Single responsibility: Determine shared parent directory */ const path = require('path'); function findCommonDirectory(directories) { if (!directories || directories.length === 0) return '.'; if (directories.length === 1) return directories[0]; // Split all paths into segments const pathSegments = directories.map(dir => dir.split(path.sep)); // Find common segments const commonSegments = []; const minLength = Math.min(...pathSegments.map(s => s.length)); for (let i = 0; i < minLength; i++) { const segment = pathSegments[0][i]; if (pathSegments.every(segments => segments[i] === segment)) { commonSegments.push(segment); } else { break; } } return commonSegments.length > 0 ? commonSegments.join(path.sep) : '.'; } module.exports = findCommonDirectory;