scai
Version:
> **AI-powered CLI for local code analysis, commit message suggestions, and natural-language queries.** 100% local, private, GDPR-friendly, made in Denmark/EU with ❤️.
50 lines (49 loc) • 1.35 kB
JavaScript
import path from 'path';
export function detectFileType(filepathOrExt) {
// If it's already an extension (starts with '.'), use it directly
const ext = filepathOrExt.startsWith(".")
? filepathOrExt.toLowerCase()
: path.extname(filepathOrExt).toLowerCase();
const map = {
".ts": "typescript",
".tsx": "typescript",
".js": "javascript",
".jsx": "javascript",
".java": "java",
".py": "python",
".rb": "ruby",
".php": "php",
".go": "go",
".rs": "rust",
".c": "c",
".cpp": "cpp",
".cs": "csharp",
".swift": "swift",
".kt": "kotlin",
".scala": "scala",
".md": "markdown",
".html": "html",
".htm": "html",
".xml": "xml",
".json": "json",
".yaml": "yaml",
".yml": "yaml",
".ini": "config",
".toml": "config",
".env": "config",
".sql": "sql",
".csv": "csv",
".tsv": "tsv",
".txt": "text",
".log": "log",
".rst": "text",
".doc": "word",
".docx": "word",
".pdf": "pdf",
".ppt": "powerpoint",
".pptx": "powerpoint",
".xls": "excel",
".xlsx": "excel",
};
return map[ext] || ext.replace(".", "") || "unknown";
}