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 getURLQueries(url: string): { [key: string]: string } {
let queryString = URLBuilder.parse(url).getQuery();
if (!queryString) {
return {};
}
queryString = queryString.trim();
queryString = queryString.startsWith("?") ? queryString.substr(1) : queryString;
let querySubStrings: string[] = queryString.split("&");
querySubStrings = querySubStrings.filter((value: string) => {
const indexOfEqual = value.indexOf("=");
const lastIndexOfEqual = value.lastIndexOf("=");
return (
indexOfEqual > 0 && indexOfEqual === lastIndexOfEqual
);
});
export function getURLPath(url: string): string | undefined {
const urlParsed = URLBuilder.parse(url);
return urlParsed.getPath();
}
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 setURLHost(url: string, host: string): string {
const urlParsed = URLBuilder.parse(url);
urlParsed.setHost(host);
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);
}
export function getURLPath(url: string): string | undefined {
const urlParsed = URLBuilder.parse(url);
return urlParsed.getPath();
}
export function appendToURLPath(url: string, name: string): string {
const urlParsed = URLBuilder.parse(url);
let path = urlParsed.getPath();
path = path ? (path.endsWith("/") ? `${path}${name}` : `${path}/${name}`) : name;
urlParsed.setPath(path);
return urlParsed.toString();
}
export function appendToURLPath(url: string, name: string): string {
const urlParsed = URLBuilder.parse(url);
let path = urlParsed.getPath();
path = path
? path.endsWith("/")
? `${path}${name}`
: `${path}/${name}`
: name;
urlParsed.setPath(path);
return urlParsed.toString();
}
export function getURLParameter(url: string, name: string): string | string[] | undefined {
const urlParsed = URLBuilder.parse(url);
return urlParsed.getQueryParameterValue(name);
}