core-api: simplify joinPaths

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2021-03-07 23:16:11 +01:00
parent a3ed283ce2
commit a7967040f4
+4 -16
View File
@@ -31,23 +31,11 @@ import { isExternalRouteRef } from './ExternalRouteRef';
// Joins a list of paths together, avoiding trailing and duplicate slashes
function joinPaths(...paths: string[]): string {
const joined = paths
.map(path => {
let ret = path;
if (path.endsWith('/')) {
ret = path.slice(0, -1);
}
if (!path.startsWith('/')) {
ret = `/${ret}`;
}
return ret;
})
.join('');
if (joined !== '/' && joined.endsWith('/')) {
return joined.slice(0, -1);
const normalized = paths.join('/').replace(/\/\/+/g, '/');
if (normalized !== '/' && normalized.endsWith('/')) {
return normalized.slice(0, -1);
}
return joined;
return normalized;
}
/**