react-native-phone-country-input 1.0.0

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.
Files changed (172) hide show
  1. package/README.md +477 -0
  2. package/lib/commonjs/CountrySelector/CountrySelector.js +74 -0
  3. package/lib/commonjs/CountrySelector/CountrySelector.js.map +1 -0
  4. package/lib/commonjs/CountrySelector/CountrySelectorModal.js +267 -0
  5. package/lib/commonjs/CountrySelector/CountrySelectorModal.js.map +1 -0
  6. package/lib/commonjs/Keyboard/Keyboard.js +316 -0
  7. package/lib/commonjs/Keyboard/Keyboard.js.map +1 -0
  8. package/lib/commonjs/Keyboard/KeyboardToolbar.js +70 -0
  9. package/lib/commonjs/Keyboard/KeyboardToolbar.js.map +1 -0
  10. package/lib/commonjs/Keyboard/KeypadButton.js +66 -0
  11. package/lib/commonjs/Keyboard/KeypadButton.js.map +1 -0
  12. package/lib/commonjs/Keyboard/KeypadButtonContainer.js +65 -0
  13. package/lib/commonjs/Keyboard/KeypadButtonContainer.js.map +1 -0
  14. package/lib/commonjs/Keyboard/KeypadRow.js +34 -0
  15. package/lib/commonjs/Keyboard/KeypadRow.js.map +1 -0
  16. package/lib/commonjs/PhoneCountryInput/PhoneCountryInput.js +86 -0
  17. package/lib/commonjs/PhoneCountryInput/PhoneCountryInput.js.map +1 -0
  18. package/lib/commonjs/PhoneNumberField.js +36 -0
  19. package/lib/commonjs/PhoneNumberField.js.map +1 -0
  20. package/lib/commonjs/Styling/Colors.js +197 -0
  21. package/lib/commonjs/Styling/Colors.js.map +1 -0
  22. package/lib/commonjs/Styling/Sizing.js +111 -0
  23. package/lib/commonjs/Styling/Sizing.js.map +1 -0
  24. package/lib/commonjs/consts/KEYBOARD_LAYOUT.js +45 -0
  25. package/lib/commonjs/consts/KEYBOARD_LAYOUT.js.map +1 -0
  26. package/lib/commonjs/consts/regions.js +1503 -0
  27. package/lib/commonjs/consts/regions.js.map +1 -0
  28. package/lib/commonjs/enum/CountryIds.js +264 -0
  29. package/lib/commonjs/enum/CountryIds.js.map +1 -0
  30. package/lib/commonjs/hooks/UsePhoneFieldState.js +237 -0
  31. package/lib/commonjs/hooks/UsePhoneFieldState.js.map +1 -0
  32. package/lib/commonjs/index.js +56 -0
  33. package/lib/commonjs/index.js.map +1 -0
  34. package/lib/commonjs/package.json +1 -0
  35. package/lib/commonjs/utils/characterDeletion.js +20 -0
  36. package/lib/commonjs/utils/characterDeletion.js.map +1 -0
  37. package/lib/commonjs/utils/characterInsert.js +20 -0
  38. package/lib/commonjs/utils/characterInsert.js.map +1 -0
  39. package/lib/commonjs/utils/fromMaskedNumberToUnmaskedSelection.js +14 -0
  40. package/lib/commonjs/utils/fromMaskedNumberToUnmaskedSelection.js.map +1 -0
  41. package/lib/commonjs/utils/fromUnmaskedToMaskedPosition.js +20 -0
  42. package/lib/commonjs/utils/fromUnmaskedToMaskedPosition.js.map +1 -0
  43. package/lib/commonjs/utils/generateCountryCodeList.js +23 -0
  44. package/lib/commonjs/utils/generateCountryCodeList.js.map +1 -0
  45. package/lib/commonjs/utils/getDefaultRegion.js +33 -0
  46. package/lib/commonjs/utils/getDefaultRegion.js.map +1 -0
  47. package/lib/commonjs/utils/maskToPhoneNumber.js +23 -0
  48. package/lib/commonjs/utils/maskToPhoneNumber.js.map +1 -0
  49. package/lib/commonjs/utils/matchCountryCode.js +27 -0
  50. package/lib/commonjs/utils/matchCountryCode.js.map +1 -0
  51. package/lib/module/CountrySelector/CountrySelector.js +70 -0
  52. package/lib/module/CountrySelector/CountrySelector.js.map +1 -0
  53. package/lib/module/CountrySelector/CountrySelectorModal.js +262 -0
  54. package/lib/module/CountrySelector/CountrySelectorModal.js.map +1 -0
  55. package/lib/module/Keyboard/Keyboard.js +310 -0
  56. package/lib/module/Keyboard/Keyboard.js.map +1 -0
  57. package/lib/module/Keyboard/KeyboardToolbar.js +65 -0
  58. package/lib/module/Keyboard/KeyboardToolbar.js.map +1 -0
  59. package/lib/module/Keyboard/KeypadButton.js +61 -0
  60. package/lib/module/Keyboard/KeypadButton.js.map +1 -0
  61. package/lib/module/Keyboard/KeypadButtonContainer.js +59 -0
  62. package/lib/module/Keyboard/KeypadButtonContainer.js.map +1 -0
  63. package/lib/module/Keyboard/KeypadRow.js +30 -0
  64. package/lib/module/Keyboard/KeypadRow.js.map +1 -0
  65. package/lib/module/PhoneCountryInput/PhoneCountryInput.js +80 -0
  66. package/lib/module/PhoneCountryInput/PhoneCountryInput.js.map +1 -0
  67. package/lib/module/PhoneNumberField.js +31 -0
  68. package/lib/module/PhoneNumberField.js.map +1 -0
  69. package/lib/module/Styling/Colors.js +193 -0
  70. package/lib/module/Styling/Colors.js.map +1 -0
  71. package/lib/module/Styling/Sizing.js +107 -0
  72. package/lib/module/Styling/Sizing.js.map +1 -0
  73. package/lib/module/consts/KEYBOARD_LAYOUT.js +41 -0
  74. package/lib/module/consts/KEYBOARD_LAYOUT.js.map +1 -0
  75. package/lib/module/consts/regions.js +1498 -0
  76. package/lib/module/consts/regions.js.map +1 -0
  77. package/lib/module/enum/CountryIds.js +260 -0
  78. package/lib/module/enum/CountryIds.js.map +1 -0
  79. package/lib/module/hooks/UsePhoneFieldState.js +232 -0
  80. package/lib/module/hooks/UsePhoneFieldState.js.map +1 -0
  81. package/lib/module/index.js +16 -0
  82. package/lib/module/index.js.map +1 -0
  83. package/lib/module/package.json +1 -0
  84. package/lib/module/utils/characterDeletion.js +16 -0
  85. package/lib/module/utils/characterDeletion.js.map +1 -0
  86. package/lib/module/utils/characterInsert.js +16 -0
  87. package/lib/module/utils/characterInsert.js.map +1 -0
  88. package/lib/module/utils/fromMaskedNumberToUnmaskedSelection.js +10 -0
  89. package/lib/module/utils/fromMaskedNumberToUnmaskedSelection.js.map +1 -0
  90. package/lib/module/utils/fromUnmaskedToMaskedPosition.js +16 -0
  91. package/lib/module/utils/fromUnmaskedToMaskedPosition.js.map +1 -0
  92. package/lib/module/utils/generateCountryCodeList.js +19 -0
  93. package/lib/module/utils/generateCountryCodeList.js.map +1 -0
  94. package/lib/module/utils/getDefaultRegion.js +28 -0
  95. package/lib/module/utils/getDefaultRegion.js.map +1 -0
  96. package/lib/module/utils/maskToPhoneNumber.js +19 -0
  97. package/lib/module/utils/maskToPhoneNumber.js.map +1 -0
  98. package/lib/module/utils/matchCountryCode.js +23 -0
  99. package/lib/module/utils/matchCountryCode.js.map +1 -0
  100. package/lib/typescript/CountrySelector/CountrySelector.d.ts +19 -0
  101. package/lib/typescript/CountrySelector/CountrySelector.d.ts.map +1 -0
  102. package/lib/typescript/CountrySelector/CountrySelectorModal.d.ts +12 -0
  103. package/lib/typescript/CountrySelector/CountrySelectorModal.d.ts.map +1 -0
  104. package/lib/typescript/Keyboard/Keyboard.d.ts +25 -0
  105. package/lib/typescript/Keyboard/Keyboard.d.ts.map +1 -0
  106. package/lib/typescript/Keyboard/KeyboardToolbar.d.ts +9 -0
  107. package/lib/typescript/Keyboard/KeyboardToolbar.d.ts.map +1 -0
  108. package/lib/typescript/Keyboard/KeypadButton.d.ts +10 -0
  109. package/lib/typescript/Keyboard/KeypadButton.d.ts.map +1 -0
  110. package/lib/typescript/Keyboard/KeypadButtonContainer.d.ts +12 -0
  111. package/lib/typescript/Keyboard/KeypadButtonContainer.d.ts.map +1 -0
  112. package/lib/typescript/Keyboard/KeypadRow.d.ts +9 -0
  113. package/lib/typescript/Keyboard/KeypadRow.d.ts.map +1 -0
  114. package/lib/typescript/PhoneCountryInput/PhoneCountryInput.d.ts +16 -0
  115. package/lib/typescript/PhoneCountryInput/PhoneCountryInput.d.ts.map +1 -0
  116. package/lib/typescript/PhoneNumberField.d.ts +17 -0
  117. package/lib/typescript/PhoneNumberField.d.ts.map +1 -0
  118. package/lib/typescript/Styling/Colors.d.ts +189 -0
  119. package/lib/typescript/Styling/Colors.d.ts.map +1 -0
  120. package/lib/typescript/Styling/Sizing.d.ts +214 -0
  121. package/lib/typescript/Styling/Sizing.d.ts.map +1 -0
  122. package/lib/typescript/consts/KEYBOARD_LAYOUT.d.ts +18 -0
  123. package/lib/typescript/consts/KEYBOARD_LAYOUT.d.ts.map +1 -0
  124. package/lib/typescript/consts/regions.d.ts +10 -0
  125. package/lib/typescript/consts/regions.d.ts.map +1 -0
  126. package/lib/typescript/enum/CountryIds.d.ts +249 -0
  127. package/lib/typescript/enum/CountryIds.d.ts.map +1 -0
  128. package/lib/typescript/hooks/UsePhoneFieldState.d.ts +34 -0
  129. package/lib/typescript/hooks/UsePhoneFieldState.d.ts.map +1 -0
  130. package/lib/typescript/index.d.ts +15 -0
  131. package/lib/typescript/index.d.ts.map +1 -0
  132. package/lib/typescript/utils/characterDeletion.d.ts +3 -0
  133. package/lib/typescript/utils/characterDeletion.d.ts.map +1 -0
  134. package/lib/typescript/utils/characterInsert.d.ts +3 -0
  135. package/lib/typescript/utils/characterInsert.d.ts.map +1 -0
  136. package/lib/typescript/utils/fromMaskedNumberToUnmaskedSelection.d.ts +2 -0
  137. package/lib/typescript/utils/fromMaskedNumberToUnmaskedSelection.d.ts.map +1 -0
  138. package/lib/typescript/utils/fromUnmaskedToMaskedPosition.d.ts +2 -0
  139. package/lib/typescript/utils/fromUnmaskedToMaskedPosition.d.ts.map +1 -0
  140. package/lib/typescript/utils/generateCountryCodeList.d.ts +3 -0
  141. package/lib/typescript/utils/generateCountryCodeList.d.ts.map +1 -0
  142. package/lib/typescript/utils/getDefaultRegion.d.ts +4 -0
  143. package/lib/typescript/utils/getDefaultRegion.d.ts.map +1 -0
  144. package/lib/typescript/utils/maskToPhoneNumber.d.ts +2 -0
  145. package/lib/typescript/utils/maskToPhoneNumber.d.ts.map +1 -0
  146. package/lib/typescript/utils/matchCountryCode.d.ts +3 -0
  147. package/lib/typescript/utils/matchCountryCode.d.ts.map +1 -0
  148. package/package.json +92 -0
  149. package/src/CountrySelector/CountrySelector.tsx +77 -0
  150. package/src/CountrySelector/CountrySelectorModal.tsx +280 -0
  151. package/src/Keyboard/Keyboard.tsx +322 -0
  152. package/src/Keyboard/KeyboardToolbar.tsx +53 -0
  153. package/src/Keyboard/KeypadButton.tsx +58 -0
  154. package/src/Keyboard/KeypadButtonContainer.tsx +67 -0
  155. package/src/Keyboard/KeypadRow.tsx +29 -0
  156. package/src/PhoneCountryInput/PhoneCountryInput.tsx +98 -0
  157. package/src/PhoneNumberField.tsx +46 -0
  158. package/src/Styling/Colors.ts +206 -0
  159. package/src/Styling/Sizing.ts +110 -0
  160. package/src/consts/KEYBOARD_LAYOUT.ts +34 -0
  161. package/src/consts/regions.ts +268 -0
  162. package/src/enum/CountryIds.ts +256 -0
  163. package/src/hooks/UsePhoneFieldState.tsx +268 -0
  164. package/src/index.ts +27 -0
  165. package/src/utils/characterDeletion.ts +16 -0
  166. package/src/utils/characterInsert.ts +20 -0
  167. package/src/utils/fromMaskedNumberToUnmaskedSelection.ts +10 -0
  168. package/src/utils/fromUnmaskedToMaskedPosition.ts +13 -0
  169. package/src/utils/generateCountryCodeList.ts +22 -0
  170. package/src/utils/getDefaultRegion.ts +30 -0
  171. package/src/utils/maskToPhoneNumber.ts +30 -0
  172. package/src/utils/matchCountryCode.ts +23 -0
