Closed cuzik closed 4 years ago
Hi.
countryCallingCode
is not part of the public API:
https://github.com/catamphetamine/libphonenumber-js#class-asyoutypeoptions-or-defaultcountry
Perhaps it has been changed at some point, but not recently.
A note: .countryCallingCode
is currently only set when an international number is being input (with a +
).
When a user doesn't input a +
, .countryCallingCode
isn't set.
Even in case of international phone number input, .countryCallingCode
isn't part of the public API.
If you think there's a valid use case when a developer might want to have access to .countryCallingCode
then you can post a comment in this discussion thread.
So I was thinking on adding a couple of utility methods to AsYouType
now that this topic has been raised.
Currently, it only has .getNumber()
and .getTemplate()
, and .getNumber()
only returns non-undefined
when there's at least a single national number digit been input.
Some developers might want something like:
/**
* Returns `true` if the phone number is being input in international format.
* In other words, returns `true` if and only if the parsed phone number starts with a `"+"`.
* @return {boolean}
*/
isInternational()
/**
* Returns the "country calling code" part of the phone number.
* Returns `undefined` if the number is not being input in international format.
* Returns "country calling code" for "non-geographic" phone numbering plans too.
* @return {string} [countryCallingCode]
*/
getCountryCallingCode()
/**
* Returns a two-letter country code of the phone number.
* Returns `undefined` for "non-geographic" phone numbering plans.
* Returns `undefined` if no phone number has been input yet.
* @return {string} [country]
*/
getCountry()
/**
* Returns `true` if the phone number is "possible".
* Is just a shortcut for `PhoneNumber.isPossible()`.
* @return {boolean}
*/
isPossible()
/**
* Returns `true` if the phone number is "valid".
* Is just a shortcut for `PhoneNumber.isValid()`.
* @return {boolean}
*/
isValid()
@cuzik
What are your thoughts?
And why did you read countryCallingCode
property?
Published libphonenumber-js@1.7.50
.
Steps to reproduce
Observed result
this returns
undefined
.Expected result
before the path version this code returns
"55"