6

Is there any lib for node.js that receives a phone number (in any format), converts it to a default format, and tells me info about the number (e.g.: country, city, etc)?

Zeeshan Hassan Memon
  • 8,105
  • 4
  • 43
  • 57
donald
  • 23,587
  • 42
  • 142
  • 223

4 Answers4

5

I'm not aware of one and I also searched the npm registry.

Google has libphonenumber for dealing with phone numbers and has a javascript API.

From their site:

Google's common Java, C++ and Javascript library for parsing, formatting, storing and validating international phone numbers. The Java version is optimized for running on smartphones.

There's also an SO post on getting phone country codes: List of phone number country codes

Community
  • 1
  • 1
bryanmac
  • 38,941
  • 11
  • 91
  • 99
2

While not a Node.js library, I think Number Laundry would fit your requirements (although it seems they only return the country, not the city):

Number Laundry is a tiny API that accepts phone numbers and returns helpful information as json:

Since you tagged the question with twilio, you might like that it returns Twilio rate data in addition to the other information:

{
  // The number you passed us
  "source": "+45 66 22 22 12",
  "error": false,
  // A nice clean format for your database (only: 0-9 and +)
  "clean": "+4566222212",
  // Twilio rate data
  "twilio": {
    "rate": "0.033",
    "prefix": "45"
  },
  // Country information (when available)
  "country": {
    "name": "Denmark",
    "code": "DK",
    "flag": "http:\/\/numberlaundry-icons.s3.amazonaws.com\/dk.png"
  }
}

They have the source on github, so you could probably port it to node if you wanted. If you're looking for more than just country info, checkout NumberGuru (although they're in limited alpha).

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
Tim Lytle
  • 17,549
  • 10
  • 60
  • 91
0

Consider also a simplified pure javascript port (no external dependencies) of Google's libphonenumber: https://github.com/halt-hammerzeit/libphonenumber-js

catamphetamine
  • 4,489
  • 30
  • 25
0

I build a library recently that run libphonenumber over NodeJs: https://github.com/Socialcam/node-libphonenumber

It might just solve your problem and you can deploy it in a snap over Heroku!

Guillaume
  • 11
  • 1