A parser for phone numbers.
  • JavaScript 100%
Find a file
2020-10-12 22:03:24 -07:00
test fix: try to better sort and match countries for phone numbers 2020-10-12 22:03:24 -07:00
.eslintrc.json chore: upgrade to countrydata 3.0.0 2020-08-24 20:04:43 -07:00
.gitignore Initial commit 2016-04-21 22:31:47 -07:00
index.js fix: try to better sort and match countries for phone numbers 2020-10-12 22:03:24 -07:00
package-lock.json fix: try to better sort and match countries for phone numbers 2020-10-12 22:03:24 -07:00
package.json fix: try to better sort and match countries for phone numbers 2020-10-12 22:03:24 -07:00
README.md Allow detecting other countries even if a country code is specified 2016-05-03 14:17:24 -07:00

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.