cross-fetch
Advanced tools
Comparing version 4.0.0 to 4.1.0
@@ -5,13 +5,16 @@ (function(self) { | ||
var global = | ||
/* eslint-disable no-prototype-builtins */ | ||
var g = | ||
(typeof globalThis !== 'undefined' && globalThis) || | ||
(typeof self !== 'undefined' && self) || | ||
(typeof global !== 'undefined' && global); | ||
// eslint-disable-next-line no-undef | ||
(typeof global !== 'undefined' && global) || | ||
{}; | ||
var support = { | ||
searchParams: 'URLSearchParams' in global, | ||
iterable: 'Symbol' in global && 'iterator' in Symbol, | ||
searchParams: 'URLSearchParams' in g, | ||
iterable: 'Symbol' in g && 'iterator' in Symbol, | ||
blob: | ||
'FileReader' in global && | ||
'Blob' in global && | ||
'FileReader' in g && | ||
'Blob' in g && | ||
(function() { | ||
@@ -25,4 +28,4 @@ try { | ||
})(), | ||
formData: 'FormData' in global, | ||
arrayBuffer: 'ArrayBuffer' in global | ||
formData: 'FormData' in g, | ||
arrayBuffer: 'ArrayBuffer' in g | ||
}; | ||
@@ -98,2 +101,5 @@ | ||
headers.forEach(function(header) { | ||
if (header.length != 2) { | ||
throw new TypeError('Headers constructor: expected name/value pair to be length 2, found' + header.length) | ||
} | ||
this.append(header[0], header[1]); | ||
@@ -169,2 +175,3 @@ }, this); | ||
function consumed(body) { | ||
if (body._noBody) return | ||
if (body.bodyUsed) { | ||
@@ -197,3 +204,5 @@ return Promise.reject(new TypeError('Already read')) | ||
var promise = fileReaderReady(reader); | ||
reader.readAsText(blob); | ||
var match = /charset=([A-Za-z0-9_-]+)/.exec(blob.type); | ||
var encoding = match ? match[1] : 'utf-8'; | ||
reader.readAsText(blob, encoding); | ||
return promise | ||
@@ -236,5 +245,7 @@ } | ||
*/ | ||
// eslint-disable-next-line no-self-assign | ||
this.bodyUsed = this.bodyUsed; | ||
this._bodyInit = body; | ||
if (!body) { | ||
this._noBody = true; | ||
this._bodyText = ''; | ||
@@ -287,24 +298,25 @@ } else if (typeof body === 'string') { | ||
}; | ||
} | ||
this.arrayBuffer = function() { | ||
if (this._bodyArrayBuffer) { | ||
var isConsumed = consumed(this); | ||
if (isConsumed) { | ||
return isConsumed | ||
} | ||
if (ArrayBuffer.isView(this._bodyArrayBuffer)) { | ||
return Promise.resolve( | ||
this._bodyArrayBuffer.buffer.slice( | ||
this._bodyArrayBuffer.byteOffset, | ||
this._bodyArrayBuffer.byteOffset + this._bodyArrayBuffer.byteLength | ||
) | ||
this.arrayBuffer = function() { | ||
if (this._bodyArrayBuffer) { | ||
var isConsumed = consumed(this); | ||
if (isConsumed) { | ||
return isConsumed | ||
} else if (ArrayBuffer.isView(this._bodyArrayBuffer)) { | ||
return Promise.resolve( | ||
this._bodyArrayBuffer.buffer.slice( | ||
this._bodyArrayBuffer.byteOffset, | ||
this._bodyArrayBuffer.byteOffset + this._bodyArrayBuffer.byteLength | ||
) | ||
} else { | ||
return Promise.resolve(this._bodyArrayBuffer) | ||
} | ||
) | ||
} else { | ||
return this.blob().then(readBlobAsArrayBuffer) | ||
return Promise.resolve(this._bodyArrayBuffer) | ||
} | ||
}; | ||
} | ||
} else if (support.blob) { | ||
return this.blob().then(readBlobAsArrayBuffer) | ||
} else { | ||
throw new Error('could not read as ArrayBuffer') | ||
} | ||
}; | ||
@@ -342,3 +354,3 @@ this.text = function() { | ||
// HTTP methods whose capitalization should be normalized | ||
var methods = ['DELETE', 'GET', 'HEAD', 'OPTIONS', 'POST', 'PUT']; | ||
var methods = ['CONNECT', 'DELETE', 'GET', 'HEAD', 'OPTIONS', 'PATCH', 'POST', 'PUT', 'TRACE']; | ||
@@ -384,3 +396,8 @@ function normalizeMethod(method) { | ||
this.mode = options.mode || this.mode || null; | ||
this.signal = options.signal || this.signal; | ||
this.signal = options.signal || this.signal || (function () { | ||
if ('AbortController' in g) { | ||
var ctrl = new AbortController(); | ||
return ctrl.signal; | ||
} | ||
}()); | ||
this.referrer = null; | ||
@@ -447,3 +464,7 @@ | ||
var value = parts.join(':').trim(); | ||
headers.append(key, value); | ||
try { | ||
headers.append(key, value); | ||
} catch (error) { | ||
console.warn('Response ' + error.message); | ||
} | ||
} | ||
@@ -466,2 +487,5 @@ }); | ||
this.status = options.status === undefined ? 200 : options.status; | ||
if (this.status < 200 || this.status > 599) { | ||
throw new RangeError("Failed to construct 'Response': The status provided (0) is outside the range [200, 599].") | ||
} | ||
this.ok = this.status >= 200 && this.status < 300; | ||
@@ -486,3 +510,5 @@ this.statusText = options.statusText === undefined ? '' : '' + options.statusText; | ||
Response.error = function() { | ||
var response = new Response(null, {status: 0, statusText: ''}); | ||
var response = new Response(null, {status: 200, statusText: ''}); | ||
response.ok = false; | ||
response.status = 0; | ||
response.type = 'error'; | ||
@@ -502,3 +528,3 @@ return response | ||
exports.DOMException = global.DOMException; | ||
exports.DOMException = g.DOMException; | ||
try { | ||
@@ -533,6 +559,12 @@ new exports.DOMException(); | ||
var options = { | ||
status: xhr.status, | ||
statusText: xhr.statusText, | ||
headers: parseHeaders(xhr.getAllResponseHeaders() || '') | ||
}; | ||
// This check if specifically for when a user fetches a file locally from the file system | ||
// Only if the status is out of a normal range | ||
if (request.url.indexOf('file://') === 0 && (xhr.status < 200 || xhr.status > 599)) { | ||
options.status = 200; | ||
} else { | ||
options.status = xhr.status; | ||
} | ||
options.url = 'responseURL' in xhr ? xhr.responseURL : options.headers.get('X-Request-URL'); | ||
@@ -553,3 +585,3 @@ var body = 'response' in xhr ? xhr.response : xhr.responseText; | ||
setTimeout(function() { | ||
reject(new TypeError('Network request failed')); | ||
reject(new TypeError('Network request timed out')); | ||
}, 0); | ||
@@ -566,3 +598,3 @@ }; | ||
try { | ||
return url === '' && global.location.href ? global.location.href : url | ||
return url === '' && g.location.href ? g.location.href : url | ||
} catch (e) { | ||
@@ -585,5 +617,3 @@ return url | ||
} else if ( | ||
support.arrayBuffer && | ||
request.headers.get('Content-Type') && | ||
request.headers.get('Content-Type').indexOf('application/octet-stream') !== -1 | ||
support.arrayBuffer | ||
) { | ||
@@ -594,6 +624,13 @@ xhr.responseType = 'arraybuffer'; | ||
if (init && typeof init.headers === 'object' && !(init.headers instanceof Headers)) { | ||
if (init && typeof init.headers === 'object' && !(init.headers instanceof Headers || (g.Headers && init.headers instanceof g.Headers))) { | ||
var names = []; | ||
Object.getOwnPropertyNames(init.headers).forEach(function(name) { | ||
names.push(normalizeName(name)); | ||
xhr.setRequestHeader(name, normalizeValue(init.headers[name])); | ||
}); | ||
request.headers.forEach(function(value, name) { | ||
if (names.indexOf(name) === -1) { | ||
xhr.setRequestHeader(name, value); | ||
} | ||
}); | ||
} else { | ||
@@ -622,7 +659,7 @@ request.headers.forEach(function(value, name) { | ||
if (!global.fetch) { | ||
global.fetch = fetch; | ||
global.Headers = Headers; | ||
global.Request = Request; | ||
global.Response = Response; | ||
if (!g.fetch) { | ||
g.fetch = fetch; | ||
g.Headers = Headers; | ||
g.Request = Request; | ||
g.Response = Response; | ||
} | ||
@@ -629,0 +666,0 @@ |
@@ -21,13 +21,16 @@ // Save global object in a variable | ||
var global = | ||
/* eslint-disable no-prototype-builtins */ | ||
var g = | ||
(typeof globalThis !== 'undefined' && globalThis) || | ||
(typeof self !== 'undefined' && self) || | ||
(typeof global !== 'undefined' && global); | ||
// eslint-disable-next-line no-undef | ||
(typeof global !== 'undefined' && global) || | ||
{}; | ||
var support = { | ||
searchParams: 'URLSearchParams' in global, | ||
iterable: 'Symbol' in global && 'iterator' in Symbol, | ||
searchParams: 'URLSearchParams' in g, | ||
iterable: 'Symbol' in g && 'iterator' in Symbol, | ||
blob: | ||
'FileReader' in global && | ||
'Blob' in global && | ||
'FileReader' in g && | ||
'Blob' in g && | ||
(function() { | ||
@@ -41,4 +44,4 @@ try { | ||
})(), | ||
formData: 'FormData' in global, | ||
arrayBuffer: 'ArrayBuffer' in global | ||
formData: 'FormData' in g, | ||
arrayBuffer: 'ArrayBuffer' in g | ||
}; | ||
@@ -114,2 +117,5 @@ | ||
headers.forEach(function(header) { | ||
if (header.length != 2) { | ||
throw new TypeError('Headers constructor: expected name/value pair to be length 2, found' + header.length) | ||
} | ||
this.append(header[0], header[1]); | ||
@@ -185,2 +191,3 @@ }, this); | ||
function consumed(body) { | ||
if (body._noBody) return | ||
if (body.bodyUsed) { | ||
@@ -213,3 +220,5 @@ return Promise.reject(new TypeError('Already read')) | ||
var promise = fileReaderReady(reader); | ||
reader.readAsText(blob); | ||
var match = /charset=([A-Za-z0-9_-]+)/.exec(blob.type); | ||
var encoding = match ? match[1] : 'utf-8'; | ||
reader.readAsText(blob, encoding); | ||
return promise | ||
@@ -252,5 +261,7 @@ } | ||
*/ | ||
// eslint-disable-next-line no-self-assign | ||
this.bodyUsed = this.bodyUsed; | ||
this._bodyInit = body; | ||
if (!body) { | ||
this._noBody = true; | ||
this._bodyText = ''; | ||
@@ -303,24 +314,25 @@ } else if (typeof body === 'string') { | ||
}; | ||
} | ||
this.arrayBuffer = function() { | ||
if (this._bodyArrayBuffer) { | ||
var isConsumed = consumed(this); | ||
if (isConsumed) { | ||
return isConsumed | ||
} | ||
if (ArrayBuffer.isView(this._bodyArrayBuffer)) { | ||
return Promise.resolve( | ||
this._bodyArrayBuffer.buffer.slice( | ||
this._bodyArrayBuffer.byteOffset, | ||
this._bodyArrayBuffer.byteOffset + this._bodyArrayBuffer.byteLength | ||
) | ||
this.arrayBuffer = function() { | ||
if (this._bodyArrayBuffer) { | ||
var isConsumed = consumed(this); | ||
if (isConsumed) { | ||
return isConsumed | ||
} else if (ArrayBuffer.isView(this._bodyArrayBuffer)) { | ||
return Promise.resolve( | ||
this._bodyArrayBuffer.buffer.slice( | ||
this._bodyArrayBuffer.byteOffset, | ||
this._bodyArrayBuffer.byteOffset + this._bodyArrayBuffer.byteLength | ||
) | ||
} else { | ||
return Promise.resolve(this._bodyArrayBuffer) | ||
} | ||
) | ||
} else { | ||
return this.blob().then(readBlobAsArrayBuffer) | ||
return Promise.resolve(this._bodyArrayBuffer) | ||
} | ||
}; | ||
} | ||
} else if (support.blob) { | ||
return this.blob().then(readBlobAsArrayBuffer) | ||
} else { | ||
throw new Error('could not read as ArrayBuffer') | ||
} | ||
}; | ||
@@ -358,3 +370,3 @@ this.text = function() { | ||
// HTTP methods whose capitalization should be normalized | ||
var methods = ['DELETE', 'GET', 'HEAD', 'OPTIONS', 'POST', 'PUT']; | ||
var methods = ['CONNECT', 'DELETE', 'GET', 'HEAD', 'OPTIONS', 'PATCH', 'POST', 'PUT', 'TRACE']; | ||
@@ -400,3 +412,8 @@ function normalizeMethod(method) { | ||
this.mode = options.mode || this.mode || null; | ||
this.signal = options.signal || this.signal; | ||
this.signal = options.signal || this.signal || (function () { | ||
if ('AbortController' in g) { | ||
var ctrl = new AbortController(); | ||
return ctrl.signal; | ||
} | ||
}()); | ||
this.referrer = null; | ||
@@ -463,3 +480,7 @@ | ||
var value = parts.join(':').trim(); | ||
headers.append(key, value); | ||
try { | ||
headers.append(key, value); | ||
} catch (error) { | ||
console.warn('Response ' + error.message); | ||
} | ||
} | ||
@@ -482,2 +503,5 @@ }); | ||
this.status = options.status === undefined ? 200 : options.status; | ||
if (this.status < 200 || this.status > 599) { | ||
throw new RangeError("Failed to construct 'Response': The status provided (0) is outside the range [200, 599].") | ||
} | ||
this.ok = this.status >= 200 && this.status < 300; | ||
@@ -502,3 +526,5 @@ this.statusText = options.statusText === undefined ? '' : '' + options.statusText; | ||
Response.error = function() { | ||
var response = new Response(null, {status: 0, statusText: ''}); | ||
var response = new Response(null, {status: 200, statusText: ''}); | ||
response.ok = false; | ||
response.status = 0; | ||
response.type = 'error'; | ||
@@ -518,3 +544,3 @@ return response | ||
exports.DOMException = global.DOMException; | ||
exports.DOMException = g.DOMException; | ||
try { | ||
@@ -549,6 +575,12 @@ new exports.DOMException(); | ||
var options = { | ||
status: xhr.status, | ||
statusText: xhr.statusText, | ||
headers: parseHeaders(xhr.getAllResponseHeaders() || '') | ||
}; | ||
// This check if specifically for when a user fetches a file locally from the file system | ||
// Only if the status is out of a normal range | ||
if (request.url.indexOf('file://') === 0 && (xhr.status < 200 || xhr.status > 599)) { | ||
options.status = 200; | ||
} else { | ||
options.status = xhr.status; | ||
} | ||
options.url = 'responseURL' in xhr ? xhr.responseURL : options.headers.get('X-Request-URL'); | ||
@@ -569,3 +601,3 @@ var body = 'response' in xhr ? xhr.response : xhr.responseText; | ||
setTimeout(function() { | ||
reject(new TypeError('Network request failed')); | ||
reject(new TypeError('Network request timed out')); | ||
}, 0); | ||
@@ -582,3 +614,3 @@ }; | ||
try { | ||
return url === '' && global.location.href ? global.location.href : url | ||
return url === '' && g.location.href ? g.location.href : url | ||
} catch (e) { | ||
@@ -601,5 +633,3 @@ return url | ||
} else if ( | ||
support.arrayBuffer && | ||
request.headers.get('Content-Type') && | ||
request.headers.get('Content-Type').indexOf('application/octet-stream') !== -1 | ||
support.arrayBuffer | ||
) { | ||
@@ -610,6 +640,13 @@ xhr.responseType = 'arraybuffer'; | ||
if (init && typeof init.headers === 'object' && !(init.headers instanceof Headers)) { | ||
if (init && typeof init.headers === 'object' && !(init.headers instanceof Headers || (g.Headers && init.headers instanceof g.Headers))) { | ||
var names = []; | ||
Object.getOwnPropertyNames(init.headers).forEach(function(name) { | ||
names.push(normalizeName(name)); | ||
xhr.setRequestHeader(name, normalizeValue(init.headers[name])); | ||
}); | ||
request.headers.forEach(function(value, name) { | ||
if (names.indexOf(name) === -1) { | ||
xhr.setRequestHeader(name, value); | ||
} | ||
}); | ||
} else { | ||
@@ -638,7 +675,7 @@ request.headers.forEach(function(value, name) { | ||
if (!global.fetch) { | ||
global.fetch = fetch; | ||
global.Headers = Headers; | ||
global.Request = Request; | ||
global.Response = Response; | ||
if (!g.fetch) { | ||
g.fetch = fetch; | ||
g.Headers = Headers; | ||
g.Request = Request; | ||
g.Response = Response; | ||
} | ||
@@ -645,0 +682,0 @@ |
@@ -1,2 +0,3 @@ | ||
!function(t){!function(e){var r="undefined"!=typeof globalThis&&globalThis||void 0!==t&&t||void 0!==r&&r,o="URLSearchParams"in r,n="Symbol"in r&&"iterator"in Symbol,i="FileReader"in r&&"Blob"in r&&function(){try{return new Blob,!0}catch(t){return!1}}(),s="FormData"in r,a="ArrayBuffer"in r;if(a)var h=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],u=ArrayBuffer.isView||function(t){return t&&h.indexOf(Object.prototype.toString.call(t))>-1};function f(t){if("string"!=typeof t&&(t=String(t)),/[^a-z0-9\-#$%&'*+.^_`|~!]/i.test(t)||""===t)throw new TypeError('Invalid character in header field name: "'+t+'"');return t.toLowerCase()}function c(t){return"string"!=typeof t&&(t=String(t)),t}function d(t){var e={next:function(){var e=t.shift();return{done:void 0===e,value:e}}};return n&&(e[Symbol.iterator]=function(){return e}),e}function y(t){this.map={},t instanceof y?t.forEach((function(t,e){this.append(e,t)}),this):Array.isArray(t)?t.forEach((function(t){this.append(t[0],t[1])}),this):t&&Object.getOwnPropertyNames(t).forEach((function(e){this.append(e,t[e])}),this)}function p(t){if(t.bodyUsed)return Promise.reject(new TypeError("Already read"));t.bodyUsed=!0}function l(t){return new Promise((function(e,r){t.onload=function(){e(t.result)},t.onerror=function(){r(t.error)}}))}function b(t){var e=new FileReader,r=l(e);return e.readAsArrayBuffer(t),r}function m(t){if(t.slice)return t.slice(0);var e=new Uint8Array(t.byteLength);return e.set(new Uint8Array(t)),e.buffer}function w(){return this.bodyUsed=!1,this._initBody=function(t){var e;this.bodyUsed=this.bodyUsed,this._bodyInit=t,t?"string"==typeof t?this._bodyText=t:i&&Blob.prototype.isPrototypeOf(t)?this._bodyBlob=t:s&&FormData.prototype.isPrototypeOf(t)?this._bodyFormData=t:o&&URLSearchParams.prototype.isPrototypeOf(t)?this._bodyText=t.toString():a&&i&&((e=t)&&DataView.prototype.isPrototypeOf(e))?(this._bodyArrayBuffer=m(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):a&&(ArrayBuffer.prototype.isPrototypeOf(t)||u(t))?this._bodyArrayBuffer=m(t):this._bodyText=t=Object.prototype.toString.call(t):this._bodyText="",this.headers.get("content-type")||("string"==typeof t?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):o&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},i&&(this.blob=function(){var t=p(this);if(t)return t;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){if(this._bodyArrayBuffer){var t=p(this);return t||(ArrayBuffer.isView(this._bodyArrayBuffer)?Promise.resolve(this._bodyArrayBuffer.buffer.slice(this._bodyArrayBuffer.byteOffset,this._bodyArrayBuffer.byteOffset+this._bodyArrayBuffer.byteLength)):Promise.resolve(this._bodyArrayBuffer))}return this.blob().then(b)}),this.text=function(){var t,e,r,o=p(this);if(o)return o;if(this._bodyBlob)return t=this._bodyBlob,e=new FileReader,r=l(e),e.readAsText(t),r;if(this._bodyArrayBuffer)return Promise.resolve(function(t){for(var e=new Uint8Array(t),r=new Array(e.length),o=0;o<e.length;o++)r[o]=String.fromCharCode(e[o]);return r.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},s&&(this.formData=function(){return this.text().then(T)}),this.json=function(){return this.text().then(JSON.parse)},this}y.prototype.append=function(t,e){t=f(t),e=c(e);var r=this.map[t];this.map[t]=r?r+", "+e:e},y.prototype.delete=function(t){delete this.map[f(t)]},y.prototype.get=function(t){return t=f(t),this.has(t)?this.map[t]:null},y.prototype.has=function(t){return this.map.hasOwnProperty(f(t))},y.prototype.set=function(t,e){this.map[f(t)]=c(e)},y.prototype.forEach=function(t,e){for(var r in this.map)this.map.hasOwnProperty(r)&&t.call(e,this.map[r],r,this)},y.prototype.keys=function(){var t=[];return this.forEach((function(e,r){t.push(r)})),d(t)},y.prototype.values=function(){var t=[];return this.forEach((function(e){t.push(e)})),d(t)},y.prototype.entries=function(){var t=[];return this.forEach((function(e,r){t.push([r,e])})),d(t)},n&&(y.prototype[Symbol.iterator]=y.prototype.entries);var v=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function E(t,e){if(!(this instanceof E))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');var r,o,n=(e=e||{}).body;if(t instanceof E){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,e.headers||(this.headers=new y(t.headers)),this.method=t.method,this.mode=t.mode,this.signal=t.signal,n||null==t._bodyInit||(n=t._bodyInit,t.bodyUsed=!0)}else this.url=String(t);if(this.credentials=e.credentials||this.credentials||"same-origin",!e.headers&&this.headers||(this.headers=new y(e.headers)),this.method=(r=e.method||this.method||"GET",o=r.toUpperCase(),v.indexOf(o)>-1?o:r),this.mode=e.mode||this.mode||null,this.signal=e.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&n)throw new TypeError("Body not allowed for GET or HEAD requests");if(this._initBody(n),!("GET"!==this.method&&"HEAD"!==this.method||"no-store"!==e.cache&&"no-cache"!==e.cache)){var i=/([?&])_=[^&]*/;if(i.test(this.url))this.url=this.url.replace(i,"$1_="+(new Date).getTime());else{this.url+=(/\?/.test(this.url)?"&":"?")+"_="+(new Date).getTime()}}}function T(t){var e=new FormData;return t.trim().split("&").forEach((function(t){if(t){var r=t.split("="),o=r.shift().replace(/\+/g," "),n=r.join("=").replace(/\+/g," ");e.append(decodeURIComponent(o),decodeURIComponent(n))}})),e}function A(t,e){if(!(this instanceof A))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');e||(e={}),this.type="default",this.status=void 0===e.status?200:e.status,this.ok=this.status>=200&&this.status<300,this.statusText=void 0===e.statusText?"":""+e.statusText,this.headers=new y(e.headers),this.url=e.url||"",this._initBody(t)}E.prototype.clone=function(){return new E(this,{body:this._bodyInit})},w.call(E.prototype),w.call(A.prototype),A.prototype.clone=function(){return new A(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new y(this.headers),url:this.url})},A.error=function(){var t=new A(null,{status:0,statusText:""});return t.type="error",t};var _=[301,302,303,307,308];A.redirect=function(t,e){if(-1===_.indexOf(e))throw new RangeError("Invalid status code");return new A(null,{status:e,headers:{location:t}})},e.DOMException=r.DOMException;try{new e.DOMException}catch(t){e.DOMException=function(t,e){this.message=t,this.name=e;var r=Error(t);this.stack=r.stack},e.DOMException.prototype=Object.create(Error.prototype),e.DOMException.prototype.constructor=e.DOMException}function g(t,o){return new Promise((function(n,s){var h=new E(t,o);if(h.signal&&h.signal.aborted)return s(new e.DOMException("Aborted","AbortError"));var u=new XMLHttpRequest;function f(){u.abort()}u.onload=function(){var t,e,r={status:u.status,statusText:u.statusText,headers:(t=u.getAllResponseHeaders()||"",e=new y,t.replace(/\r?\n[\t ]+/g," ").split("\r").map((function(t){return 0===t.indexOf("\n")?t.substr(1,t.length):t})).forEach((function(t){var r=t.split(":"),o=r.shift().trim();if(o){var n=r.join(":").trim();e.append(o,n)}})),e)};r.url="responseURL"in u?u.responseURL:r.headers.get("X-Request-URL");var o="response"in u?u.response:u.responseText;setTimeout((function(){n(new A(o,r))}),0)},u.onerror=function(){setTimeout((function(){s(new TypeError("Network request failed"))}),0)},u.ontimeout=function(){setTimeout((function(){s(new TypeError("Network request failed"))}),0)},u.onabort=function(){setTimeout((function(){s(new e.DOMException("Aborted","AbortError"))}),0)},u.open(h.method,function(t){try{return""===t&&r.location.href?r.location.href:t}catch(e){return t}}(h.url),!0),"include"===h.credentials?u.withCredentials=!0:"omit"===h.credentials&&(u.withCredentials=!1),"responseType"in u&&(i?u.responseType="blob":a&&h.headers.get("Content-Type")&&-1!==h.headers.get("Content-Type").indexOf("application/octet-stream")&&(u.responseType="arraybuffer")),!o||"object"!=typeof o.headers||o.headers instanceof y?h.headers.forEach((function(t,e){u.setRequestHeader(e,t)})):Object.getOwnPropertyNames(o.headers).forEach((function(t){u.setRequestHeader(t,c(o.headers[t]))})),h.signal&&(h.signal.addEventListener("abort",f),u.onreadystatechange=function(){4===u.readyState&&h.signal.removeEventListener("abort",f)}),u.send(void 0===h._bodyInit?null:h._bodyInit)}))}g.polyfill=!0,r.fetch||(r.fetch=g,r.Headers=y,r.Request=E,r.Response=A),e.Headers=y,e.Request=E,e.Response=A,e.fetch=g}({})}("undefined"!=typeof self?self:this); | ||
(function(E){var C=function(h){var a=typeof globalThis<"u"&&globalThis||typeof E<"u"&&E||typeof global<"u"&&global||{},u={searchParams:"URLSearchParams"in a,iterable:"Symbol"in a&&"iterator"in Symbol,blob:"FileReader"in a&&"Blob"in a&&function(){try{return new Blob,!0}catch{return!1}}(),formData:"FormData"in a,arrayBuffer:"ArrayBuffer"in a};function O(e){return e&&DataView.prototype.isPrototypeOf(e)}if(u.arrayBuffer)var x=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],D=ArrayBuffer.isView||function(e){return e&&x.indexOf(Object.prototype.toString.call(e))>-1};function y(e){if(typeof e!="string"&&(e=String(e)),/[^a-z0-9\-#$%&'*+.^_`|~!]/i.test(e)||e==="")throw new TypeError('Invalid character in header field name: "'+e+'"');return e.toLowerCase()}function b(e){return typeof e!="string"&&(e=String(e)),e}function w(e){var t={next:function(){var r=e.shift();return{done:r===void 0,value:r}}};return u.iterable&&(t[Symbol.iterator]=function(){return t}),t}function i(e){this.map={},e instanceof i?e.forEach(function(t,r){this.append(r,t)},this):Array.isArray(e)?e.forEach(function(t){if(t.length!=2)throw new TypeError("Headers constructor: expected name/value pair to be length 2, found"+t.length);this.append(t[0],t[1])},this):e&&Object.getOwnPropertyNames(e).forEach(function(t){this.append(t,e[t])},this)}i.prototype.append=function(e,t){e=y(e),t=b(t);var r=this.map[e];this.map[e]=r?r+", "+t:t},i.prototype.delete=function(e){delete this.map[y(e)]},i.prototype.get=function(e){return e=y(e),this.has(e)?this.map[e]:null},i.prototype.has=function(e){return this.map.hasOwnProperty(y(e))},i.prototype.set=function(e,t){this.map[y(e)]=b(t)},i.prototype.forEach=function(e,t){for(var r in this.map)this.map.hasOwnProperty(r)&&e.call(t,this.map[r],r,this)},i.prototype.keys=function(){var e=[];return this.forEach(function(t,r){e.push(r)}),w(e)},i.prototype.values=function(){var e=[];return this.forEach(function(t){e.push(t)}),w(e)},i.prototype.entries=function(){var e=[];return this.forEach(function(t,r){e.push([r,t])}),w(e)},u.iterable&&(i.prototype[Symbol.iterator]=i.prototype.entries);function m(e){if(!e._noBody){if(e.bodyUsed)return Promise.reject(new TypeError("Already read"));e.bodyUsed=!0}}function g(e){return new Promise(function(t,r){e.onload=function(){t(e.result)},e.onerror=function(){r(e.error)}})}function P(e){var t=new FileReader,r=g(t);return t.readAsArrayBuffer(e),r}function R(e){var t=new FileReader,r=g(t),n=/charset=([A-Za-z0-9_-]+)/.exec(e.type),s=n?n[1]:"utf-8";return t.readAsText(e,s),r}function U(e){for(var t=new Uint8Array(e),r=new Array(t.length),n=0;n<t.length;n++)r[n]=String.fromCharCode(t[n]);return r.join("")}function T(e){if(e.slice)return e.slice(0);var t=new Uint8Array(e.byteLength);return t.set(new Uint8Array(e)),t.buffer}function B(){return this.bodyUsed=!1,this._initBody=function(e){this.bodyUsed=this.bodyUsed,this._bodyInit=e,e?typeof e=="string"?this._bodyText=e:u.blob&&Blob.prototype.isPrototypeOf(e)?this._bodyBlob=e:u.formData&&FormData.prototype.isPrototypeOf(e)?this._bodyFormData=e:u.searchParams&&URLSearchParams.prototype.isPrototypeOf(e)?this._bodyText=e.toString():u.arrayBuffer&&u.blob&&O(e)?(this._bodyArrayBuffer=T(e.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):u.arrayBuffer&&(ArrayBuffer.prototype.isPrototypeOf(e)||D(e))?this._bodyArrayBuffer=T(e):this._bodyText=e=Object.prototype.toString.call(e):(this._noBody=!0,this._bodyText=""),this.headers.get("content-type")||(typeof e=="string"?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):u.searchParams&&URLSearchParams.prototype.isPrototypeOf(e)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},u.blob&&(this.blob=function(){var e=m(this);if(e)return e;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))}),this.arrayBuffer=function(){if(this._bodyArrayBuffer){var e=m(this);return e||(ArrayBuffer.isView(this._bodyArrayBuffer)?Promise.resolve(this._bodyArrayBuffer.buffer.slice(this._bodyArrayBuffer.byteOffset,this._bodyArrayBuffer.byteOffset+this._bodyArrayBuffer.byteLength)):Promise.resolve(this._bodyArrayBuffer))}else{if(u.blob)return this.blob().then(P);throw new Error("could not read as ArrayBuffer")}},this.text=function(){var e=m(this);if(e)return e;if(this._bodyBlob)return R(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(U(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},u.formData&&(this.formData=function(){return this.text().then(S)}),this.json=function(){return this.text().then(JSON.parse)},this}var j=["CONNECT","DELETE","GET","HEAD","OPTIONS","PATCH","POST","PUT","TRACE"];function H(e){var t=e.toUpperCase();return j.indexOf(t)>-1?t:e}function l(e,t){if(!(this instanceof l))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');t=t||{};var r=t.body;if(e instanceof l){if(e.bodyUsed)throw new TypeError("Already read");this.url=e.url,this.credentials=e.credentials,t.headers||(this.headers=new i(e.headers)),this.method=e.method,this.mode=e.mode,this.signal=e.signal,!r&&e._bodyInit!=null&&(r=e._bodyInit,e.bodyUsed=!0)}else this.url=String(e);if(this.credentials=t.credentials||this.credentials||"same-origin",(t.headers||!this.headers)&&(this.headers=new i(t.headers)),this.method=H(t.method||this.method||"GET"),this.mode=t.mode||this.mode||null,this.signal=t.signal||this.signal||function(){if("AbortController"in a){var o=new AbortController;return o.signal}}(),this.referrer=null,(this.method==="GET"||this.method==="HEAD")&&r)throw new TypeError("Body not allowed for GET or HEAD requests");if(this._initBody(r),(this.method==="GET"||this.method==="HEAD")&&(t.cache==="no-store"||t.cache==="no-cache")){var n=/([?&])_=[^&]*/;if(n.test(this.url))this.url=this.url.replace(n,"$1_="+new Date().getTime());else{var s=/\?/;this.url+=(s.test(this.url)?"&":"?")+"_="+new Date().getTime()}}}l.prototype.clone=function(){return new l(this,{body:this._bodyInit})};function S(e){var t=new FormData;return e.trim().split("&").forEach(function(r){if(r){var n=r.split("="),s=n.shift().replace(/\+/g," "),o=n.join("=").replace(/\+/g," ");t.append(decodeURIComponent(s),decodeURIComponent(o))}}),t}function F(e){var t=new i,r=e.replace(/\r?\n[\t ]+/g," ");return r.split("\r").map(function(n){return n.indexOf(` | ||
`)===0?n.substr(1,n.length):n}).forEach(function(n){var s=n.split(":"),o=s.shift().trim();if(o){var p=s.join(":").trim();try{t.append(o,p)}catch(A){console.warn("Response "+A.message)}}}),t}B.call(l.prototype);function c(e,t){if(!(this instanceof c))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');if(t||(t={}),this.type="default",this.status=t.status===void 0?200:t.status,this.status<200||this.status>599)throw new RangeError("Failed to construct 'Response': The status provided (0) is outside the range [200, 599].");this.ok=this.status>=200&&this.status<300,this.statusText=t.statusText===void 0?"":""+t.statusText,this.headers=new i(t.headers),this.url=t.url||"",this._initBody(e)}B.call(c.prototype),c.prototype.clone=function(){return new c(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new i(this.headers),url:this.url})},c.error=function(){var e=new c(null,{status:200,statusText:""});return e.ok=!1,e.status=0,e.type="error",e};var I=[301,302,303,307,308];c.redirect=function(e,t){if(I.indexOf(t)===-1)throw new RangeError("Invalid status code");return new c(null,{status:t,headers:{location:e}})},h.DOMException=a.DOMException;try{new h.DOMException}catch{h.DOMException=function(t,r){this.message=t,this.name=r;var n=Error(t);this.stack=n.stack},h.DOMException.prototype=Object.create(Error.prototype),h.DOMException.prototype.constructor=h.DOMException}function v(e,t){return new Promise(function(r,n){var s=new l(e,t);if(s.signal&&s.signal.aborted)return n(new h.DOMException("Aborted","AbortError"));var o=new XMLHttpRequest;function p(){o.abort()}o.onload=function(){var f={statusText:o.statusText,headers:F(o.getAllResponseHeaders()||"")};s.url.indexOf("file://")===0&&(o.status<200||o.status>599)?f.status=200:f.status=o.status,f.url="responseURL"in o?o.responseURL:f.headers.get("X-Request-URL");var d="response"in o?o.response:o.responseText;setTimeout(function(){r(new c(d,f))},0)},o.onerror=function(){setTimeout(function(){n(new TypeError("Network request failed"))},0)},o.ontimeout=function(){setTimeout(function(){n(new TypeError("Network request timed out"))},0)},o.onabort=function(){setTimeout(function(){n(new h.DOMException("Aborted","AbortError"))},0)};function A(f){try{return f===""&&a.location.href?a.location.href:f}catch{return f}}if(o.open(s.method,A(s.url),!0),s.credentials==="include"?o.withCredentials=!0:s.credentials==="omit"&&(o.withCredentials=!1),"responseType"in o&&(u.blob?o.responseType="blob":u.arrayBuffer&&(o.responseType="arraybuffer")),t&&typeof t.headers=="object"&&!(t.headers instanceof i||a.Headers&&t.headers instanceof a.Headers)){var _=[];Object.getOwnPropertyNames(t.headers).forEach(function(f){_.push(y(f)),o.setRequestHeader(f,b(t.headers[f]))}),s.headers.forEach(function(f,d){_.indexOf(d)===-1&&o.setRequestHeader(d,f)})}else s.headers.forEach(function(f,d){o.setRequestHeader(d,f)});s.signal&&(s.signal.addEventListener("abort",p),o.onreadystatechange=function(){o.readyState===4&&s.signal.removeEventListener("abort",p)}),o.send(typeof s._bodyInit>"u"?null:s._bodyInit)})}return v.polyfill=!0,a.fetch||(a.fetch=v,a.Headers=i,a.Request=l,a.Response=c),h.Headers=i,h.Request=l,h.Response=c,h.fetch=v,h}({})})(typeof self<"u"?self:this); | ||
//# sourceMappingURL=cross-fetch.js.map |
{ | ||
"name": "cross-fetch", | ||
"version": "4.0.0", | ||
"version": "4.1.0", | ||
"description": "Universal WHATWG Fetch API for Node, Browsers and React Native", | ||
@@ -71,3 +71,3 @@ "homepage": "https://github.com/lquixada/cross-fetch", | ||
"dependencies": { | ||
"node-fetch": "^2.6.12" | ||
"node-fetch": "^2.7.0" | ||
}, | ||
@@ -77,3 +77,2 @@ "devDependencies": { | ||
"@commitlint/config-conventional": "17.6.6", | ||
"@rollup/plugin-terser": "0.4.3", | ||
"@types/chai": "4.3.5", | ||
@@ -97,2 +96,4 @@ "@types/mocha": "10.0.1", | ||
"rollup-plugin-copy": "3.4.0", | ||
"rollup-plugin-esbuild": "6.1.1", | ||
"rollup-plugin-esbuild-minify": "1.1.2", | ||
"semver": "7.5.3", | ||
@@ -105,3 +106,3 @@ "serve-index": "1.9.1", | ||
"webpack-cli": "5.1.4", | ||
"whatwg-fetch": "3.6.2", | ||
"whatwg-fetch": "3.6.20", | ||
"yargs": "17.7.2" | ||
@@ -108,0 +109,0 @@ }, |
@@ -23,3 +23,2 @@ cross-fetch<br> | ||
- [Table of Contents](#table-of-contents) | ||
- [Install](#install) | ||
@@ -26,0 +25,0 @@ - [Usage](#usage) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
93252
1270
31
13
165
Updatednode-fetch@^2.7.0