Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const parseUrl: UrlParser = (url: string): Endpoint => {
const { hostname, pathname, port, protocol, search } = new URL(url);
let query: QueryParameterBag | undefined;
if (search) {
query = parseQueryString(search);
}
return {
hostname,
port: port ? parseInt(port) : undefined,
protocol,
path: pathname,
query
};
};
export const parseUrl: UrlParser = (url: string): Endpoint => {
const {
hostname = "localhost",
pathname = "/",
port,
protocol = "https:",
search
} = parse(url);
let query: QueryParameterBag | undefined;
if (search) {
query = parseQueryString(search);
}
return {
hostname,
port: port ? parseInt(port) : undefined,
protocol,
path: pathname,
query
};
};