From 613ac145c6fc1acd66aa8bebc809850b99c3dd5a Mon Sep 17 00:00:00 2001 From: "P. Reis" Date: Fri, 24 May 2024 13:55:05 -0300 Subject: [PATCH] refactor: rename variables and remove useless if statement --- src/utils/accounts.ts | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/utils/accounts.ts b/src/utils/accounts.ts index a320c581..66737474 100644 --- a/src/utils/accounts.ts +++ b/src/utils/accounts.ts @@ -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;