@exuus/rwanda-phone-utils
TypeScript icon, indicating that this package has built-in type declarations

1.0.9 • Public • Published

@exuus/rwanda-phone-utils

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

NPM

Installation

npm install @exuus/rwanda-phone-utils

or

yarn add @exuus/rwanda-phone-utils

Basic Usage

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

phoneUtils("0780000000")
// {
//     isValid: true,
//     error: null,
//     normalized: "0780000000",
//     formatted: "(+250) 780 000 000",
//     telco: "MTN",
//     short: "780000000",
//     dashed: "+(250)-780-000-000",
//     format: function
// }

phoneUtils("80000000");
// {
//     isValid: false,
//     error: "Phone number is invalid",
//     normalized: null,
//     formatted: null,
//     unformatted: 80000000,
//     telco: null,
//     short: null,
//     dashed: null
//     format: function
// }

Format

Get the formatted phone number according to the option (shape) passed in.

phoneUtils("+250780000000").format() // default
// 780000000

phoneUtils("+250788000000").format("dashed-normalized")
// 0780-000-000

List of all available formats

Format Output
short 780000000
normalized 0780000000
unformatted 250780000000
dashed +(250)-795-844-487
dashed-short 795-844-487
dashed-normalized 0795-844-487
dashed-unformatted 250-795-844-487
space +(250) 795 844 487
space-short 795 844 487
space-normalized 0795 844 487
space-unformatted 250 795 844 487

Formatting an invalid number will give your an error message

phoneUtils("+1780000000").format("short")
// Phone number is invalid

Contributors

Elie Mugenzi
Hadad

Licence

MIT

Author

Elie Mugenzi

Readme

Keywords

Package Sidebar

Install

npm i @exuus/rwanda-phone-utils

Weekly Downloads

3

Version

1.0.9

License

MIT

Unpacked Size

421 kB

Total Files

108

Last publish

Collaborators

  • dusmel
  • eliemugenzi
  • oesukam
  • exuus-dev