UNPKG

scai

Version:

> AI-powered CLI tool for commit messages **and** pull request reviews — using local models.

24 lines (23 loc) 801 B
// src/utils/normalizePath.ts import os from 'os'; import path from "path"; /** * Normalizes a path string for loose, fuzzy matching: * - Lowercases * - Removes slashes and backslashes * - Removes whitespace */ export function normalizePathForLooseMatch(p) { return p.toLowerCase().replace(/[\\/]/g, '').replace(/\s+/g, ''); } // Helper to normalize and resolve paths to a consistent format (forward slashes) export function normalizePath(p) { if (p.startsWith('~')) { p = path.join(os.homedir(), p.slice(1)); } return path.resolve(p).replace(/\\/g, '/'); } export function getRepoKeyForPath(pathToMatch, config) { const norm = normalizePath(pathToMatch); return Object.entries(config.repos).find(([, val]) => normalizePath(val.indexDir) === norm)?.[0] || null; }