Skip to content

Commit

Permalink
[TS migration] Migrate 'LocalePhoneNumber.js' lib to TypeScript
Browse files Browse the repository at this point in the history
  • Loading branch information
BartoszGrajdek committed Sep 17, 2023
1 parent 2ed276b commit 1462a6d
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/libs/LocalePhoneNumber.js → src/libs/LocalePhoneNumber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 '';
}
Expand All @@ -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;
Expand Down

0 comments on commit 1462a6d

Please sign in to comment.