keycloak-scim/js/apps/admin-ui/src/utils/joinPath.ts

22 lines
575 B
TypeScript

const PATH_SEPARATOR = "/";
export function joinPath(...paths: string[]) {
const normalizedPaths = paths.map((path, index) => {
const isFirst = index === 0;
const isLast = index === paths.length - 1;
// Strip out any leading slashes from the path.
if (!isFirst && path.startsWith(PATH_SEPARATOR)) {
path = path.slice(1);
}
// Strip out any trailing slashes from the path.
if (!isLast && path.endsWith(PATH_SEPARATOR)) {
path = path.slice(0, -1);
}
return path;
}, []);
return normalizedPaths.join(PATH_SEPARATOR);
}