1.1.1 • Published 3 years ago

rwanda-phone-utils v1.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

rwanda-phone-utils

This is a simple npm package that validates the structure and format phone numbers from Rwanda.

NPM

Installation

npm install rwanda-phone-utils

or

yarn add rwanda-phone-utils

Basic Usage

// Load full build
import phone from "rwanda-phone-utils";

console.log(phone("0780000000"));
// {
//     isValid: true,
//     error: null,
//     normalized: "250780000000",
//     formatted: "(+250) 780 000 000",
//     telco: "MTN",
//     short: "780000000",
//     dashed: "0780-000-000",
// }

console.log(phone("80000000"));
// {
//     isValid: false,
//     error: "Phone number NOT valid",
//     normalized: "80000000",
//     formatted: "(+250) 7XX XXX XXX",
//     telco: null,
//     short: "7XXXXXXXX",
//     dashed: "07XX-XXX-XXX"
// }

Methods

isValid()

import { isValid } from "rwanda-phone-utils";

console.log(isValid("0780000000"));
// true

Or

phone("0780000000").isValid;

format()

import { format } from "rwanda-phone-utils";

console.log(format("0780000000"));
// "(+250) 780 000 000"

Or

phone("0780000000").formatted;

normalize()

import { normalize } from "rwanda-phone-utils";

console.log(normalize("0780000000"));
// "250780000000"

Or

phone("0780000000").normalized;

short()

import { short } from "rwanda-phone-utils";

console.log(short("0780000000"));
// "780000000"

Or

phone("0780000000").short;

telco()

import { telco } from "rwanda-phone-utils";

console.log(telco("0780000000"));
// "MTN"

Or

phone("0780000000").telco;

telco()

import { dashed } from "rwanda-phone-utils";

console.log(dashed("0780000000"));
// "0780-000-000"

Or

phone("0780000000").dashed;

phone()

import phone from "rwanda-phone-utils";

console.log(phone("0780000000"));
// {
//     isValid: true,
//     error: null,
//     normalized: "250780000000",
//     formatted: "(+250) 780 000 000",
//     telco: "MTN",
//     short: "780000000",
//     dashed: "0780-000-000"
// }

Contributors

Elie Mugenzi

Licence

MIT

Author

Elie Mugenzi

1.1.1

3 years ago

1.1.0

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.2

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago