refactor: improve drag interaction and workspace identity normalization
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
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 : "/";
|
||||
}
|
||||
Reference in New Issue
Block a user