!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):e.cep=r()}(this,function(){"use strict";function e(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",n=t+"https://apps.correios.com.br/SigepMasterJPA/AtendeClienteService/AtendeCliente",o={method:"POST",body:'\n\n \n \n \n '+e+"\n \n \n",headers:{"Content-Type":"text/xml;charset=UTF-8","cache-control":"no-cache"}};return L(n,o).then(r).catch(i)}function r(e){return e.ok?e.text().then(t).then(s):e.text().then(n).then(o)}function t(e){try{var r=e.replace(/\r?\n|\r/g,"").match(/(.*)<\/return>/)[0]||"",t=r.replace("","").replace("",""),n=t.split(/).reduce(function(e,r){var t=r.split(">");return t.length>1&&t[1].length&&(e[t[0]]=t[1]),e},{});return n}catch(e){throw new Error("Não foi possível interpretar o XML de resposta.")}}function n(e){try{var r=e.match(/(.*)<\/faultstring>/)[0]||"",t=r.replace("","").replace("","");return t}catch(e){throw new Error("Não foi possível interpretar o XML de resposta.")}}function o(e){throw new Error(e)}function s(e){return{cep:e.cep,state:e.uf,city:e.cidade,neighborhood:e.bairro,street:e.end}}function i(e){var r=new R({message:e.message,service:"correios"});throw"FetchError"===e.name&&(r.message="Erro ao se conectar com o serviço dos Correios."),r}function a(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",t=r+"https://viacep.com.br/ws/"+e+"/json/",n={method:"GET",mode:"cors",headers:{"content-type":"application/json;charset=utf-8"}};return L(t,n).then(c).then(u).then(f).catch(p)}function c(e){if(e.ok)return e.json();throw Error("Erro ao se conectar com o serviço ViaCEP.")}function u(e){if(e.erro===!0)throw new Error("CEP não encontrado na base do ViaCEP.");return e}function f(e){return{cep:e.cep.replace("-",""),state:e.uf,city:e.localidade,neighborhood:e.bairro,street:e.logradouro}}function p(e){var r=new R({message:e.message,service:"viacep"});throw"FetchError"===e.name&&(r.message="Erro ao se conectar com o serviço ViaCEP."),r}function l(){return"undefined"!=typeof window}function h(e){return function(r){return e(r,k)}}function d(e){return Promise.resolve(e).then(m).then(v).then(g).then(y).then(w).catch(b).catch(E)}function m(e){var r="undefined"==typeof e?"undefined":P(e);if("number"===r||"string"===r)return e;throw new j({message:"Erro ao inicializar a instância do CepPromise.",type:"validation_error",errors:[{message:"Você deve chamar o construtor utilizando uma String ou um Number.",service:"cep_validation"}]})}function v(e){return e.toString().replace(/\D+/g,"")}function y(e){return"0".repeat(V-e.length)+e}function g(e){if(e.length<=V)return e;throw new j({message:"CEP deve conter exatamente "+V+" caracteres.",type:"validation_error",errors:[{message:"CEP informado possui mais do que "+V+" caracteres.",service:"cep_validation"}]})}function w(e){return Promise.any([H(e),M(e)])}function b(e){if(void 0!==e.length)throw new j({message:"Todos os serviços de CEP retornaram erro.",type:"service_error",errors:e});throw e}function E(e){var r=e.message,t=e.type,n=e.errors;throw new j({message:r,type:t,errors:n})}var P="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},C=function(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")},x=function(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function, not "+typeof r);e.prototype=Object.create(r&&r.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),r&&(Object.setPrototypeOf?Object.setPrototypeOf(e,r):e.__proto__=r)},_=function(e,r){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!r||"object"!=typeof r&&"function"!=typeof r?e:r},S=function(e){if(Array.isArray(e)){for(var r=0,t=Array(e.length);r0&&void 0!==arguments[0]?arguments[0]:{},t=e.message,n=e.type,o=e.errors;C(this,r);var s=_(this,(r.__proto__||Object.getPrototypeOf(r)).call(this));return s.name="CepPromiseError",s.message=t,s.type=n,s.errors=o,s}return x(r,e),r}(Error),O="function"==typeof fetch?fetch.bind():function(e,r){return r=r||{},new Promise(function(t,n){function o(){var e,r=[],t=[],n={};return s.getAllResponseHeaders().replace(/^(.*?):\s*([\s\S]*?)$/gm,function(o,s,i){r.push(s=s.toLowerCase()),t.push([s,i]),e=n[s],n[s]=e?e+","+i:i}),{ok:1==(s.status/200|0),status:s.status,statusText:s.statusText,url:s.responseURL,clone:o,text:function(){return Promise.resolve(s.responseText)},json:function(){return Promise.resolve(s.responseText).then(JSON.parse)},blob:function(){return Promise.resolve(new Blob([s.response]))},headers:{keys:function(){return r},entries:function(){return t},get:function(e){return n[e.toLowerCase()]},has:function(e){return e.toLowerCase()in n}}}}var s=new XMLHttpRequest;s.open(r.method||"get",e);for(var i in r.headers)s.setRequestHeader(i,r.headers[i]);s.withCredentials="include"==r.credentials,s.onload=function(){t(o())},s.onerror=n,s.send(r.body)})},T=Object.freeze({default:O}),A=T&&O||T,L=window.fetch||(window.fetch=A.default||A),R=function(e){function r(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.message,n=e.service;C(this,r);var o=_(this,(r.__proto__||Object.getPrototypeOf(r)).call(this));return o.name="ServiceError",o.message=t,o.service=n,o}return x(r,e),r}(Error),k="https://proxier.now.sh/",H=l()?h(e):e,M=l()?h(a):a,N=function(e){return new Promise(function(r,t){return Promise.resolve(e).then(t,r)})};Promise.any=function(e){return N(Promise.all([].concat(S(e)).map(N)))};var V=8;return d});