src/basis.js
function(path){
        path = (path || '')
              .replace(PROTOCOL_RX, '/')
              .replace(ORIGIN_RX, '/')        // but cut off origin
              .replace(SEARCH_HASH_RX, '');   // cut off query search and hash

        // use link element as path resolver
        var result = [];
        var parts = path.split('/');             // split

        // process path parts
        for (var i = 0; i < parts.length; i++)
        {
          if (parts[i] == '..')
          {
            if (result.length > 1 || result[0])
              result.pop();
          }
          else
          {
            if ((parts[i] || !i) && parts[i] != '.')
              result.push(parts[i]);
          }
        }

        return result.join('/') ||
               (path[0] === '/' ? '/' : '');
      }
function(path){
        path = (path || '')
              .replace(PROTOCOL_RX, '/')
              .replace(ORIGIN_RX, '/')        // but cut off origin
              .replace(SEARCH_HASH_RX, '');   // cut off query search and hash

        // use link element as path resolver
        var result = [];
        var parts = path.split('/');             // split

        // process path parts
        for (var i = 0; i < parts.length; i++)
        {
          if (parts[i] == '..')
          {
            if (result.length > 1 || result[0])
              result.pop();
          }
          else
          {
            if ((parts[i] || !i) && parts[i] != '.')
              result.push(parts[i]);
          }
        }

        return result.join('/') ||
               (path[0] === '/' ? '/' : '');
      }
function ( path ) { path = ( path || '' ) . replace ( PROTOCOL_RX , '/' ) . replace ( ORIGIN_RX , '/' ) // but cut off origin . replace ( SEARCH_HASH_RX , '' ) ; // cut off query search and hash // use link element as path resolver var result = [ ] ; var parts = path . split ( '/' ) ; // split // process path parts for ( var i = 0 ; i < parts . length ; i ++ ) { if ( parts [ i ] == '..' ) { if ( result . length > 1 || result [ 0 ] ) result . pop ( ) ; } else { if ( ( parts [ i ] || ! i ) && parts [ i ] != '.' ) result . push ( parts [ i ] ) ; } } return result . join ( '/' ) || ( path [ 0 ] === '/' ? '/' : '' ) ; }
Normalize a string path, taking care of '..' and '.' parts.
When multiple slashes are found, they're replaced by a single one;
when the path contains a trailing slash, it is preserved.

Origin is not includes in result path.

@example
basis.path.normalize('/foo/bar//baz/asdf/quux/..');
// returns '/foo/bar/baz/asdf'

basis.path.normalize('http://example.com:8080/foo//..//bar/');
// returns '/bar'

basis.path.normalize('//localhost/foo/./..//bar/');
// returns '/bar'

@param {string} path
@return {string}
Normalize a string path taking care of .. and . parts . When multiple slashes are found they re replaced by a single one ; when the path contains a trailing slash it is preserved .