gmxhr-fetch
Advanced tools
Comparing version 0.0.4 to 0.0.5
@@ -16,13 +16,9 @@ ;((global, fn) => { | ||
} | ||
get _arrayBuffer() { | ||
const te = new TextEncoder() | ||
return te.encode(this.xhr.response) | ||
} | ||
arrayBuffer() { | ||
this._bodyUsed = true | ||
return Promise.resolve(this._arrayBuffer) | ||
return Promise.resolve(this.xhr.response) | ||
} | ||
blob() { | ||
this._bodyUsed = true | ||
return Promise.resolve(new Blob([this._arrayBuffer])) | ||
return Promise.resolve(new Blob([this.xhr.response])) | ||
} | ||
@@ -36,7 +32,10 @@ formData() { | ||
this._bodyUsed = true | ||
return Promise.resolve(JSON.parse(this.xhr.response)) | ||
return Promise.resolve(JSON.parse(this._text)) | ||
} | ||
get _text() { | ||
return (this._ct = this._ct || new TextDecoder.decode(this.xhr.response)) | ||
} | ||
text() { | ||
this._bodyUsed = true | ||
return Promise.resolve(this.xhr.response) | ||
return Promise.resolve(this._text) | ||
} | ||
@@ -91,3 +90,3 @@ clone() { | ||
url: input, | ||
responseType: 'text' | ||
responseType: 'arraybuffer' | ||
} | ||
@@ -94,0 +93,0 @@ ) |
@@ -1,1 +0,1 @@ | ||
((a,b)=>{a.gmfetch=b("undefined"==typeof GM?{}:GM)})(this,a=>{if("undefined"==typeof GM_xmlhttpRequest&&"undefined"==typeof a.xmlHttpRequest)throw new Error("Either GM_xmlhttpRequest or GM.xmlHttpRequest must exists!");"function"!=typeof GM_xmlhttpRequest||a.xmlHttpRequest||(a.xmlHttpRequest=GM_xmlhttpRequest);class b{constructor(a,b){this.xhr=a,this.init=b,this._bodyUsed=!1}get _arrayBuffer(){const a=new TextEncoder;return a.encode(this.xhr.response)}arrayBuffer(){return this._bodyUsed=!0,Promise.resolve(this._arrayBuffer)}blob(){return this._bodyUsed=!0,Promise.resolve(new Blob([this._arrayBuffer]))}formData(){throw this._bodyUsed=!0,new Error("Not implemented!")}json(){return this._bodyUsed=!0,Promise.resolve(JSON.parse(this.xhr.response))}text(){return this._bodyUsed=!0,Promise.resolve(this.xhr.response)}clone(){return Object.assign({},this)}redirect(){return this.clone()}get ok(){return 200<=this.xhr.status&&300>this.xhr.status}get headers(){return new Headers(this.xhr.headers)}get status(){return this.xhr.status}get statusText(){return this.xhr.statusText}get type(){return"cors"}get url(){return this.init.url}get bodyUsed(){return this._bodyUsed}get redirected(){return!0}get useFinalURL(){return!0}}return(c,d={})=>new Promise(e=>{d=Object.assign({method:"GET",headers:{}},d,{url:c,responseType:"text"}),a.xmlHttpRequest(Object.assign({},d,{onload:a=>e(new b(a,d)),onerror:a=>e(new b(a,d))}))})}); | ||
((a,b)=>{a.gmfetch=b("undefined"==typeof GM?{}:GM)})(this,a=>{if("undefined"==typeof GM_xmlhttpRequest&&"undefined"==typeof a.xmlHttpRequest)throw new Error("Either GM_xmlhttpRequest or GM.xmlHttpRequest must exists!");"function"!=typeof GM_xmlhttpRequest||a.xmlHttpRequest||(a.xmlHttpRequest=GM_xmlhttpRequest);class b{constructor(a,b){this.xhr=a,this.init=b,this._bodyUsed=!1}arrayBuffer(){return this._bodyUsed=!0,Promise.resolve(this.xhr.response)}blob(){return this._bodyUsed=!0,Promise.resolve(new Blob([this.xhr.response]))}formData(){throw this._bodyUsed=!0,new Error("Not implemented!")}json(){return this._bodyUsed=!0,Promise.resolve(JSON.parse(this._text))}get _text(){return this._ct=this._ct||new TextDecoder.decode(this.xhr.response)}text(){return this._bodyUsed=!0,Promise.resolve(this._text)}clone(){return Object.assign({},this)}redirect(){return this.clone()}get ok(){return 200<=this.xhr.status&&300>this.xhr.status}get headers(){return new Headers(this.xhr.headers)}get status(){return this.xhr.status}get statusText(){return this.xhr.statusText}get type(){return"cors"}get url(){return this.init.url}get bodyUsed(){return this._bodyUsed}get redirected(){return!0}get useFinalURL(){return!0}}return(c,d={})=>new Promise(e=>{d=Object.assign({method:"GET",headers:{}},d,{url:c,responseType:"arraybuffer"}),a.xmlHttpRequest(Object.assign({},d,{onload:a=>e(new b(a,d)),onerror:a=>e(new b(a,d))}))})}); |
{ | ||
"name": "gmxhr-fetch", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "fetch-like wrapper for GM_xmlhttpRequest.", | ||
@@ -5,0 +5,0 @@ "main": "gmxhr-fetch.js", |
4264
99