| import { EXTENSION_MAP, EXCLUDED_DIRECTORIES, FRONTEND_EXTENSIONS } from './constants.js'; |
|
|
| |
| |
| |
| export function estimateTokens(text: string): number { |
| return Math.ceil(text.length / 4); |
| } |
|
|
| |
| |
| |
| export function getLanguageFromPath(filePath: string): string { |
| const ext = filePath.slice(filePath.lastIndexOf('.')); |
| return EXTENSION_MAP[ext] || 'plaintext'; |
| } |
|
|
| |
| |
| |
| export function getFileExtension(filePath: string): string { |
| const dotIndex = filePath.lastIndexOf('.'); |
| return dotIndex >= 0 ? filePath.slice(dotIndex) : ''; |
| } |
|
|
| |
| |
| |
| export function getFileName(filePath: string): string { |
| return filePath.split('/').pop() || filePath; |
| } |
|
|
| |
| |
| |
| export function isFrontendFile(filePath: string): boolean { |
| const ext = getFileExtension(filePath); |
| return FRONTEND_EXTENSIONS.has(ext); |
| } |
|
|
| |
| |
| |
| export function isExcludedDirectory(dirName: string): boolean { |
| return EXCLUDED_DIRECTORIES.has(dirName); |
| } |
|
|
| |
| |
| |
| export function isBinaryFile(filePath: string): boolean { |
| const binaryExtensions = new Set([ |
| '.png', '.jpg', '.jpeg', '.gif', '.bmp', '.ico', '.webp', '.avif', |
| '.mp4', '.webm', '.mov', '.avi', |
| '.mp3', '.wav', '.ogg', '.flac', |
| '.woff', '.woff2', '.ttf', '.otf', '.eot', |
| '.zip', '.tar', '.gz', '.rar', '.7z', |
| '.pdf', '.doc', '.docx', '.xls', '.xlsx', |
| '.exe', '.dll', '.so', '.dylib', |
| ]); |
| return binaryExtensions.has(getFileExtension(filePath).toLowerCase()); |
| } |
|
|
| |
| |
| |
| export function truncateLines(text: string, maxLines: number): string { |
| const lines = text.split('\n'); |
| if (lines.length <= maxLines) return text; |
| return lines.slice(0, maxLines).join('\n') + '\n// ... [truncated]'; |
| } |
|
|
| |
| |
| |
| export function generateId(): string { |
| return `${Date.now()}-${Math.random().toString(36).substring(2, 11)}`; |
| } |
|
|