react-native-international-phone-number 0.8.1 → 0.8.2

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
@@ -198,7 +198,7 @@ const PhoneInput = forwardRef(
198
198
  callingCode ? callingCode : countryValue?.callingCode,
199
199
  countryValue?.cca2,
200
200
  customMask ? customMask : null,
201
- allowZeroAfterCallingCode
201
+ allowZeroAfterCallingCode === false ? false : true
202
202
  );
203
203
 
204
204
  if (ref) {
@@ -1,10 +1,16 @@
1
1
  import { countries } from '../constants/countries';
2
2
 
3
- function eliminateZeroAfterCallingCode(phoneNumber, callingCode) {
3
+ function startsWithZero(phoneNumber, callingCode) {
4
4
  const newCode = callingCode.replace('+', '');
5
- return phoneNumber.startsWith('0') ||
5
+ return (
6
+ phoneNumber.startsWith('0') ||
6
7
  phoneNumber.startsWith(`${newCode}0`)
7
- ? phoneNumber.slice(newCode.length + 1, phoneNumber.length)
8
+ );
9
+ }
10
+
11
+ function eliminateZeroAfterCallingCode(phoneNumber, callingCode) {
12
+ return startsWithZero(phoneNumber, callingCode)
13
+ ? phoneNumber.slice(1, phoneNumber.length)
8
14
  : phoneNumber;
9
15
  }
10
16
 
@@ -73,7 +79,12 @@ export default function getInputMask(
73
79
  ? value
74
80
  : eliminateZeroAfterCallingCode(value, callingCode);
75
81
 
76
- return matrix.replace(/(?!\+)./g, function (a) {
82
+ const newMatrix =
83
+ allowZeroAfterCallingCode && startsWithZero(value, callingCode)
84
+ ? '#' + matrix
85
+ : matrix;
86
+
87
+ return newMatrix.replace(/(?!\+)./g, function (a) {
77
88
  return /[#\d]/.test(a) && i < newValue.length
78
89
  ? newValue.charAt(i++)
79
90
  : i >= newValue.length
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.8.1",
4
+ "version": "0.8.2",
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",