@@ -0,0 +1,30 @@
1
+ export function maskToPhoneNumber(rawInput: string, countryCode: string, mask: string): string {
2
+ const justDigits = rawInput.replace(/\D/g, '');
3
+ const restOfNumber = justDigits.slice(countryCode.length, justDigits.length);
4
+ let digitIndex = 0;
5
+ let maskedPart = '';
6
+
7
+ for (const char of mask) {
8
+ console.debug(
9
+ 'char',
10
+ char,
11
+ 'digitIndex',
12
+ digitIndex,
13
+ 'restOfNumber',
14
+ restOfNumber,
15
+ 'restOfNumber[digitIndex]',
16
+ restOfNumber[digitIndex],
17
+ 'Output',
18
+ maskedPart
19
+ );
20
+
21
+ if (digitIndex >= restOfNumber.length) break;
22
+ if (char === '#') {
23
+ maskedPart += restOfNumber[digitIndex++];
24
+ } else {
25
+ maskedPart += char;
26
+ }
27
+ }
28
+
29
+ return countryCode + maskedPart;
30
+ }
@@ -0,0 +1,23 @@
1
+ import { CountryCode } from '../consts/regions';
2
+
3
+ export function matchCountryCode(
4
+ filteredCountryCodes: CountryCode[],
5
+ rawInput: string
6
+ ): CountryCode | undefined {
7
+ return filteredCountryCodes.find(({ code }) => {
8
+ // intentional to use _value here instead of cleanedValue because we want to match against the raw input value that includes the '+' sign and any formatting characters, since country codes are typically prefixed with a '+' and may be followed by formatting characters like dashes or parentheses. Using cleanedValue would remove these characters and could lead to incorrect matching of country codes.
9
+
10
+ const phoneNumberWithoutPlus = rawInput.replace('+', '');
11
+ const CountryCodeWithoutPlus = code.replace('+', '');
12
+ const result = phoneNumberWithoutPlus.startsWith(CountryCodeWithoutPlus);
13
+ // console.debug(
14
+ // 'checking code',
15
+ // code,
16
+ // 'against cleanedValue',
17
+ // cleanedValue,
18
+ // 'result',
19
+ // result
20
+ // );
21
+ return result;
22
+ });
23
+ }