From 1462a6d5aaff1ca9fc291b9eade45e1a9549e875 Mon Sep 17 00:00:00 2001 From: Bartosz Grajdek Date: Sun, 17 Sep 2023 19:33:47 +0200 Subject: [PATCH] [TS migration] Migrate 'LocalePhoneNumber.js' lib to TypeScript --- .../{LocalePhoneNumber.js => LocalePhoneNumber.ts} | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) rename src/libs/{LocalePhoneNumber.js => LocalePhoneNumber.ts} (82%) diff --git a/src/libs/LocalePhoneNumber.js b/src/libs/LocalePhoneNumber.ts similarity index 82% rename from src/libs/LocalePhoneNumber.js rename to src/libs/LocalePhoneNumber.ts index e5c7cbfa45ba..962040aee049 100644 --- a/src/libs/LocalePhoneNumber.js +++ b/src/libs/LocalePhoneNumber.ts @@ -3,20 +3,17 @@ import Str from 'expensify-common/lib/str'; import {parsePhoneNumber} from 'awesome-phonenumber'; import ONYXKEYS from '../ONYXKEYS'; -let countryCodeByIP; +let countryCodeByIP: number; Onyx.connect({ key: ONYXKEYS.COUNTRY_CODE, - callback: (val) => (countryCodeByIP = val || 1), + callback: (val) => (countryCodeByIP = val ?? 1), }); /** * Returns a locally converted phone number for numbers from the same region * and an internationally converted phone number with the country code for numbers from other regions - * - * @param {String} number - * @returns {String} */ -function formatPhoneNumber(number) { +function formatPhoneNumber(number: string): string { if (!number) { return ''; } @@ -26,7 +23,7 @@ function formatPhoneNumber(number) { // return the string untouched if it's not a phone number if (!parsedPhoneNumber.valid) { - if (parsedPhoneNumber.number && parsedPhoneNumber.number.international) { + if (parsedPhoneNumber.number?.international) { return parsedPhoneNumber.number.international; } return numberWithoutSMSDomain;