Skip to content

Commit

Permalink
feat: Update package name to "phone-formater-eth" in package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
HuluWZ committed Aug 20, 2024
1 parent 81ee068 commit f791185
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ A simple npm package to format Ethiopian phone numbers to the ISP standard code.
### Installation via npm

```
npm install --save phone-formatter-eth
npm install --save phone-formater-eth
```

### Via CDN
Expand All @@ -16,11 +16,11 @@ npm install --save phone-formatter-eth

### Usage
```
const { formatPhone, checkOperator, isValid } = require('phone-formatter-eth');
const { formatPhone, checkOperator, isValid } = require('phone-formater-eth');
Or
import { formatPhone, checkOperator, isValid } from 'phone-formatter-eth';
import { formatPhone, checkOperator, isValid } from 'phone-formater-eth';
```

Expand Down Expand Up @@ -67,7 +67,7 @@ console.log(isValid('0812345678')); // Outputs: false

### TODO ☑️

1. Parse - Cleans up or normalizes phone.e.g special characters like - and ()
1. parse - Cleans up or normalizes phone.e.g special characters like - and ()
2. toLocal - Converts phone number to local | Ethiopian format. 09 or 07 format
3. toInternational - Converts phone number to Int'l | Ethiopian format. +2519/7
4. isMobile - check if it's mobile sim. eg 09/07/+2519/7
Expand Down
21 changes: 12 additions & 9 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@ exports.formatPhone = formatPhone;
exports.checkOperator = checkOperator;
exports.isValid = isValid;
function formatPhone(phone) {
const phone_length = phone === null || phone === void 0 ? void 0 : phone.toString().length;
if (phone_length === 13 && phone.startsWith("+251")) {
return phone;
const formatted_phone = phone.replace(/[^+\d]/g, "");
const phone_length = formatted_phone === null || formatted_phone === void 0 ? void 0 : formatted_phone.toString().length;
if (phone_length === 13 && formatted_phone.startsWith("+251")) {
return formatted_phone;
}
else if (phone_length === 12 && phone.startsWith("251")) {
return `+${phone}`;
else if (phone_length === 12 && formatted_phone.startsWith("251")) {
return `+${formatted_phone}`;
}
else if (phone_length === 10 && ["09", "07"].includes(phone.slice(0, 2))) {
return `+251${phone.slice(1)}`;
else if (phone_length === 10 &&
["09", "07"].includes(formatted_phone.slice(0, 2))) {
return `+251${formatted_phone.slice(1)}`;
}
else if (phone_length === 9 && ["9", "7"].includes(phone.charAt(0))) {
return `+251${phone}`;
else if (phone_length === 9 &&
["9", "7"].includes(formatted_phone.charAt(0))) {
return `+251${formatted_phone}`;
}
else {
return "INVALID_PHONE_NUMBER";
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "phone-formatter-eth",
"version": "1.1.6",
"name": "phone-formater-eth",
"version": "1.1.6-beta",
"description": "Format Ethiopian phone numbers and check ISP under the number.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down

0 comments on commit f791185

Please sign in to comment.