Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[No QA][TS migration] Migrate 'Url.js' constants dependency to TypeScript #25744

Merged
merged 2 commits into from
Sep 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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};
Loading