src/basis.js
function(from, to){
        // it makes function useful with array iterate methods, i.e.
        // ['foo', 'bar'].map(basis.path.relative)
        if (typeof to != 'string')
        {
          to = from;
          from = baseURI;
        }

        from = utils.normalize(from);
        to = utils.normalize(to);

        if (from[0] == '/' && to[0] != '/')
          return from;
        if (to[0] == '/' && from[0] != '/')
          return to;

        var base = from.replace(/^\/$/, '').split(/\//);
        var path = to.replace(/^\/$/, '').split(/\//);
        var result = [];
        var i = 0;

        while (path[i] == base[i] && typeof base[i] == 'string')
          i++;

        for (var j = base.length - i; j > 0; j--)
          result.push('..');

        return result.concat(path.slice(i).filter(Boolean)).join('/');
      }
function(from, to){
        // it makes function useful with array iterate methods, i.e.
        // ['foo', 'bar'].map(basis.path.relative)
        if (typeof to != 'string')
        {
          to = from;
          from = baseURI;
        }

        from = utils.normalize(from);
        to = utils.normalize(to);

        if (from[0] == '/' && to[0] != '/')
          return from;
        if (to[0] == '/' && from[0] != '/')
          return to;

        var base = from.replace(/^\/$/, '').split(/\//);
        var path = to.replace(/^\/$/, '').split(/\//);
        var result = [];
        var i = 0;

        while (path[i] == base[i] && typeof base[i] == 'string')
          i++;

        for (var j = base.length - i; j > 0; j--)
          result.push('..');

        return result.concat(path.slice(i).filter(Boolean)).join('/');
      }
function ( from , to ) { // it makes function useful with array iterate methods, i.e. // ['foo', 'bar'].map(basis.path.relative) if ( typeof to != 'string' ) { to = from ; from = baseURI ; } from = utils . normalize ( from ) ; to = utils . normalize ( to ) ; if ( from [ 0 ] == '/' && to [ 0 ] != '/' ) return from ; if ( to [ 0 ] == '/' && from [ 0 ] != '/' ) return to ; var base = from . replace ( / ^\/$ / , '' ) . split ( / \/ / ) ; var path = to . replace ( / ^\/$ / , '' ) . split ( / \/ / ) ; var result = [ ] ; var i = 0 ; while ( path [ i ] == base [ i ] && typeof base [ i ] == 'string' ) i ++ ; for ( var j = base . length - i ; j > 0 ; j -- ) result . push ( '..' ) ; return result . concat ( path . slice ( i ) . filter ( Boolean ) ) . join ( '/' ) ; }
Solve the relative path from from to to.

At times we have two absolute paths, and we need to derive the
relative path from one to the other. This is actually the reverse
transform of {basis.path.resolve}, which means we see that:

basis.path.resolve(from, basis.path.relative(from, to)) == basis.path.resolve(to)

If `to` argument omitted than resolve `from` relative to current baseURI.

Function also could be used with Array#map method as well. In this case
every array member resolves to current baseURI.

@example
basis.path.relative('/data/orandea/test/aaa', '/data/orandea/impl/bbb');
// returns '../../impl/bbb'

['foo', '/a/b/bar', 'a/b/baz'].map(basis.path.relative);
// if baseURI is '/a/b' it produces
// ['../../foo', 'bar', '../../a/b/baz']

@param {string} from
@param {string=} to
@return {string}
Solve the relative path from from to to .