A JavaScript library to automatically format and correct phone numbers for international dialing, with a focus on accuracy and ease of use.
- Automatic Formatting: Converts phone numbers into the E.164 standard format, making them ready for international calls.
- Country Code Correction: Adds the correct country code if missing or incorrect.
- Mobile Operator Detection: Identifies the mobile operator based on the phone number’s prefix.
- Caching: Utilizes caching to store previously formatted and corrected phone numbers for quicker access in future requests.
- Error Handling: Provides clear error messages for invalid or incorrectly formatted phone numbers.
Install the package using npm:
npm install phone-number-formatter-corrector
const { formatPhoneNumber, getMobileOperator } = require('phone-number-formatter-corrector');
const formattedNumber = formatPhoneNumber('677123456', 'CM');
console.log(formattedNumber); // Expected output: +237677123456
const operator = getMobileOperator('677123456', 'CM');
console.log(operator); // Expected output: MTN (or the appropriate operator for this number)
number
(String): The phone number to be formatted.countryCode
(String): The country code to be used if the phone number is not in international format.
number
(String): The phone number for which the mobile operator will be determined.countryCode
(String): The country code for the provided phone number.
- google-libphonenumber: For parsing, formatting, and validating international phone numbers.
- node-cache: For caching previously formatted and corrected phone numbers.
Contributions are welcome! Feel free to open an issue or submit a pull request.
This project is licensed under the MIT License - see the LICENSE.md file for details.