Skip to content

Commit 65db9d1

Browse files
Merge pull request #188 from filipedeschamps/unfetch
modules: add `unfetch` due to rollup replace
2 parents fe981b5 + 8a03f2b commit 65db9d1

File tree

4 files changed

+63
-8
lines changed

4 files changed

+63
-8
lines changed

dist/cep-promise-browser.js

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
(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';
86

97
function _typeof(obj) {
108
"@babel/helpers - typeof";
@@ -278,6 +276,57 @@
278276
return CepPromiseError;
279277
}( /*#__PURE__*/_wrapNativeSuper(Error));
280278

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+
281330
var ServiceError = /*#__PURE__*/function (_Error) {
282331
_inherits(ServiceError, _Error);
283332

0 commit comments

Comments
 (0)