|
1 | 1 | (function (global, factory) { |
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; |
| 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'; |
8 | 6 |
|
9 | 7 | function _typeof(obj) { |
10 | 8 | "@babel/helpers - typeof"; |
|
278 | 276 | return CepPromiseError; |
279 | 277 | }( /*#__PURE__*/_wrapNativeSuper(Error)); |
280 | 278 |
|
| 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 | + |
281 | 330 | var ServiceError = /*#__PURE__*/function (_Error) { |
282 | 331 | _inherits(ServiceError, _Error); |
283 | 332 |
|
|
0 commit comments