murashit_codex-panel/src/features/chat/display/paths.ts
2026-05-23 09:42:42 +09:00

11 lines
603 B
TypeScript

export function pathRelativeToRoot(path: string, root?: string | null): string {
const normalizedPath = path.replace(/\\/g, "/").replace(/^\.\//, "");
const normalizedRoot = root?.replace(/\\/g, "/").replace(/\/+$/, "");
if (!normalizedRoot) return normalizedPath;
if (normalizedPath === normalizedRoot) return ".";
return normalizedPath.startsWith(`${normalizedRoot}/`) ? normalizedPath.slice(normalizedRoot.length + 1) : normalizedPath;
}
export function pathsRelativeToRoot(paths: string[], root?: string | null): string[] {
return paths.map((path) => pathRelativeToRoot(path, root));
}