|
1 | 1 | (function (global, factory) { |
2 | | - typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : |
3 | | - typeof define === 'function' && define.amd ? define(factory) : |
4 | | - (global = global || self, global.cep = factory()); |
5 | | -}(this, (function () { 'use strict'; |
| 2 | + typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('unfetch')) : |
| 3 | + typeof define === 'function' && define.amd ? define(['unfetch'], factory) : |
| 4 | + (global = global || self, global.cep = factory(global.fetch)); |
| 5 | +}(this, (function (fetch) { 'use strict'; |
| 6 | + |
| 7 | + fetch = fetch && Object.prototype.hasOwnProperty.call(fetch, 'default') ? fetch['default'] : fetch; |
6 | 8 |
|
7 | 9 | function _typeof(obj) { |
8 | 10 | "@babel/helpers - typeof"; |
|
276 | 278 | return CepPromiseError; |
277 | 279 | }( /*#__PURE__*/_wrapNativeSuper(Error)); |
278 | 280 |
|
279 | | - function fetch (e, n) { |
280 | | - return n = n || {}, new Promise(function (t, r) { |
281 | | - var s = new XMLHttpRequest(), |
282 | | - o = [], |
283 | | - u = [], |
284 | | - i = {}, |
285 | | - a = function a() { |
286 | | - return { |
287 | | - ok: 2 == (s.status / 100 | 0), |
288 | | - statusText: s.statusText, |
289 | | - status: s.status, |
290 | | - url: s.responseURL, |
291 | | - text: function text() { |
292 | | - return Promise.resolve(s.responseText); |
293 | | - }, |
294 | | - json: function json() { |
295 | | - return Promise.resolve(JSON.parse(s.responseText)); |
296 | | - }, |
297 | | - blob: function blob() { |
298 | | - return Promise.resolve(new Blob([s.response])); |
299 | | - }, |
300 | | - clone: a, |
301 | | - headers: { |
302 | | - keys: function keys() { |
303 | | - return o; |
304 | | - }, |
305 | | - entries: function entries() { |
306 | | - return u; |
307 | | - }, |
308 | | - get: function get(e) { |
309 | | - return i[e.toLowerCase()]; |
310 | | - }, |
311 | | - has: function has(e) { |
312 | | - return e.toLowerCase() in i; |
313 | | - } |
314 | | - } |
315 | | - }; |
316 | | - }; |
317 | | - |
318 | | - for (var l in s.open(n.method || "get", e, !0), s.onload = function () { |
319 | | - s.getAllResponseHeaders().replace(/^(.*?):[^\S\n]*([\s\S]*?)$/gm, function (e, n, t) { |
320 | | - o.push(n = n.toLowerCase()), u.push([n, t]), i[n] = i[n] ? i[n] + "," + t : t; |
321 | | - }), t(a()); |
322 | | - }, s.onerror = r, s.withCredentials = "include" == n.credentials, n.headers) { |
323 | | - s.setRequestHeader(l, n.headers[l]); |
324 | | - } |
325 | | - |
326 | | - s.send(n.body || null); |
327 | | - }); |
328 | | - } |
329 | | - |
330 | 281 | var ServiceError = /*#__PURE__*/function (_Error) { |
331 | 282 | _inherits(ServiceError, _Error); |
332 | 283 |
|
|
441 | 392 | method: 'GET', |
442 | 393 | mode: 'cors', |
443 | 394 | headers: { |
444 | | - 'content-type': 'application/json;charset=utf-8' |
| 395 | + 'content-type': 'application/json;charset=utf-8', |
| 396 | + 'user-agent': '' |
445 | 397 | } |
446 | 398 | }; |
447 | 399 | return fetch(url, options).then(analyzeAndParseResponse$1).then(checkForViaCepError).then(extractCepValuesFromResponse)["catch"](throwApplicationError$1); |
|
589 | 541 |
|
590 | 542 | if (isBrowser) { |
591 | 543 | return { |
592 | | - brasilapi: fetchBrasilAPIService, |
593 | 544 | viacep: fetchViaCepService, |
594 | | - widenet: fetchWideNetService |
| 545 | + widenet: fetchWideNetService, |
| 546 | + brasilapi: fetchBrasilAPIService |
595 | 547 | }; |
596 | 548 | } |
597 | 549 |
|
598 | 550 | return { |
599 | | - brasilapi: fetchBrasilAPIService, |
| 551 | + correios: fetchCorreiosService, |
600 | 552 | viacep: fetchViaCepService, |
601 | 553 | widenet: fetchWideNetService, |
602 | | - correios: fetchCorreiosService |
| 554 | + brasilapi: fetchBrasilAPIService |
603 | 555 | }; |
604 | 556 | } |
605 | 557 |
|
|
0 commit comments