2020-08-29 06:34:20 +02:00
|
|
|
export function removeTrailingSlash(url) {
|
2020-09-01 05:25:31 +02:00
|
|
|
return url && url.length > 1 && url.endsWith('/') ? url.slice(0, -1) : url;
|
2020-08-29 06:34:20 +02:00
|
|
|
}
|
|
|
|
|
2020-09-16 06:25:51 +02:00
|
|
|
export function removeWWW(url) {
|
|
|
|
return url && url.length > 1 && url.startsWith('www.') ? url.slice(4) : url;
|
|
|
|
}
|
|
|
|
|
2020-08-29 06:34:20 +02:00
|
|
|
export function getDomainName(str) {
|
|
|
|
try {
|
|
|
|
return new URL(str).hostname;
|
2020-09-01 05:25:31 +02:00
|
|
|
} catch (e) {
|
2020-08-29 06:34:20 +02:00
|
|
|
return str;
|
|
|
|
}
|
|
|
|
}
|
2020-09-26 07:31:18 +02:00
|
|
|
|
|
|
|
export function getQueryString(params) {
|
|
|
|
const map = Object.keys(params).reduce((arr, key) => {
|
|
|
|
if (params[key] !== undefined) {
|
|
|
|
return arr.concat(`${key}=${encodeURIComponent(params[key])}`);
|
|
|
|
}
|
|
|
|
return arr;
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
if (map.length) {
|
|
|
|
return `?${map.join('&')}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
return '';
|
|
|
|
}
|