gmxhr-fetch
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -10,10 +10,7 @@ ;((global, fn) => { | ||
} | ||
const fromEntries = e => e.reduce((acc, [k, v]) => ((acc[k] = v), acc), {}) | ||
const parseHeader = h => | ||
fromEntries( | ||
h | ||
.split('\n') | ||
.filter(Boolean) | ||
.map(l => l.split(':').map(tok => tok.trim())) | ||
) | ||
const splitHeaderLine = l => { | ||
const i = l.indexOf(':') | ||
return [l.slice(0, i), l.slice(i + 1).trimLeft()] | ||
} | ||
const parseHeader = h => Object.fromEntries(h.split('\r\n').filter(Boolean).map(splitHeaderLine)) | ||
const fetch = (input, init = {}) => { | ||
@@ -20,0 +17,0 @@ if (input instanceof Request) { |
@@ -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);const b=a=>a.reduce((a,[b,c])=>(a[b]=c,a),{}),c=a=>b(a.split("\n").filter(Boolean).map(a=>a.split(":").map(a=>a.trim()))),d=(e,f={})=>e instanceof Request?d(e.url,Object.assign({},e,f)):new Promise(d=>{f.headers instanceof Headers&&(f.headers=b(Array.from(f.headers.entries()))),f.data=f.body,f=Object.assign({method:"GET",headers:{}},f,{url:e,responseType:"blob"}),a.xmlHttpRequest(Object.assign({},f,{onload:a=>{a.headers=c(a.responseHeaders),d(new Response(a.response,Object.assign({},f,a)))},onerror:a=>{console.log("err",a),d(new Response(a.response,Object.assign({},f,a)))}}))});return 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);const b=a=>{const b=a.indexOf(":");return[a.slice(0,b),a.slice(b+1).trimLeft()]},c=a=>Object.fromEntries(a.split("\r\n").filter(Boolean).map(b)),d=(b,e={})=>b instanceof Request?d(b.url,Object.assign({},b,e)):new Promise(d=>{e.headers instanceof Headers&&(e.headers=fromEntries(Array.from(e.headers.entries()))),e.data=e.body,e=Object.assign({method:"GET",headers:{}},e,{url:b,responseType:"blob"}),a.xmlHttpRequest(Object.assign({},e,{onload:a=>{a.headers=c(a.responseHeaders),d(new Response(a.response,Object.assign({},e,a)))},onerror:a=>{console.log("err",a),d(new Response(a.response,Object.assign({},e,a)))}}))});return d}); |
{ | ||
"name": "gmxhr-fetch", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "fetch-like wrapper for GM_xmlhttpRequest.", | ||
@@ -5,0 +5,0 @@ "main": "gmxhr-fetch.js", |
3126
50