react-native-international-phone-number 0.10.4 → 0.10.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -213,8 +213,9 @@ const PhoneInput = forwardRef(
213
213
  let formattedNumber = '';
214
214
 
215
215
  const metadata = new Metadata();
216
- metadata.selectNumberingPlan(selectedCountry.cca2);
217
- const possibleLengths = metadata.possibleLengths();
216
+ metadata.selectNumberingPlan(selectedCountry?.cca2);
217
+
218
+ const possibleLengths = selectedCountry ? metadata.possibleLengths() : [];
218
219
 
219
220
  let validCallingCode = callingCode
220
221
  ? callingCode
@@ -1,10 +1,22 @@
1
1
  import parsePhoneNumber from 'libphonenumber-js';
2
- import {getCountryByCca2} from 'react-native-country-select';
2
+ import {
3
+ getCountryByCca2,
4
+ getCountriesByCallingCode,
5
+ } from 'react-native-country-select';
3
6
 
4
7
  export default function getCountryByPhoneNumber(phoneNumber) {
5
- const matchingCountry = getCountryByCca2(
6
- parsePhoneNumber(phoneNumber)?.getPossibleCountries()[0],
7
- );
8
+ const country = parsePhoneNumber(phoneNumber)?.getPossibleCountries()[0];
9
+ let matchingCountry = getCountryByCca2(country);
10
+
11
+ if (!matchingCountry) {
12
+ const callingCode = parsePhoneNumber(
13
+ phoneNumber,
14
+ )?.countryCallingCode.includes('+')
15
+ ? parsePhoneNumber(phoneNumber)?.countryCallingCode
16
+ : `+${parsePhoneNumber(phoneNumber)?.countryCallingCode}`;
17
+
18
+ matchingCountry = getCountriesByCallingCode(callingCode)[0];
19
+ }
8
20
 
9
21
  return matchingCountry;
10
22
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react-native-international-phone-number",
3
3
  "author": "AstrOOnauta (https://github.com/AstrOOnauta)",
4
- "version": "0.10.4",
4
+ "version": "0.10.5",
5
5
  "description": "International mobile phone input component with mask for React Native",
6
6
  "main": "lib/index.js",
7
7
  "types": "lib/index.d.ts",