Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function getURLPathAndQuery(url: string): string | undefined {
const urlParsed = URLBuilder.parse(url);
const pathString = urlParsed.getPath();
if (!pathString) {
throw new RangeError("Invalid url without valid path.");
}
let queryString = urlParsed.getQuery() || "";
queryString = queryString.trim();
if (queryString != "") {
queryString = queryString.startsWith("?") ? queryString : `?${queryString}`; // Ensure query string start with '?'
}
return `${pathString}${queryString}`;
}
export function getURLParameter(url: string, name: string): string | string[] | undefined {
const urlParsed = URLBuilder.parse(url);
return urlParsed.getQueryParameterValue(name);
}
export function getURLScheme(url: string): string | undefined {
const urlParsed = URLBuilder.parse(url);
return urlParsed.getScheme();
}
export function escapeURLPath(url: string): string {
const urlParsed = URLBuilder.parse(url);
let path = urlParsed.getPath();
path = path || "/";
path = escape(path);
urlParsed.setPath(path);
return urlParsed.toString();
}
export function getURLPath(url: string): string | undefined {
const urlParsed = URLBuilder.parse(url);
return urlParsed.getPath();
}
export function getURLParameter(url: string, name: string): string | string[] | undefined {
const urlParsed = URLBuilder.parse(url);
return urlParsed.getQueryParameterValue(name);
}
export function setURLParameter(url: string, name: string, value?: string): string {
const urlParsed = URLBuilder.parse(url);
urlParsed.setQueryParameter(name, value);
return urlParsed.toString();
}
export function setURLHost(url: string, host: string): string {
const urlParsed = URLBuilder.parse(url);
urlParsed.setHost(host);
return urlParsed.toString();
}
export function getURLParameter(url: string, name: string): string | string[] | undefined {
const urlParsed = URLBuilder.parse(url);
return urlParsed.getQueryParameterValue(name);
}