create URL fallback only when necessary

This commit is contained in:
tophf 2022-01-17 03:53:16 +03:00
parent 12eb243610
commit 14e0a418bf

View File

@ -290,9 +290,11 @@ function tryJSONparse(jsonString) {
} catch (e) {}
}
function tryURL(
url,
fallback = {
function tryURL(url) {
try {
return new URL(url);
} catch (e) {
return {
hash: '',
host: '',
hostname: '',
@ -305,11 +307,7 @@ function tryURL(
search: '',
searchParams: new URLSearchParams(),
username: '',
}) {
try {
return new URL(url);
} catch (e) {
return fallback;
};
}
}