mirror of
https://github.com/getpaseo/paseo.git
synced 2026-07-29 12:01:31 +00:00
21 lines
655 B
TypeScript
21 lines
655 B
TypeScript
function trimNonEmpty(value: string | null | undefined): string | null {
|
|
if (typeof value !== "string") {
|
|
return null;
|
|
}
|
|
const trimmed = value.trim();
|
|
return trimmed.length > 0 ? trimmed : null;
|
|
}
|
|
|
|
export function normalizeWorkspaceIdentity(value: string | null | undefined): string | null {
|
|
const trimmed = trimNonEmpty(value);
|
|
if (!trimmed) {
|
|
return null;
|
|
}
|
|
const withUnixSeparators = trimmed.replace(/\\/g, "/");
|
|
if (withUnixSeparators === "/") {
|
|
return withUnixSeparators;
|
|
}
|
|
const withoutTrailingSlash = withUnixSeparators.replace(/\/+$/, "");
|
|
return withoutTrailingSlash.length > 0 ? withoutTrailingSlash : "/";
|
|
}
|