lib/utils.js
function getSourcepath(filepath, htmlpath, rootpath) {
  if (!filepath) {
    return ['', ''];
  }

  if (isRemoteFilepath(filepath)) {
    const url = new URL(filepath);

    filepath = `./${url.pathname.slice(1).replace(RE_FORWARD_SLASH, '_')}`;
  }
  // Strip query params
  filepath = filepath.replace(RE_QUERY, '');
  // Relative path
  if (htmlpath && isRelativeFilepath(filepath)) {
    filepath = path.resolve(path.dirname(htmlpath), filepath);
    // Strip leading '/'
  } else if (filepath.indexOf('/') == 0) {
    filepath = filepath.slice(1);
  }
  if (filepath.includes('#')) {
    filepath = filepath.split('#');
  }

  return Array.isArray(filepath)
    ? [path.resolve(rootpath, filepath[0]), filepath[1]]
    : [path.resolve(rootpath, filepath), ''];
}
function getSourcepath(filepath, htmlpath, rootpath) {
  if (!filepath) {
    return ['', ''];
  }

  if (isRemoteFilepath(filepath)) {
    const url = new URL(filepath);

    filepath = `./${url.pathname.slice(1).replace(RE_FORWARD_SLASH, '_')}`;
  }
  // Strip query params
  filepath = filepath.replace(RE_QUERY, '');
  // Relative path
  if (htmlpath && isRelativeFilepath(filepath)) {
    filepath = path.resolve(path.dirname(htmlpath), filepath);
    // Strip leading '/'
  } else if (filepath.indexOf('/') == 0) {
    filepath = filepath.slice(1);
  }
  if (filepath.includes('#')) {
    filepath = filepath.split('#');
  }

  return Array.isArray(filepath)
    ? [path.resolve(rootpath, filepath[0]), filepath[1]]
    : [path.resolve(rootpath, filepath), ''];
}
function getSourcepath ( filepath , htmlpath , rootpath ) { if ( ! filepath ) { return [ '' , '' ] ; } if ( isRemoteFilepath ( filepath ) ) { const url = new URL ( filepath ) ; filepath = ` ${ url . pathname . slice ( 1 ) . replace ( RE_FORWARD_SLASH , '_' ) } ` ; } // Strip query params filepath = filepath . replace ( RE_QUERY , '' ) ; // Relative path if ( htmlpath && isRelativeFilepath ( filepath ) ) { filepath = path . resolve ( path . dirname ( htmlpath ) , filepath ) ; // Strip leading '/' } else if ( filepath . indexOf ( '/' ) == 0 ) { filepath = filepath . slice ( 1 ) ; } if ( filepath . includes ( '#' ) ) { filepath = filepath . split ( '#' ) ; } return Array . isArray ( filepath ) ? [ path . resolve ( rootpath , filepath [ 0 ] ) , filepath [ 1 ] ] : [ path . resolve ( rootpath , filepath ) , '' ] ; }
Retrieve resolved 'filepath' and optional anchor
@param {String} filepath
@param {String} htmlpath
@param {String} rootpath
@returns {Array}
Retrieve resolved filepath and optional anchor