refactor: move filter fn as separate isValidPath

This commit is contained in:
Shivam Mishra
2024-06-05 09:09:52 +05:30
parent 1336b0c750
commit 4f7d1a67cf
+7 -9
View File
@@ -1,12 +1,10 @@
const sanitizePaths = paths => {
return paths.filter(path => {
if (!path) return false;
if (path === null && path === '') return false;
// if path is just a sequence of slashes
if (/^\/+$/.test(path)) return false;
const isValidPath = path => {
if (!path) return false;
if (path === null && path === '') return false;
// if path is just a sequence of slashes
if (/^\/+$/.test(path)) return false;
return true;
});
return true;
};
/**
@@ -20,7 +18,7 @@ const sanitizePaths = paths => {
export function joinUrl(baseUrl, ...paths) {
// remove empty undefined and null path items
// also handle if the path is just a slash or just multiple slashes only
const sanitizedPaths = sanitizePaths(paths);
const sanitizedPaths = paths.filter(isValidPath);
const fullUrl = sanitizedPaths.reduce(
(acc, path) => {