Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.7.32 breacking change - countryCallingCode #388

Closed
cuzik opened this issue Apr 2, 2020 · 4 comments
Closed

1.7.32 breacking change - countryCallingCode #388

cuzik opened this issue Apr 2, 2020 · 4 comments
Assignees

Comments

@cuzik
Copy link

cuzik commented Apr 2, 2020

Steps to reproduce

formatter = libphonenumber.AsYouType("BR")
formatter.countryCallingCode

Observed result

this returns undefined.

Expected result

before the path version this code returns "55"

@catamphetamine
Copy link
Owner

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.

@catamphetamine
Copy link
Owner

catamphetamine commented Apr 2, 2020

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.

@catamphetamine
Copy link
Owner

catamphetamine commented Apr 4, 2020

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?

@catamphetamine
Copy link
Owner

Published [email protected].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants