export function join ( ... segments ) { const parts = segments . reduce ( ( parts , segment ) => { if ( parts . length > 0 ) { segment = segment . replace ( /^\// , "" ) ; } segment = segment . replace ( /\/$/ , "" ) ; return [ ... parts , ... segment . split ( "/" ) ] ; } , [ ] ) ; const resultParts = [ ] ; for ( const part of parts ) { if ( part === "." ) { continue ; } if ( part === ".." ) { resultParts . pop ( ) ; continue ; } resultParts . push ( part ) ; } return resultParts . join ( "/" ) ; } export function dirname ( path ) { return join ( path , ".." ) ; }