mirror of
https://github.com/getpaseo/paseo.git
synced 2026-07-29 12:01:31 +00:00
18 lines
467 B
TypeScript
18 lines
467 B
TypeScript
export function stripCwdPrefix(filePath: string, cwd?: string): string {
|
|
if (!cwd || !filePath) {
|
|
return filePath;
|
|
}
|
|
|
|
const normalizedCwd = cwd.replace(/\\/g, "/").replace(/\/+$/, "");
|
|
const normalizedPath = filePath.replace(/\\/g, "/");
|
|
const prefix = `${normalizedCwd}/`;
|
|
|
|
if (normalizedPath.startsWith(prefix)) {
|
|
return normalizedPath.slice(prefix.length);
|
|
}
|
|
if (normalizedPath === normalizedCwd) {
|
|
return ".";
|
|
}
|
|
return filePath;
|
|
}
|