Server : nginx/1.18.0 System : Linux localhost 6.14.3-x86_64-linode168 #1 SMP PREEMPT_DYNAMIC Mon Apr 21 19:47:55 EDT 2025 x86_64 User : www-data ( 33) PHP Version : 8.0.16 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, Directory : /var/www/ecommerce/node_modules/relateurl/lib/ |
"use strict";
var constants = require("./constants");
function formatAuth(urlObj, options)
{
if (urlObj.auth && !options.removeAuth && (urlObj.extra.relation.maximumHost || options.output===constants.ABSOLUTE))
{
return urlObj.auth + "@";
}
return "";
}
function formatHash(urlObj, options)
{
return urlObj.hash ? urlObj.hash : "";
}
function formatHost(urlObj, options)
{
if (urlObj.host.full && (urlObj.extra.relation.maximumAuth || options.output===constants.ABSOLUTE))
{
return urlObj.host.full;
}
return "";
}
function formatPath(urlObj, options)
{
var str = "";
var absolutePath = urlObj.path.absolute.string;
var relativePath = urlObj.path.relative.string;
var resource = showResource(urlObj, options);
if (urlObj.extra.relation.maximumHost || options.output===constants.ABSOLUTE || options.output===constants.ROOT_RELATIVE)
{
str = absolutePath;
}
else if (relativePath.length<=absolutePath.length && options.output===constants.SHORTEST || options.output===constants.PATH_RELATIVE)
{
str = relativePath;
if (str === "")
{
var query = showQuery(urlObj,options) && !!getQuery(urlObj,options);
if (urlObj.extra.relation.maximumPath && !resource)
{
str = "./";
}
else if (urlObj.extra.relation.overridesQuery && !resource && !query)
{
str = "./";
}
}
}
else
{
str = absolutePath;
}
if ( str==="/" && !resource && options.removeRootTrailingSlash && (!urlObj.extra.relation.minimumPort || options.output===constants.ABSOLUTE) )
{
str = "";
}
return str;
}
function formatPort(urlObj, options)
{
if (urlObj.port && !urlObj.extra.portIsDefault && urlObj.extra.relation.maximumHost)
{
return ":" + urlObj.port;
}
return "";
}
function formatQuery(urlObj, options)
{
return showQuery(urlObj,options) ? getQuery(urlObj, options) : "";
}
function formatResource(urlObj, options)
{
return showResource(urlObj,options) ? urlObj.resource : "";
}
function formatScheme(urlObj, options)
{
var str = "";
if (urlObj.extra.relation.maximumHost || options.output===constants.ABSOLUTE)
{
if (!urlObj.extra.relation.minimumScheme || !options.schemeRelative || options.output===constants.ABSOLUTE)
{
str += urlObj.scheme + "://";
}
else
{
str += "//";
}
}
return str;
}
function formatUrl(urlObj, options)
{
var url = "";
url += formatScheme(urlObj, options);
url += formatAuth(urlObj, options);
url += formatHost(urlObj, options);
url += formatPort(urlObj, options);
url += formatPath(urlObj, options);
url += formatResource(urlObj, options);
url += formatQuery(urlObj, options);
url += formatHash(urlObj, options);
return url;
}
function getQuery(urlObj, options)
{
var stripQuery = options.removeEmptyQueries && urlObj.extra.relation.minimumPort;
return urlObj.query.string[ stripQuery ? "stripped" : "full" ];
}
function showQuery(urlObj, options)
{
return !urlObj.extra.relation.minimumQuery || options.output===constants.ABSOLUTE || options.output===constants.ROOT_RELATIVE;
}
function showResource(urlObj, options)
{
var removeIndex = options.removeDirectoryIndexes && urlObj.extra.resourceIsIndex;
var removeMatchingResource = urlObj.extra.relation.minimumResource && options.output!==constants.ABSOLUTE && options.output!==constants.ROOT_RELATIVE;
return !!urlObj.resource && !removeMatchingResource && !removeIndex;
}
module.exports = formatUrl;