mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
refactor: rename variables and remove useless if statement
This commit is contained in:
parent
e3ff41f31f
commit
613ac145c6
1 changed files with 3 additions and 8 deletions
|
|
@ -1,23 +1,18 @@
|
|||
function sanitizeWebsite(website: string | undefined): string | undefined {
|
||||
if (!website) return undefined;
|
||||
|
||||
if (
|
||||
'https://'.includes(website) ||
|
||||
'http://'.includes(website)
|
||||
) return undefined;
|
||||
|
||||
try {
|
||||
// See if 'website' is a valid url
|
||||
new URL(website);
|
||||
return website;
|
||||
} catch (_) {
|
||||
try {
|
||||
const websiteWithPrefix = 'https://' + website;
|
||||
const prefixed = 'https://' + website;
|
||||
// 'website' could still be a valid url
|
||||
// try adding a 'https' prefix to 'website'
|
||||
new URL(websiteWithPrefix);
|
||||
new URL(prefixed);
|
||||
|
||||
return websiteWithPrefix;
|
||||
return prefixed;
|
||||
} catch (_) {
|
||||
// 'website' is not a valid url even with 'https' prefix
|
||||
return undefined;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue