let US_EXT="(?[0-9]{5})[ -]?(?[0-9]{4})?",CA="(?[a-z][0-9][a-z][ -]?[0-9][a-z][0-9])",zipRegex=new RegExp(`\\b${US_EXT}|${CA}\\b`,"gi"),formatPostalCode=val=>{if(val)return(val=val.replace(/[^0-9A-Z]/g,"")).substring(0,3)+" "+val.substring(3,6)},addressZip=address=>{var match,zips=[],matches=address.matchAll(zipRegex);if(!matches)return[];for(match of matches){var{zip,zipExt,postalCode}=match.groups,source=match[0].trim();zips.push({zip:zip??formatPostalCode(postalCode)??"",zipExt:zipExt,countryIso2s:zip?["US"]:["CA"],source:source,ndx:address.lastIndexOf(source),length:source.length})}return 1a.ndx>b.ndx?-1:1),zips};exports.addressZip=addressZip;