@automattic/wpcom-checkout
Version:
Functions and components used by WordPress.com checkout.
29 lines • 1.29 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getCountryPostalCodeSupport = getCountryPostalCodeSupport;
/**
* Returns true if postal codes are supported on the specified country code.
*
* NOTE: Will return false if the countries list is empty or if the country
* code is not in the list! Always check that the countries list has loaded
* before calling this.
*/
function getCountryPostalCodeSupport(countries, countryCode) {
if (!countryCode) {
return false;
}
if (!countries?.length) {
// eslint-disable-next-line no-console
console.error('Error: getCountryPostalCodeSupport was called without a countries list. This will result in incorrect data!');
return false;
}
const countryListItem = countries.find((country) => country.code === countryCode.toUpperCase() ||
(country.vat_supported && country.tax_country_codes.includes(countryCode.toUpperCase())));
if (!countryListItem) {
// eslint-disable-next-line no-console
console.warn(`Warning: getCountryPostalCodeSupport could not find the country "${countryCode}"!`);
return false;
}
return countryListItem.has_postal_codes ?? false;
}
//# sourceMappingURL=get-country-postal-code-support.js.map