123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- import Metadata from '../metadata.js'
- import getNumberType from './getNumberType.js'
- export default function getCountryByNationalNumber(nationalPhoneNumber, {
- countries,
- defaultCountry,
- metadata
- }) {
-
- metadata = new Metadata(metadata)
- const matchingCountries = []
- for (const country of countries) {
- metadata.country(country)
-
-
-
-
-
-
-
- if (metadata.leadingDigits()) {
- if (nationalPhoneNumber &&
- nationalPhoneNumber.search(metadata.leadingDigits()) === 0) {
- return country
- }
- }
-
-
- else if (getNumberType({ phone: nationalPhoneNumber, country }, undefined, metadata.metadata)) {
-
- if (defaultCountry) {
- if (country === defaultCountry) {
- return country
- }
- matchingCountries.push(country)
- } else {
- return country
- }
- }
- }
-
- if (matchingCountries.length > 0) {
- return matchingCountries[0]
- }
- }
|