refactor: move filter fn as separate isValidPath
This commit is contained in:
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user