dev-rw-phone

RW Phone Number

Usage no npm install needed!

<script type="module">
  import devRwPhone from 'https://cdn.skypack.dev/dev-rw-phone';
</script>

README

dev-rw-phone

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

Site | Docs

NPM

Installation

npm install dev-rw-phone

or

yarn add dev-rw-phone

Basic Usage

// Load full build
const { phone } = require("dev-rw-phone");

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

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

Methods

isOk()

const { isOk } = require("dev-rw-phone");

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

Or

phone("0780000000").isOk;

format()

const { format } = require("dev-rw-phone");

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

Or

phone("0780000000").formatted;

normalize()

const { normalize } = require("dev-rw-phone");

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

Or

phone("0780000000").normalized;

short()

const { short } = require("dev-rw-phone");

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

Or

phone("0780000000").short;

telco()

const { telco } = require("dev-rw-phone");

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

Or

phone("0780000000").telco;

phone()

const { phone } = require("dev-rw-phone");

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

Contributors


Alleluia M

Licence

MIT

Author

Alleluia M