Skip to content

andyburke/phoneparser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

phoneparser

A parser for phone numbers.

Code Example

const phoneparser = require( 'phoneparser' );

const phone = phoneparser.parse( '93712345678' );
console.log( JSON.stringify( phone, null, 4 ) );

Output:

{
    "valid": true,
    "normalized": "+93712345678",
    "stripped": "93712345678",
    "localized": {
        "stripped": "712345678"
    },
    "info": {
        "prefix": "7",
        "type": "mobile"
    },
    "country": {
        "name": {
            "de": "Afghanistan",
            "es": "Afganistán",
            "fr": "Afghanistan",
            "ja": "アフガニスタン",
            "it": "Afghanistan",
            "en": "Afghanistan"
        },
        "iso3166": {
            "alpha2": "AF",
            "alpha3": "AFG",
            "independent": true,
            "name": "Afghanistan",
            "numeric": 4,
            "currency": {
                "name": "Afghani",
                "code": "AFN",
                "numeric": 971,
                "minor_unit": 2
            }
        },
        "phone": {
            "code": "93",
            "lengths": [
                9
            ],
            "prefixes": {
                "7": {
                    "type": "mobile"
                }
            }
        },
        "latitude": 33,
        "longitude": 65,
        "timezones": [
            "UTC+04:30"
        ],
        "area": 652230,
        "population": 26023100,
        "region": "Asia",
        "subregion": "Southern Asia"
    }
}

Installation

npm install --save phoneparser

Tests

npm run test

Contributing

Contributions are encouraged and appreciated. To make the process as quick and painless as possible for everyone involved, here's a checklist that will make a pull request easily accepted:

  1. Implement your new feature or bugfix
  2. Add or update tests to ensure coverage
  3. Ensure your code passes jshint according to the .jshintrc
  4. Ensure your code is formatted according to the .jsbeautifyrc
  5. Submit

License

MIT

Inspiration

https://github.com/aftership/phone

Inspired by the 'phone' library. Many thanks to aftership.com for a great example.

About

A parser for phone numbers.

Resources

Stars

Watchers

Forks

Packages

No packages published