!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r(require("isomorphic-unfetch")):"function"==typeof define&&define.amd?define(["isomorphic-unfetch"],r):e.cep=r(e.fetch)}(this,function(e){"use strict";function r(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.message,o=e.type,t=e.errors;this.name="CepPromiseError",this.message=r,this.type=o,this.errors=t}function o(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.message,o=e.service;this.name="ServiceError",this.message=r,this.service=o}function t(r){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",t=o+"http://www.cepaberto.com/api/v2/ceps.json?cep="+r,i={method:"GET",mode:"cors",headers:{"content-type":"application/json;charset=utf-8",Authorization:'Token token="37bfda18fd4b423cdb6748d14ba30aa6"'}};return e(t,i).then(n).then(a).then(s).catch(c)}function n(e){if(e.ok)return e.json();throw Error("Erro ao se conectar com o serviço Cep Aberto.")}function a(e){if(!Object.keys(e).length)throw new Error("CEP não encontrado na base do Cep Aberto.");return e}function s(e){return{cep:e.cep,state:e.estado,city:e.cidade,neighborhood:e.bairro,street:e.logradouro}}function c(e){var r=new o({message:e.message,service:"cepaberto"});throw"FetchError"===e.name&&(r.message="Erro ao se conectar com o serviço Cep Aberto."),r}function i(r){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",t=o+"https://apps.correios.com.br/SigepMasterJPA/AtendeClienteService/AtendeCliente",n={method:"POST",body:'\n\n \n \n \n '+r+"\n \n \n",headers:{"Content-Type":"text/xml;charset=UTF-8","cache-control":"no-cache"}};return e(t,n).then(u).catch(d)}function u(e){return e.ok?e.text().then(p).then(m):e.text().then(h).then(f)}function p(e){try{var r=e.replace(/\r?\n|\r/g,"").match(/(.*)<\/return>/)[0]||"",o=r.replace("","").replace("",""),t=o.split(/).reduce(function(e,r){var o=r.split(">");return o.length>1&&o[1].length&&(e[o[0]]=o[1]),e},{});return t}catch(e){throw new Error("Não foi possível interpretar o XML de resposta.")}}function h(e){try{var r=e.match(/(.*)<\/faultstring>/)[0]||"",o=r.replace("","").replace("","");return o}catch(e){throw new Error("Não foi possível interpretar o XML de resposta.")}}function f(e){throw new Error(e)}function m(e){return{cep:e.cep,state:e.uf,city:e.cidade,neighborhood:e.bairro,street:e.end}}function d(e){var r=new o({message:e.message,service:"correios"});throw"FetchError"===e.name&&(r.message="Erro ao se conectar com o serviço dos Correios."),r}function l(r){var o="https://viacep.com.br/ws/"+r+"/json/",t={method:"GET",mode:"cors",headers:{"content-type":"application/json;charset=utf-8"}};return e(o,t).then(v).then(g).then(y).catch(w)}function v(e){if(e.ok)return e.json();throw Error("Erro ao se conectar com o serviço ViaCEP.")}function g(e){if(e.erro===!0)throw new Error("CEP não encontrado na base do ViaCEP.");return e}function y(e){return{cep:e.cep.replace("-",""),state:e.uf,city:e.localidade,neighborhood:e.bairro,street:e.logradouro}}function w(e){var r=new o({message:e.message,service:"viacep"});throw"FetchError"===e.name&&(r.message="Erro ao se conectar com o serviço ViaCEP."),r}function b(e){return function(r){return e(r,T)}}function E(e){return Promise.resolve(e).then(P).then(C).then(A).then(x).then(S).catch(j).catch(k)}function P(e){var o="undefined"==typeof e?"undefined":z(e);if("number"===o||"string"===o)return e;throw new r({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 C(e){return e.toString().replace(/\D+/g,"")}function x(e){return"0".repeat(O-e.length)+e}function A(e){if(e.length<=O)return e;throw new r({message:"CEP deve conter exatamente "+O+" caracteres.",type:"validation_error",errors:[{message:"CEP informado possui mais do que "+O+" caracteres.",service:"cep_validation"}]})}function S(e){return Promise.any([_(e),F(e),V(e)])}function j(e){if(void 0!==e.length)throw new r({message:"Todos os serviços de CEP retornaram erro.",type:"service_error",errors:e});throw e}function k(e){var o=e.message,t=e.type,n=e.errors;throw new r({message:o,type:t,errors:n})}e=e&&e.hasOwnProperty("default")?e.default:e,r.prototype=new Error,o.prototype=new Error;var T="https://cors-anywhere.herokuapp.com/",_="undefined"==typeof process?b(t):t,F="undefined"==typeof process?b(i):i,V=l,z="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},M=function(e){if(Array.isArray(e)){for(var r=0,o=Array(e.length);r