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.
- package/README.md +477 -0
- package/lib/commonjs/CountrySelector/CountrySelector.js +74 -0
- package/lib/commonjs/CountrySelector/CountrySelector.js.map +1 -0
- package/lib/commonjs/CountrySelector/CountrySelectorModal.js +267 -0
- package/lib/commonjs/CountrySelector/CountrySelectorModal.js.map +1 -0
- package/lib/commonjs/Keyboard/Keyboard.js +316 -0
- package/lib/commonjs/Keyboard/Keyboard.js.map +1 -0
- package/lib/commonjs/Keyboard/KeyboardToolbar.js +70 -0
- package/lib/commonjs/Keyboard/KeyboardToolbar.js.map +1 -0
- package/lib/commonjs/Keyboard/KeypadButton.js +66 -0
- package/lib/commonjs/Keyboard/KeypadButton.js.map +1 -0
- package/lib/commonjs/Keyboard/KeypadButtonContainer.js +65 -0
- package/lib/commonjs/Keyboard/KeypadButtonContainer.js.map +1 -0
- package/lib/commonjs/Keyboard/KeypadRow.js +34 -0
- package/lib/commonjs/Keyboard/KeypadRow.js.map +1 -0
- package/lib/commonjs/PhoneCountryInput/PhoneCountryInput.js +86 -0
- package/lib/commonjs/PhoneCountryInput/PhoneCountryInput.js.map +1 -0
- package/lib/commonjs/PhoneNumberField.js +36 -0
- package/lib/commonjs/PhoneNumberField.js.map +1 -0
- package/lib/commonjs/Styling/Colors.js +197 -0
- package/lib/commonjs/Styling/Colors.js.map +1 -0
- package/lib/commonjs/Styling/Sizing.js +111 -0
- package/lib/commonjs/Styling/Sizing.js.map +1 -0
- package/lib/commonjs/consts/KEYBOARD_LAYOUT.js +45 -0
- package/lib/commonjs/consts/KEYBOARD_LAYOUT.js.map +1 -0
- package/lib/commonjs/consts/regions.js +1503 -0
- package/lib/commonjs/consts/regions.js.map +1 -0
- package/lib/commonjs/enum/CountryIds.js +264 -0
- package/lib/commonjs/enum/CountryIds.js.map +1 -0
- package/lib/commonjs/hooks/UsePhoneFieldState.js +237 -0
- package/lib/commonjs/hooks/UsePhoneFieldState.js.map +1 -0
- package/lib/commonjs/index.js +56 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/utils/characterDeletion.js +20 -0
- package/lib/commonjs/utils/characterDeletion.js.map +1 -0
- package/lib/commonjs/utils/characterInsert.js +20 -0
- package/lib/commonjs/utils/characterInsert.js.map +1 -0
- package/lib/commonjs/utils/fromMaskedNumberToUnmaskedSelection.js +14 -0
- package/lib/commonjs/utils/fromMaskedNumberToUnmaskedSelection.js.map +1 -0
- package/lib/commonjs/utils/fromUnmaskedToMaskedPosition.js +20 -0
- package/lib/commonjs/utils/fromUnmaskedToMaskedPosition.js.map +1 -0
- package/lib/commonjs/utils/generateCountryCodeList.js +23 -0
- package/lib/commonjs/utils/generateCountryCodeList.js.map +1 -0
- package/lib/commonjs/utils/getDefaultRegion.js +33 -0
- package/lib/commonjs/utils/getDefaultRegion.js.map +1 -0
- package/lib/commonjs/utils/maskToPhoneNumber.js +23 -0
- package/lib/commonjs/utils/maskToPhoneNumber.js.map +1 -0
- package/lib/commonjs/utils/matchCountryCode.js +27 -0
- package/lib/commonjs/utils/matchCountryCode.js.map +1 -0
- package/lib/module/CountrySelector/CountrySelector.js +70 -0
- package/lib/module/CountrySelector/CountrySelector.js.map +1 -0
- package/lib/module/CountrySelector/CountrySelectorModal.js +262 -0
- package/lib/module/CountrySelector/CountrySelectorModal.js.map +1 -0
- package/lib/module/Keyboard/Keyboard.js +310 -0
- package/lib/module/Keyboard/Keyboard.js.map +1 -0
- package/lib/module/Keyboard/KeyboardToolbar.js +65 -0
- package/lib/module/Keyboard/KeyboardToolbar.js.map +1 -0
- package/lib/module/Keyboard/KeypadButton.js +61 -0
- package/lib/module/Keyboard/KeypadButton.js.map +1 -0
- package/lib/module/Keyboard/KeypadButtonContainer.js +59 -0
- package/lib/module/Keyboard/KeypadButtonContainer.js.map +1 -0
- package/lib/module/Keyboard/KeypadRow.js +30 -0
- package/lib/module/Keyboard/KeypadRow.js.map +1 -0
- package/lib/module/PhoneCountryInput/PhoneCountryInput.js +80 -0
- package/lib/module/PhoneCountryInput/PhoneCountryInput.js.map +1 -0
- package/lib/module/PhoneNumberField.js +31 -0
- package/lib/module/PhoneNumberField.js.map +1 -0
- package/lib/module/Styling/Colors.js +193 -0
- package/lib/module/Styling/Colors.js.map +1 -0
- package/lib/module/Styling/Sizing.js +107 -0
- package/lib/module/Styling/Sizing.js.map +1 -0
- package/lib/module/consts/KEYBOARD_LAYOUT.js +41 -0
- package/lib/module/consts/KEYBOARD_LAYOUT.js.map +1 -0
- package/lib/module/consts/regions.js +1498 -0
- package/lib/module/consts/regions.js.map +1 -0
- package/lib/module/enum/CountryIds.js +260 -0
- package/lib/module/enum/CountryIds.js.map +1 -0
- package/lib/module/hooks/UsePhoneFieldState.js +232 -0
- package/lib/module/hooks/UsePhoneFieldState.js.map +1 -0
- package/lib/module/index.js +16 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/utils/characterDeletion.js +16 -0
- package/lib/module/utils/characterDeletion.js.map +1 -0
- package/lib/module/utils/characterInsert.js +16 -0
- package/lib/module/utils/characterInsert.js.map +1 -0
- package/lib/module/utils/fromMaskedNumberToUnmaskedSelection.js +10 -0
- package/lib/module/utils/fromMaskedNumberToUnmaskedSelection.js.map +1 -0
- package/lib/module/utils/fromUnmaskedToMaskedPosition.js +16 -0
- package/lib/module/utils/fromUnmaskedToMaskedPosition.js.map +1 -0
- package/lib/module/utils/generateCountryCodeList.js +19 -0
- package/lib/module/utils/generateCountryCodeList.js.map +1 -0
- package/lib/module/utils/getDefaultRegion.js +28 -0
- package/lib/module/utils/getDefaultRegion.js.map +1 -0
- package/lib/module/utils/maskToPhoneNumber.js +19 -0
- package/lib/module/utils/maskToPhoneNumber.js.map +1 -0
- package/lib/module/utils/matchCountryCode.js +23 -0
- package/lib/module/utils/matchCountryCode.js.map +1 -0
- package/lib/typescript/CountrySelector/CountrySelector.d.ts +19 -0
- package/lib/typescript/CountrySelector/CountrySelector.d.ts.map +1 -0
- package/lib/typescript/CountrySelector/CountrySelectorModal.d.ts +12 -0
- package/lib/typescript/CountrySelector/CountrySelectorModal.d.ts.map +1 -0
- package/lib/typescript/Keyboard/Keyboard.d.ts +25 -0
- package/lib/typescript/Keyboard/Keyboard.d.ts.map +1 -0
- package/lib/typescript/Keyboard/KeyboardToolbar.d.ts +9 -0
- package/lib/typescript/Keyboard/KeyboardToolbar.d.ts.map +1 -0
- package/lib/typescript/Keyboard/KeypadButton.d.ts +10 -0
- package/lib/typescript/Keyboard/KeypadButton.d.ts.map +1 -0
- package/lib/typescript/Keyboard/KeypadButtonContainer.d.ts +12 -0
- package/lib/typescript/Keyboard/KeypadButtonContainer.d.ts.map +1 -0
- package/lib/typescript/Keyboard/KeypadRow.d.ts +9 -0
- package/lib/typescript/Keyboard/KeypadRow.d.ts.map +1 -0
- package/lib/typescript/PhoneCountryInput/PhoneCountryInput.d.ts +16 -0
- package/lib/typescript/PhoneCountryInput/PhoneCountryInput.d.ts.map +1 -0
- package/lib/typescript/PhoneNumberField.d.ts +17 -0
- package/lib/typescript/PhoneNumberField.d.ts.map +1 -0
- package/lib/typescript/Styling/Colors.d.ts +189 -0
- package/lib/typescript/Styling/Colors.d.ts.map +1 -0
- package/lib/typescript/Styling/Sizing.d.ts +214 -0
- package/lib/typescript/Styling/Sizing.d.ts.map +1 -0
- package/lib/typescript/consts/KEYBOARD_LAYOUT.d.ts +18 -0
- package/lib/typescript/consts/KEYBOARD_LAYOUT.d.ts.map +1 -0
- package/lib/typescript/consts/regions.d.ts +10 -0
- package/lib/typescript/consts/regions.d.ts.map +1 -0
- package/lib/typescript/enum/CountryIds.d.ts +249 -0
- package/lib/typescript/enum/CountryIds.d.ts.map +1 -0
- package/lib/typescript/hooks/UsePhoneFieldState.d.ts +34 -0
- package/lib/typescript/hooks/UsePhoneFieldState.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +15 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/utils/characterDeletion.d.ts +3 -0
- package/lib/typescript/utils/characterDeletion.d.ts.map +1 -0
- package/lib/typescript/utils/characterInsert.d.ts +3 -0
- package/lib/typescript/utils/characterInsert.d.ts.map +1 -0
- package/lib/typescript/utils/fromMaskedNumberToUnmaskedSelection.d.ts +2 -0
- package/lib/typescript/utils/fromMaskedNumberToUnmaskedSelection.d.ts.map +1 -0
- package/lib/typescript/utils/fromUnmaskedToMaskedPosition.d.ts +2 -0
- package/lib/typescript/utils/fromUnmaskedToMaskedPosition.d.ts.map +1 -0
- package/lib/typescript/utils/generateCountryCodeList.d.ts +3 -0
- package/lib/typescript/utils/generateCountryCodeList.d.ts.map +1 -0
- package/lib/typescript/utils/getDefaultRegion.d.ts +4 -0
- package/lib/typescript/utils/getDefaultRegion.d.ts.map +1 -0
- package/lib/typescript/utils/maskToPhoneNumber.d.ts +2 -0
- package/lib/typescript/utils/maskToPhoneNumber.d.ts.map +1 -0
- package/lib/typescript/utils/matchCountryCode.d.ts +3 -0
- package/lib/typescript/utils/matchCountryCode.d.ts.map +1 -0
- package/package.json +92 -0
- package/src/CountrySelector/CountrySelector.tsx +77 -0
- package/src/CountrySelector/CountrySelectorModal.tsx +280 -0
- package/src/Keyboard/Keyboard.tsx +322 -0
- package/src/Keyboard/KeyboardToolbar.tsx +53 -0
- package/src/Keyboard/KeypadButton.tsx +58 -0
- package/src/Keyboard/KeypadButtonContainer.tsx +67 -0
- package/src/Keyboard/KeypadRow.tsx +29 -0
- package/src/PhoneCountryInput/PhoneCountryInput.tsx +98 -0
- package/src/PhoneNumberField.tsx +46 -0
- package/src/Styling/Colors.ts +206 -0
- package/src/Styling/Sizing.ts +110 -0
- package/src/consts/KEYBOARD_LAYOUT.ts +34 -0
- package/src/consts/regions.ts +268 -0
- package/src/enum/CountryIds.ts +256 -0
- package/src/hooks/UsePhoneFieldState.tsx +268 -0
- package/src/index.ts +27 -0
- package/src/utils/characterDeletion.ts +16 -0
- package/src/utils/characterInsert.ts +20 -0
- package/src/utils/fromMaskedNumberToUnmaskedSelection.ts +10 -0
- package/src/utils/fromUnmaskedToMaskedPosition.ts +13 -0
- package/src/utils/generateCountryCodeList.ts +22 -0
- package/src/utils/getDefaultRegion.ts +30 -0
- package/src/utils/maskToPhoneNumber.ts +30 -0
- 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
|
+
}
|