A simple npm package to format Ethiopian phone numbers to the ISP standard code.
npm install --save phone-formater-eth
<script src="https://cdn.jsdelivr.net/npm/phone-formater-eth@1.1.7/dist/index.min.js"></script>
const { formatPhone, checkOperator, isValid, parse} = require('phone-formater-eth');
Or
import { formatPhone, checkOperator, isValid, parse } from 'phone-formater-eth';
- formatPhone - Formats an Ethiopian phone number to the ISP standard code.
console.log(formatPhone('0912345678')); // Outputs: +251912345678 - Int'l format
console.log(formatPhone('+251712345678',"local")); // Outputs: 0712345678 - Local
console.log(formatPhone('251912345678'."local")); // Outputs: 0912345678 - Local
console.log(formatPhone('09123456789')); // Outputs: +2519123456789
console.log(formatPhone('0712345678',"local")); // Outputs: 0712345678 - Local
console.log(formatPhone('25191234567')); // Outputs: +25191234567
console.log(formatPhone('0801234567')); // Outputs: Invalid Phone
- checkOperator - Checks the phone operator based on the formatted Ethiopian phone number.
console.log(checkOperator('712345678')); // Outputs: Safaricom
console.log(checkOperator('+251912345678')); // Outputs: Ethio Telecom
console.log(checkOperator('0712345678')); // Outputs: Safaricom
console.log(checkOperator('251912345678')); // Outputs: Ethio Telecom
console.log(checkOperator('0812345678')); // Outputs: Unknown
- isValid - Checks if phone number is valid or not
console.log(isValid('712345678')); // Outputs: true
console.log(isValid('+251912345678')); // Outputs: true
console.log(isValid('07812345678')); // Outputs: false
console.log(isValid('251912345678')); // Outputs: true
console.log(isValid('0812345678')); // Outputs: false
- parse - Parse phone number to remove special characters like '-' and '(' ')'
console.log(parse("(251) 911-123-456")); //25191112456
console.log(parse("(251) 911-123-456")); //25191112456
console.log(parse("251-911-123-456")); //25191112456
console.log(parse("2519-11-123-456")); //25191112456
- isMobile - check if it's mobile sim. eg 09/07/+2519/7
- isLandline - check if it's landline sim. eg. +2511
PLease submit your contributions as PRs and also leave a good description for the PR
This project is licensed under the MIT License. See the LICENSE file for more information.