Skip to main content
Glama
fileUtils.ts903 B
import path from 'path'; export const fileUtils = { isTextFile(filePath: string): boolean { const textExtensions = [ '.txt', '.md', '.js', '.ts', '.json', '.yaml', '.yml', '.html', '.css', '.csv', '.xml', '.log', '.env', '.jsx', '.tsx', '.py', '.java', '.cpp', '.c', '.h' ]; return textExtensions.includes(path.extname(filePath).toLowerCase()); }, sanitizePath(inputPath: string): string { // Remove any parent directory traversal const normalizedPath = path.normalize(inputPath).replace(/^(\.\.(\/|\\|$))+/, ''); return path.resolve(normalizedPath); }, formatFileSize(bytes: number): string { const units = ['B', 'KB', 'MB', 'GB']; let size = bytes; let unitIndex = 0; while (size >= 1024 && unitIndex < units.length - 1) { size /= 1024; unitIndex++; } return `${size.toFixed(2)} ${units[unitIndex]}`; } };

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/compiledwithproblems/file-context-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server