UNPKG

@shopgate/engage

Version:
10 lines 1.52 kB
function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}import{logger}from'@shopgate/pwa-core/helpers';import iso3166 from"./iso-3166-2";import{getCountryNames}from"../../../../i18n/countries.helpers";/** * Get country list for * @param {Object} countryElement Configuration of which form fields to render * @param {?Object} optional object to prepend optional choice * @return {Object} */export default(function(countryElement){var optional=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;// Check validity of the country element options list "countries" if(countryElement.countries!==null&&countryElement.countries!==undefined&&!Array.isArray(countryElement.countries)){logger.error("Error: Invalid property type 'countries' in element "+"'".concat(countryElement.id,"'. Must be 'array', 'null' or 'undefined'"));return{};}// Build country display list for the country element (whitelist) // For 'null', 'undefined' and '[]' it shows all countries var countryKeys;if(countryElement.countries&&countryElement.countries.length>0){countryKeys=countryElement.countries;}else{countryKeys=Object.keys(iso3166);}var countryList=getCountryNames(countryKeys);// Add a "no selection" element if(countryElement.required){return countryList;}return _extends({},optional,{},countryList);});