function getPhoneDigitsForNewCountry(phoneDigits, {
	prevCountry,
	newCountry,
	metadata,
	useNationalFormat
}) {
	if (prevCountry === newCountry) {
		return phoneDigits
	}

	// If `parsed_input` is empty
	// then no need to migrate anything.
	if (!phoneDigits) {
		if (useNationalFormat) {
			return ''
		} else {
			if (newCountry) {
				// If `phoneDigits` is empty then set `phoneDigits` to
				// `+{getCountryCallingCode(newCountry)}`.
				return getInternationalPhoneNumberPrefix(newCountry, metadata)
			}
			return ''
		}
	}

	// If switching to some country.
	// (from "International" or another country)
	// If switching from "International" then `phoneDigits` starts with a `+`.
	// Otherwise it may or may not start with a `+`.
	if (newCountry) {
		// If the phone number was entered in international format
		// then migrate it to the newly selected country.
		// The phone number may be incomplete.
		// The phone number entered not necessarily starts with
		// the previously selected country phone prefix.
		if (phoneDigits[0] === '+') {
			// If the international phone number is for the new country
			// then convert it to local if required.
			if (useNationalFormat) {
				// // If a phone number is being input in international form
				// // and the country can already be derived from it,
				// // and if it is the new country, then format as a national number.
				// const derived_country = getCountryFromPossiblyIncompleteInternationalPhoneNumber(phoneDigits, metadata)
				// if (derived_country === newCountry) {
				// 	return stripCountryCallingCode(phoneDigits, derived_country, metadata)
				// }

				// Actually, the two countries don't necessarily need to match:
				// the condition could be looser here, because several countries
				// might share the same international phone number format
				// (for example, "NANPA" countries like US, Canada, etc).
				// The looser condition would be just "same nternational phone number format"
				// which would mean "same country calling code" in the context of `libphonenumber-js`.
				if (phoneDigits.indexOf('+' + getCountryCallingCode(newCountry, metadata)) === 0) {
					return stripCountryCallingCode(phoneDigits, newCountry, metadata)
				}

				// Simply discard the previously entered international phone number,
				// because otherwise any "smart" transformation like getting the
				// "national (significant) number" part and then prepending the
				// newly selected country's "country calling code" to it
				// would just be confusing for a user without being actually useful.
				return ''

				// // Simply strip the leading `+` character
				// // therefore simply converting all digits into a "local" phone number.
				// // https://github.com/catamphetamine/react-phone-number-input/issues/287
				// return phoneDigits.slice(1)
			}

			if (prevCountry) {
				const newCountryPrefix = getInternationalPhoneNumberPrefix(newCountry, metadata)
				if (phoneDigits.indexOf(newCountryPrefix) === 0) {
					return phoneDigits
				} else {
					return newCountryPrefix
				}
			} else {
				const defaultValue = getInternationalPhoneNumberPrefix(newCountry, metadata)
				// If `phoneDigits`'s country calling code part is the same
				// as for the new `country`, then leave `phoneDigits` as is.
				if (phoneDigits.indexOf(defaultValue) === 0) {
					return phoneDigits
				}
				// If `phoneDigits`'s country calling code part is not the same
				// as for the new `country`, then set `phoneDigits` to
				// `+{getCountryCallingCode(newCountry)}`.
				return defaultValue
			}

			// // If the international phone number already contains
			// // any country calling code then trim the country calling code part.
			// // (that could also be the newly selected country phone code prefix as well)
			// // `phoneDigits` doesn't neccessarily belong to `prevCountry`.
			// // (e.g. if a user enters an international number
			// //  not belonging to any of the reduced `countries` list).
			// phoneDigits = stripCountryCallingCode(phoneDigits, prevCountry, metadata)

			// // Prepend country calling code prefix
			// // for the newly selected country.
			// return e164(phoneDigits, newCountry, metadata) || `+${getCountryCallingCode(newCountry, metadata)}`
		}
	}
	// If switching to "International" from a country.
	else {
		// If the phone number was entered in national format.
		if (phoneDigits[0] !== '+') {
			// Format the national phone number as an international one.
			// The phone number entered not necessarily even starts with
			// the previously selected country phone prefix.
			// Even if the phone number belongs to whole another country
			// it will still be parsed into some national phone number.
			//
			// Ignore the now-uncovered `|| ''` code branch:
			// previously `e164()` function could return an empty string
			// even when `phoneDigits` were not empty.
			// Now it always returns some `value` when there're any `phoneDigits`.
			// Still, didn't remove the `|| ''` code branch just in case
			// that logic changes somehow in some future, so there're no
			// possible bugs related to that.
			//
			// (ignore the `|| ''` code branch)
			/* istanbul ignore next */
			return e164(phoneDigits, prevCountry, metadata) || ''
		}
	}

	return phoneDigits
}
Migrates parsed `<input/>` `value` for the newly selected `country`.
@param {string?} phoneDigits - Phone number digits (and `+`) parsed from phone number `<input/>` (it's not the same as the `value` property).
@param {string?} prevCountry - Previously selected country.
@param {string?} newCountry - Newly selected country. Can't be same as previously selected country.
@param {object} metadata - `libphonenumber-js` metadata.
@param {boolean} useNationalFormat - whether should attempt to convert from international to national number for the new country.
@return {string?}