lib/relpath.js
function relpath(basePath, absPath) {
  let base = dedot(basePath);
  let abs = dedot(absPath);
  // Find the longest common prefix that ends with a separator.
  const commonPrefix = longestCommonPathPrefix(base, abs);
  // Remove the common path elements.
  base = apply(substring, base, [ commonPrefix ]);
  abs = apply(substring, abs, [ commonPrefix ]);
  // For each path element in base, output "/..".
  let rel = '.';
  if (base) {
    rel = '..';
    for (let i = 0; (i = apply(indexOf, base, [ sep, i ])) >= 0; ++i) {
      rel = `${ rel }/..`;
    }
  }
  // Append abs.
  if (abs) {
    rel += sep + abs;
  }
  return rel;
}
function relpath(basePath, absPath) {
  let base = dedot(basePath);
  let abs = dedot(absPath);
  // Find the longest common prefix that ends with a separator.
  const commonPrefix = longestCommonPathPrefix(base, abs);
  // Remove the common path elements.
  base = apply(substring, base, [ commonPrefix ]);
  abs = apply(substring, abs, [ commonPrefix ]);
  // For each path element in base, output "/..".
  let rel = '.';
  if (base) {
    rel = '..';
    for (let i = 0; (i = apply(indexOf, base, [ sep, i ])) >= 0; ++i) {
      rel = `${ rel }/..`;
    }
  }
  // Append abs.
  if (abs) {
    rel += sep + abs;
  }
  return rel;
}
function relpath ( basePath , absPath ) { let base = dedot ( basePath ) ; let abs = dedot ( absPath ) ; // Find the longest common prefix that ends with a separator. const commonPrefix = longestCommonPathPrefix ( base , abs ) ; // Remove the common path elements. base = apply ( substring , base , [ commonPrefix ] ) ; abs = apply ( substring , abs , [ commonPrefix ] ) ; // For each path element in base, output "/..". let rel = '.' ; if ( base ) { rel = '..' ; for ( let i = 0 ; ( i = apply ( indexOf , base , [ sep , i ] ) ) >= 0 ; ++ i ) { rel = ` ${ rel } ` ; } } // Append abs. if ( abs ) { rel += sep + abs ; } return rel ; }
A path to absFile relative to base.
This is a string transform so is independent of the
symlink and hardlink structure of the file-system.

@param {string} base an absolute path
@param {string} absPath an absolute path
@return {string} a relative path that starts with '.'
such that {@code path.join(base, output) === absPath}
modulo dot path segments in absPath.
A path to absFile relative to base . This is a string transform so is independent of the symlink and hardlink structure of the file - system .