phone-cd
Version:
Phone DRC is a phone number library to manage DRC phone number
125 lines (81 loc) • 2.97 kB
Markdown
Handle DRC phone number validation and formatting with ease.
To install the Phone CD package, run the following command:
```bash
npm install phone-cd
```
You can import the package using either ES6 or CommonJS syntax:
```javascript
import phone from "phone-cd";
```
```javascript
const phone = require("phone-cd");
```
Formats the phone number to the national DRC format.
```javascript
phoneCD.national("00243832044091"); // returns 832044091
phoneCD.national(243832044091); // returns 832044091
phoneCD.national(+243832044091); // returns 832044091
phoneCD.national('0832044091'); // returns 832044091
```
Formats the phone number to the international DRC format (+243).
#### Examples
```javascript
phoneCD.international("00243832044091"); // returns 243832044091
phoneCD.international(243832044091); // returns 243832044091
phoneCD.international(+243832044091); // returns 243832044091
phoneCD.international('0832044091'); // returns 243832044091
```
Checks if a phone number is a valid DRC phone number.
```javascript
phoneCD.isValid(832044091); // returns true
phoneCD.isValid(0850964008); // returns true
phoneCD.isValid(243978491245); // returns true
phoneCD.isValid(+243902248661); // returns true
phoneCD.isValid(243721412335); // returns false
```
Verifies the operator of a DRC phone number.
```javascript
phoneCD.operator('0832044091'); // returns "vodacom"
phoneCD.operator(243850964008); // returns "orange"
phoneCD.operator(+243978491245); // returns "airtel"
phoneCD.operator(00243902248661); // returns "africel"
phoneCD.operator(243721412335); // returns null
```
**Parameters:**
- `value`: The phone number to format. Can be a string or a number.
**Returns:**
- The phone number in national format.
**Parameters:**
- `value`: The phone number to format. Can be a string or a number.
**Returns:**
- The phone number in international format or `null` if invalid.
**Parameters:**
- `value`: The phone number to validate. Can be a string or a number.
**Returns:**
- `true` if the number is a valid DRC phone number, `false` otherwise.
**Parameters:**
- `value`: The phone number to check the operator. Can be a string or a number.
**Returns:**
- The operator name as a string or `null` if no operator matches.
Contributions are welcome! Please open an issue or submit a pull request on GitHub.
This project is licensed under the MIT License. See the LICENSE file for details.