Skip to content

Commit

Permalink
feat: Add isValid function for checking if a phone number is valid
Browse files Browse the repository at this point in the history
  • Loading branch information
HuluWZ committed Aug 20, 2024
1 parent a327e81 commit 6aeb229
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Object.defineProperty(exports, "__esModule", { value: true });
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")) {
Expand All @@ -17,7 +18,7 @@ function formatPhone(phone) {
return `+251${phone}`;
}
else {
return "INVALID PHONE NUMBER";
return "INVALID_PHONE_NUMBER";
}
}
function checkOperator(phone) {
Expand All @@ -32,3 +33,7 @@ function checkOperator(phone) {
return "UNKNOWN";
}
}
function isValid(phone) {
const formattedPhone = formatPhone(phone);
return formattedPhone === "INVALID_PHONE_NUMBER" ? false : true;
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "phone-formatter-eth",
"version": "1.1.5",
"version": "1.1.6",
"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 6aeb229

Please sign in to comment.