getCountryCodeSource
getCountryCodeSource() is used to gets the value of the country code source.
Usage
Using Standard JavaScript:
// Create an instance of PhoneNumberUtil
const phoneUtil = require('libphonenumbers').PhoneNumberUtil.getInstance();
// Parse number with US country code and keep raw input
const number = phoneUtil.parseAndKeepRawInput('202-456-2121', 'US');
// Get the phone's extension
console.log(number.getCountryCodeSource());
// FROM_DEFAULT_COUNTRY
Using ECMAScript (ES):
import libphonenumbers from 'libphonenumbers';
// Create an instance of PhoneNumberUtil
const phoneUtil = libphonenumbers.PhoneNumberUtil.getInstance();
// Parse number with US country code and keep raw input
const number = phoneUtil.parseAndKeepRawInput('202-456-2121', 'US');
// Print the phone's extension
console.log(number.getCountryCodeSource());
// FROM_DEFAULT_COUNTRY
CountryCodeSource
The following enums is used to compare with the output of getCountryCodeSource().
Enum | Value |
---|---|
UNSPECIFIED | 0 |
FROM_NUMBER_WITH_PLUS_SIGN | 1 |
FROM_NUMBER_WITH_IDD | 5 |
FROM_NUMBER_WITHOUT_PLUS_SIGN | 10 |
FROM_DEFAULT_COUNTRY | 20 |