Skip to content

Commit

Permalink
Merge pull request #25744 from software-mansion-labs/ts-migration/url
Browse files Browse the repository at this point in the history
[No QA][TS migration] Migrate 'Url.js' constants dependency to TypeScript
  • Loading branch information
danieldoglas authored Sep 11, 2023
2 parents 393475b + e38c99f commit bfc6468
Showing 1 changed file with 6 additions and 17 deletions.
23 changes: 6 additions & 17 deletions src/libs/Url.js → src/libs/Url.ts
Original file line number Diff line number Diff line change
@@ -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}/`;
}
Expand All @@ -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;
Expand All @@ -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) => host.replace(/^www\./i, '');
try {
const parsedUrl1 = new URL(url1);
const parsedUrl2 = new URL(url2);
Expand All @@ -47,9 +41,4 @@ function hasSameExpensifyOrigin(url1, url2) {
}
}

export {
// eslint-disable-next-line import/prefer-default-export
addTrailingForwardSlash,
hasSameExpensifyOrigin,
getPathFromURL,
};
export {addTrailingForwardSlash, hasSameExpensifyOrigin, getPathFromURL};

0 comments on commit bfc6468

Please sign in to comment.