UNPKG

@nanocollective/nanocoder

Version:

A local-first CLI coding agent that brings the power of agentic coding tools like Claude Code and Gemini CLI to local models or controlled APIs like OpenRouter

51 lines 1.5 kB
import { extname } from 'node:path'; import { FILE_EXTENSION_TO_LANGUAGE } from '../../constants.js'; /** * Get all file paths within a directory node recursively */ export function getAllFilesInDirectory(node) { const files = []; if (!node.isDirectory) { files.push(node.path); } else if (node.children) { for (const child of node.children) { files.push(...getAllFilesInDirectory(child)); } } return files; } /** * Get the highlight.js language name from a file path */ export function getLanguageFromPath(filePath) { const ext = extname(filePath).toLowerCase(); const basename = filePath.split('/').pop()?.toLowerCase() ?? ''; // Check for special filenames if (basename === 'dockerfile') return 'dockerfile'; if (basename === 'makefile') return 'makefile'; return FILE_EXTENSION_TO_LANGUAGE[ext] ?? 'plaintext'; } /** * Format token count for display (e.g., 1500 -> "1.5k") */ export function formatTokens(tokens) { if (tokens >= 1000000) return `${(tokens / 1000000).toFixed(1)}M`; if (tokens >= 1000) return `${(tokens / 1000).toFixed(1)}k`; return String(tokens); } /** * Format file size for display */ export function formatSize(bytes) { if (bytes < 1024) return `${bytes} B`; if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`; return `${(bytes / (1024 * 1024)).toFixed(1)} MB`; } //# sourceMappingURL=utils.js.map