From 90fb20b6c85230b9513410984ebb1b58f8393f9c Mon Sep 17 00:00:00 2001 From: Blazej Kustra Date: Wed, 23 Aug 2023 08:36:51 +0200 Subject: [PATCH 1/2] [TS migration] Migrate 'Url.js' constants dependency to TypeScript --- src/libs/{Url.js => Url.ts} | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) rename src/libs/{Url.js => Url.ts} (65%) diff --git a/src/libs/Url.js b/src/libs/Url.ts similarity index 65% rename from src/libs/Url.js rename to src/libs/Url.ts index eb96b697a8fc..65b78ad32bf7 100644 --- a/src/libs/Url.js +++ b/src/libs/Url.ts @@ -1,10 +1,9 @@ import 'react-native-url-polyfill/auto'; + /** * Add / to the end of any URL if not present - * @param {String} url - * @returns {String} */ -function addTrailingForwardSlash(url) { +function addTrailingForwardSlash(url: string): string { if (!url.endsWith('/')) { return `${url}/`; } @@ -13,10 +12,8 @@ function addTrailingForwardSlash(url) { /** * Get path from URL string - * @param {String} url - * @returns {String} */ -function getPathFromURL(url) { +function getPathFromURL(url: string): string { try { const parsedUrl = new URL(url); const path = parsedUrl.pathname + parsedUrl.search + parsedUrl.hash; @@ -29,12 +26,9 @@ function getPathFromURL(url) { /** * Determine if two urls have the same origin - * @param {String} url1 - * @param {String} url2 - * @returns {Boolean} */ -function hasSameExpensifyOrigin(url1, url2) { - const removeW3 = (host) => host.replace(/^www\./i, ''); +function hasSameExpensifyOrigin(url1: string, url2: string): boolean { + const removeW3 = (host: string): string => host.replace(/^www\./i, ''); try { const parsedUrl1 = new URL(url1); const parsedUrl2 = new URL(url2); @@ -47,9 +41,4 @@ function hasSameExpensifyOrigin(url1, url2) { } } -export { - // eslint-disable-next-line import/prefer-default-export - addTrailingForwardSlash, - hasSameExpensifyOrigin, - getPathFromURL, -}; +export {addTrailingForwardSlash, hasSameExpensifyOrigin, getPathFromURL}; From e38c99fff3d3d574c181c7569487125e7c9dc034 Mon Sep 17 00:00:00 2001 From: Blazej Kustra Date: Wed, 23 Aug 2023 11:29:48 +0200 Subject: [PATCH 2/2] Use inferred return type for a simple function --- src/libs/Url.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/Url.ts b/src/libs/Url.ts index 65b78ad32bf7..a21f007e8468 100644 --- a/src/libs/Url.ts +++ b/src/libs/Url.ts @@ -28,7 +28,7 @@ function getPathFromURL(url: string): string { * Determine if two urls have the same origin */ function hasSameExpensifyOrigin(url1: string, url2: string): boolean { - const removeW3 = (host: string): string => host.replace(/^www\./i, ''); + const removeW3 = (host: string) => host.replace(/^www\./i, ''); try { const parsedUrl1 = new URL(url1); const parsedUrl2 = new URL(url2);