mirror of
https://github.com/murashit/codex-panel.git
synced 2026-07-22 17:30:31 +00:00
11 lines
603 B
TypeScript
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));
|
|
}
|