问题
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)?
回答1:
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
回答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).
回答3:
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!
回答4:
Consider also a simplified pure javascript port (no external dependencies) of Google's libphonenumber
:
https://github.com/halt-hammerzeit/libphonenumber-js
来源:https://stackoverflow.com/questions/8769723/information-about-a-phone-number