!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 s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",a=s+"http://www.cepaberto.com/api/v2/ceps.json?cep="+e,i={method:"GET",mode:"cors",headers:{"content-type":"application/json;charset=utf-8",Authorization:"Token token="+V}};return H(a,i).then(r).then(t).then(o).catch(n)}function r(e){if(e.ok)return e.json();throw Error("Erro ao se conectar com o serviço Cep Aberto.")}function t(e){if(!Object.keys(e).length)throw new Error("CEP não encontrado na base do Cep Aberto.");return e}function o(e){return{cep:e.cep,state:e.estado,city:e.cidade,neighborhood:e.bairro,street:e.logradouro}}function n(e){var r=new M({message:e.message,service:"cepaberto"});throw"FetchError"===e.name&&(r.message="Erro ao se conectar com o serviço Cep Aberto."),r}function s(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",t=r+"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 H(t,o).then(a).catch(p)}function a(e){return e.ok?e.text().then(i).then(f):e.text().then(c).then(u)}function i(e){try{var r=e.replace(/\r?\n|\r/g,"").match(/(.*)<\/return>/)[0]||"",t=r.replace("","").replace("",""),o=t.split(/).reduce(function(e,r){var t=r.split(">");return t.length>1&&t[1].length&&(e[t[0]]=t[1]),e},{});return o}catch(e){throw new Error("Não foi possível interpretar o XML de resposta.")}}function c(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 u(e){throw new Error(e)}function f(e){return{cep:e.cep,state:e.uf,city:e.cidade,neighborhood:e.bairro,street:e.end}}function p(e){var r=new M({message:e.message,service:"correios"});throw"FetchError"===e.name&&(r.message="Erro ao se conectar com o serviço dos Correios."),r}function h(e){var r="https://viacep.com.br/ws/"+e+"/json/",t={method:"GET",mode:"cors",headers:{"content-type":"application/json;charset=utf-8"}};return H(r,t).then(l).then(d).then(m).catch(v)}function l(e){if(e.ok)return e.json();throw Error("Erro ao se conectar com o serviço ViaCEP.")}function d(e){if(e.erro===!0)throw new Error("CEP não encontrado na base do ViaCEP.");return e}function m(e){return{cep:e.cep.replace("-",""),state:e.uf,city:e.localidade,neighborhood:e.bairro,street:e.logradouro}}function v(e){var r=new M({message:e.message,service:"viacep"});throw"FetchError"===e.name&&(r.message="Erro ao se conectar com o serviço ViaCEP."),r}function y(){return"undefined"!=typeof window}function g(e){return function(r){return e(r,N)}}function w(e){return Promise.resolve(e).then(b).then(E).then(C).then(P).then(x).catch(_).catch(j)}function b(e){var r="undefined"==typeof e?"undefined":S(e);if("number"===r||"string"===r)return e;throw new L({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 E(e){return e.toString().replace(/\D+/g,"")}function P(e){return"0".repeat(J-e.length)+e}function C(e){if(e.length<=J)return e;throw new L({message:"CEP deve conter exatamente "+J+" caracteres.",type:"validation_error",errors:[{message:"CEP informado possui mais do que "+J+" caracteres.",service:"cep_validation"}]})}function x(e){return Promise.any([q(e),B(e),X(e)])}function _(e){if(void 0!==e.length)throw new L({message:"Todos os serviços de CEP retornaram erro.",type:"service_error",errors:e});throw e}function j(e){var r=e.message,t=e.type,o=e.errors;throw new L({message:r,type:t,errors:o})}var S="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},O=function(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")},T=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)},A=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},k=function(e){if(Array.isArray(e)){for(var r=0,t=Array(e.length);r0&&void 0!==arguments[0]?arguments[0]:{},t=e.message,o=e.type,n=e.errors;O(this,r);var s=A(this,(r.__proto__||Object.getPrototypeOf(r)).call(this));return s.name="CepPromiseError",s.message=t,s.type=o,s.errors=n,s}return T(r,e),r}(Error),R="function"==typeof fetch?fetch.bind():function(e,r){return r=r||{},new Promise(function(t,o){function n(){var e,r=[],t=[],o={};return s.getAllResponseHeaders().replace(/^(.*?):\s*([\s\S]*?)$/gm,function(n,s,a){r.push(s=s.toLowerCase()),t.push([s,a]),e=o[s],o[s]=e?e+","+a:a}),{ok:1==(s.status/200|0),status:s.status,statusText:s.statusText,url:s.responseURL,clone:n,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 o[e.toLowerCase()]},has:function(e){return e.toLowerCase()in o}}}}var s=new XMLHttpRequest;s.open(r.method||"get",e);for(var a in r.headers)s.setRequestHeader(a,r.headers[a]);s.withCredentials="include"==r.credentials,s.onload=function(){t(n())},s.onerror=o,s.send(r.body)})},z=Object.freeze({default:R}),F=z&&R||z,H=window.fetch||(window.fetch=F.default||F),M=function(e){function r(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.message,o=e.service;O(this,r);var n=A(this,(r.__proto__||Object.getPrototypeOf(r)).call(this));return n.name="ServiceError",n.message=t,n.service=o,n}return T(r,e),r}(Error),N="https://proxier.now.sh/",V="37d718d2984e6452584a76d3d59d3a26",q=y()?g(e):e,B=y()?g(s):s,X=h,G=function(e){return new Promise(function(r,t){return Promise.resolve(e).then(t,r)})};Promise.any=function(e){return G(Promise.all([].concat(k(e)).map(G)))};var J=8;return w});