param strArray returns function joinPath ( ... strArray ) { if ( strArray . length === 0 ) { return '' ; } const resultArray = [ ] ; const filterStrArray = strArray . filter ( str => str !== '' ) ; filterStrArray . forEach ( ( str , index ) => { if ( typeof str !== 'string' ) { throw new Error ( `Path must be a string. Received ${ str }` ) ; } let routePath = str ; if ( index > 0 ) { routePath = routePath . replace ( /^[/]+/ , '' ) ; } if ( index < filterStrArray . length - 1 ) { routePath = routePath . replace ( /[/]+$/ , '' ) ; } else { routePath = routePath . replace ( /[/]+$/ , '/' ) ; } resultArray . push ( routePath ) ; } ) ; return resultArray . join ( '/' ) ; } export default joinPath ;