question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature request: expose a function to convert CountryCallingCode to CountryCode, or expose MetadataJson value

See original GitHub issue

There is a function exposed getCountryCallingCode(countryCode: CountryCode): CountryCallingCode) but no inverse of this function:

export function getAllCountryCodes(countryCallingCode: CountryCallingCode): CountryCode[] | undefined {
    return metadata.country_calling_codes[countryCallingCode];
}

This would be useful if you are trying to use any of the functionality that uses CountryCode but your dataset happens to have a calling code separate from the numbers but no country data.

Alternatively exposing the built in metadata would allow users to do this ourselves. An implementation I am playing with today needs this function in order to figure out which parameters are needed to pass to parsePhoneNumber to handle a large amount of questionably formatted data. I’ve resorted to:

const phoneMetadata: Record<string, any> = new Metadata();
let metadataJson: MetadataJson | undefined = undefined;
if ('metadata' in phoneMetadata) {
  metadataJson = phoneMetadata.metadata;
}
if (!metadataJson) {
  throw new Error(
    'libphonenumber-js implementation changed; figure out new way to get country codes from country calling codes'
  );
}

to write the above function…

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
awcscommented, Nov 29, 2022

I think he meant for cases like multiple countries for one country calling code we need a function to extract those countries (that’s my case).

Example for country calling code +44, we could have a function like this: const countryList = libPhoneNumber.getCountriesByCallingCode(44)

And in countryList we would have : ['GB', 'GG', 'IM', 'JE']

0reactions
catamphetaminecommented, Dec 21, 2022

If a phone number belongs to any country, its ‘country’ will be set. Otherwise, the country is unknown

On Wed, 21 Dec 2022 at 23:23, rwev @.***> wrote:

A phone number input in which the user can select a country.

https://dribbble.com/shots/15474151-Phone-Number-Input-Field-Exploration

Determining the country code from the selected country is easily done via getCountryCallingCode

Repopulating the input from the final phone number is where the problem arises, as the parsed countryCallingCode does not determine the original country.

Classic problem of reversing a many -> one calculation (i.e. one -> many)

— Reply to this email directly, view it on GitHub https://github.com/catamphetamine/libphonenumber-js/issues/420#issuecomment-1362054327, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADUP33P6VVDTL3EPR234WLWONRL5ANCNFSM5NP7KXGQ . You are receiving this because you commented.Message ID: @.***>

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issues · catamphetamine/libphonenumber-js - GitHub
Feature request : expose a function to convert CountryCallingCode to CountryCode, or expose MetadataJson value. #420 opened on Feb 3 by bbarry.
Read more >
How I Translate Feature Requests into Code - Michael-F-Bryan
In this stage you develop a big picture view of the feature and how it will expose its functionality to the outside world....
Read more >
https://raw.githubusercontent.com/liferay/liferay-...
REQUEST_ADMINISTRATOR_ACCESS=Request Administrator Access (Automatic Copy) action. ... -feature=Add formulas to calculate values based on other fields.
Read more >
[Flexible Layouts] Add a render test - Nasa/Openmct - IssueHint
Feature request : expose a function to convert CountryCallingCode to CountryCode, or expose MetadataJson value, 1, 2022-02-03, 2022-08-15.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found