mirror of
https://github.com/Wessel/wumpfetch.git
synced 2026-07-06 16:03:36 +02:00
Small little improvement
This commit is contained in:
@@ -8,7 +8,7 @@ module.exports = (url, method) => {
|
||||
};
|
||||
|
||||
common.forEach((v) => {
|
||||
module.exports[v.toLowerCase()] = (url, method = v) => {
|
||||
return new request(url, method);
|
||||
module.exports[v.toLowerCase()] = (url, method) => {
|
||||
return new request(url, Object.assign({ method: v }, method));
|
||||
}
|
||||
});
|
||||
2
dist/wumpfetch.concat.js
vendored
2
dist/wumpfetch.concat.js
vendored
@@ -187,6 +187,6 @@ module.exports = w;
|
||||
|
||||
common.forEach((v) => {
|
||||
module.exports[v.toLowerCase()] = (url, method = v) => {
|
||||
return new WumpRequest(url, method);
|
||||
return new request(url, Object.assign({ method: v }, method));
|
||||
}
|
||||
});
|
||||
1
dist/wumpfetch.concat.min.js
vendored
1
dist/wumpfetch.concat.min.js
vendored
@@ -1 +0,0 @@
|
||||
const http=require("http"),https=require("https"),{URL:URL}=require("url"),{join:join}=require("path"),{stringify:stringify}=require("querystring"),{createGunzip:createGunzip,createInflate:createInflate}=require("zlib"),c=["gzip","deflate"],common=["GET","HEAD","POST","PUT","DELETE","CONNECT","OPTIONS","TRACE","PATCH"],WumpResponse=class{constructor(t){this.body=Buffer.alloc(0),this.coreRes=t,this.headers=t.headers,this.statusCode=t.statusCode}_addChunk(t){this.body=Buffer.concat([this.body,t])}text(){return this.body.toString()}json(){return JSON.parse(this.body)}},WumpRequest=class{constructor(t={},e={}){const o="string"==typeof t?e:t,r="object"==typeof o;if("string"!=typeof t&&!o.hasOwnProperty("url"))throw new Error("Missing url parameter");return this.o={m:"string"==typeof o?o:r&&o.method?o.method:"GET",url:"string"==typeof t?new URL(t):r&&"string"==typeof o.url?new URL(o.url):t,SDA:r&&"string"==typeof o.sendDataAs?o.sendDataAs:void 0,data:r&&o.data?o.data:r&&o.form?stringify(o.form):void 0,parse:r&&o.parse?o.parse:void 0,follow:!(!r||!o.followRedirects),rHeaders:r&&"object"==typeof o.headers?o.headers:{},streamed:!(!r||!o.streamed),compressed:!(!r||!o.compressed),timeoutTime:r&&"number"==typeof o.timeout?o.timeout:null,coreOptions:r&&"object"==typeof o.coreOptions?o.coreOptions:{}},"object"==typeof o.core&&Object.keys(o.core).forEach(t=>this.option(t,o.core[t])),this}query(t,e){return"object"==typeof t?Object.keys(t).forEach(e=>this.o.url.searchParams.append(e,t[e])):this.o.url.searchParams.append(t,e),this}body(t,e){return this.o.SDA="object"!=typeof t||e||Buffer.isBuffer(t)?e?e.toLowerCase():"buffer":"json",this.o.data="form"===this.SDA?stringify(t):"json"===this.SDA?JSON.stringify(t):t,this}header(t,e){return"object"==typeof t?Object.keys(t).forEach(e=>this.o.rHeaders[e.toLowerCase()]=t[e]):this.o.rHeaders[t.toLowerCase()]=e,this}compress(){return this.compressed=!0,this.o.rHeaders["accept-encoding"]||(this.o.rHeaders["accept-encoding"]=c.join(", ")),this}path(t){return this.o.url.pathname=join(this.o.url.pathname,t),this}stream(){return this.o.streamed=!0,this}option(t,e){return this.o.coreOptions[t]=e,this}timeout(t){return this.o.timeoutTime=t,this}send(){return new Promise((t,e)=>{let o;this.o.data&&(this.o.rHeaders.hasOwnProperty("user-agent")||(this.o.rHeaders["User-Agent"]="wumpfetch/0.0.1 (https://github.com/PassTheWessel/wumpfetch)"),"json"!==this.o.SDA||this.o.rHeaders.hasOwnProperty("content-type")||(this.o.rHeaders["Content-Type"]="application/json"),"form"===this.o.SDA&&(this.o.rHeaders.hasOwnProperty("content-type")||(this.o.rHeaders["Content-Type"]="application/x-www-form-urlencoded"),this.o.rHeaders.hasOwnProperty("content-length")||(this.o.rHeaders["Content-Length"]=Buffer.byteLength(this.o.data))));const r=Object.assign({host:this.o.url.hostname,port:this.o.url.port,path:this.o.url.pathname+this.o.url.search,method:this.o.m,headers:this.o.rHeaders,protocol:this.o.url.protocol},this.o.coreOptions),s=async o=>{let r,s=o;if(this.o.compressed&&("gzip"===o.headers["content-encoding"]?s=o.pipe(createGunzip()):"deflate"===o.headers["content-encoding"]&&(s=o.pipe(createInflate()))),this.o.streamed)t(s);else{if(r=new WumpResponse(o),o.headers.hasOwnProperty("location")&&this.o.follow)return this.o.url=new URL(o.headers.location,this.o.url).toString(),await w(this.o);s.on("error",t=>e(t)),s.on("data",t=>r._addChunk(t)),s.on("end",()=>{this.o.parse&&("json"===this.o.parse?r.body=JSON.parse(r.body):"text"===this.o.parse?r.body=r.body.toString():r.body=r.body),t(r)})}};if("http:"===this.o.url.protocol)o=http.request(r,s);else{if("https:"!==this.o.url.protocol)throw new Error(`Bad URL protocol: ${this.o.url.protocol}`);o=https.request(r,s)}this.o.timeoutTime&&o.setTimeout(this.o.timeoutTime,()=>{o.abort(),this.o.streamed||e(new Error("Timeout reached"))}),o.on("error",t=>e(t)),this.o.data&&o.write("json"===this.o.SDA?JSON.stringify(this.o.data):this.o.data),o.end()})}};function w(t,e){return new WumpRequest(t,e)}module.exports=w,common.forEach(t=>{module.exports[t.toLowerCase()]=((e,o=t)=>new WumpRequest(e,o))});
|
||||
2
dist/wumpfetch.min.js
vendored
2
dist/wumpfetch.min.js
vendored
@@ -1 +1 @@
|
||||
const http=require("http"),https=require("https"),{URL:URL}=require("url"),{join:join}=require("path"),{stringify:stringify}=require("querystring"),{createGunzip:createGunzip,createInflate:createInflate}=require("zlib"),c=["gzip","deflate"],common=["GET","HEAD","POST","PUT","DELETE","CONNECT","OPTIONS","TRACE","PATCH"],WumpResponse=class{constructor(e){this.body=Buffer.alloc(0),this.coreRes=e,this.headers=e.headers,this.statusCode=e.statusCode}_addChunk(e){this.body=Buffer.concat([this.body,e])}text(){return this.body.toString()}json(){return JSON.parse(this.body)}},WumpRequest=class{constructor(e={},t={}){const o="string"==typeof e?t:e,r="object"==typeof o;if("string"!=typeof e&&!o.hasOwnProperty("url"))throw new Error("Missing url parameter");return this.o={m:"string"==typeof o?o:r&&o.method?o.method:"GET",url:"string"==typeof e?new URL(e):r&&"string"==typeof o.url?new URL(o.url):e,SDA:r&&"string"==typeof o.sendDataAs?o.sendDataAs:void 0,data:r&&o.data?o.data:r&&o.form?stringify(o.form):void 0,parse:r&&o.parse?o.parse:void 0,follow:!(!r||!o.followRedirects),rHeaders:r&&"object"==typeof o.headers?o.headers:{},streamed:!(!r||!o.streamed),compressed:!(!r||!o.compressed),timeoutTime:r&&"number"==typeof o.timeout?o.timeout:null,coreOptions:r&&"object"==typeof o.coreOptions?o.coreOptions:{}},"object"==typeof o.core&&Object.keys(o.core).forEach(e=>this.option(e,o.core[e])),this}query(e,t){return"object"==typeof e?Object.keys(e).forEach(t=>this.o.url.searchParams.append(t,e[t])):this.o.url.searchParams.append(e,t),this}body(e,t){return this.o.SDA="object"!=typeof e||t||Buffer.isBuffer(e)?t?t.toLowerCase():"buffer":"json",this.o.data="form"===this.SDA?stringify(e):"json"===this.SDA?JSON.stringify(e):e,this}header(e,t){return"object"==typeof e?Object.keys(e).forEach(t=>this.o.rHeaders[t.toLowerCase()]=e[t]):this.o.rHeaders[e.toLowerCase()]=t,this}compress(){return this.compressed=!0,this.o.rHeaders["accept-encoding"]||(this.o.rHeaders["accept-encoding"]=c.join(", ")),this}path(e){return this.o.url.pathname=join(this.o.url.pathname,e),this}stream(){return this.o.streamed=!0,this}option(e,t){return this.o.coreOptions[e]=t,this}timeout(e){return this.o.timeoutTime=e,this}send(){return new Promise((e,t)=>{let o;this.o.data&&(this.o.rHeaders.hasOwnProperty("user-agent")||(this.o.rHeaders["User-Agent"]="wumpfetch/0.0.1 (https://github.com/PassTheWessel/wumpfetch)"),"json"!==this.o.SDA||this.o.rHeaders.hasOwnProperty("content-type")||(this.o.rHeaders["Content-Type"]="application/json"),"form"===this.o.SDA&&(this.o.rHeaders.hasOwnProperty("content-type")||(this.o.rHeaders["Content-Type"]="application/x-www-form-urlencoded"),this.o.rHeaders.hasOwnProperty("content-length")||(this.o.rHeaders["Content-Length"]=Buffer.byteLength(this.o.data))));const r=Object.assign({host:this.o.url.hostname,port:this.o.url.port,path:this.o.url.pathname+this.o.url.search,method:this.o.m,headers:this.o.rHeaders,protocol:this.o.url.protocol},this.o.coreOptions),s=async o=>{let r,s=o;if(this.o.compressed&&("gzip"===o.headers["content-encoding"]?s=o.pipe(createGunzip()):"deflate"===o.headers["content-encoding"]&&(s=o.pipe(createInflate()))),this.o.streamed)e(s);else{if(r=new WumpResponse(o),o.headers.hasOwnProperty("location")&&this.o.follow)return this.o.url=new URL(o.headers.location,this.o.url).toString(),await w(this.o);s.on("error",e=>t(e)),s.on("data",e=>r._addChunk(e)),s.on("end",()=>{this.o.parse&&("json"===this.o.parse?r.body=JSON.parse(r.body):"text"===this.o.parse?r.body=r.body.toString():r.body=r.body),e(r)})}};if("http:"===this.o.url.protocol)o=http.request(r,s);else{if("https:"!==this.o.url.protocol)throw new Error(`Bad URL protocol: ${this.o.url.protocol}`);o=https.request(r,s)}this.o.timeoutTime&&o.setTimeout(this.o.timeoutTime,()=>{o.abort(),this.o.streamed||t(new Error("Timeout reached"))}),o.on("error",e=>t(e)),this.o.data&&o.write(JSON.stringify(this.o.data)),o.end()})}};function w(e,t){return new WumpRequest(e,t)}module.exports=w,common.forEach(e=>{module.exports[e.toLowerCase()]=((t,o=e)=>new WumpRequest(t,o))});
|
||||
const http=require("http"),https=require("https"),{URL:URL}=require("url"),{join:join}=require("path"),{stringify:stringify}=require("querystring"),{createGunzip:createGunzip,createInflate:createInflate}=require("zlib"),c=["gzip","deflate"],common=["GET","HEAD","POST","PUT","DELETE","CONNECT","OPTIONS","TRACE","PATCH"],WumpResponse=class{constructor(t){this.body=Buffer.alloc(0),this.coreRes=t,this.headers=t.headers,this.statusCode=t.statusCode}_addChunk(t){this.body=Buffer.concat([this.body,t])}text(){return this.body.toString()}json(){return JSON.parse(this.body)}},WumpRequest=class{constructor(t={},e={}){const o="string"==typeof t?e:t,r="object"==typeof o;if("string"!=typeof t&&!o.hasOwnProperty("url"))throw new Error("Missing url parameter");return this.o={m:"string"==typeof o?o:r&&o.method?o.method:"GET",url:"string"==typeof t?new URL(t):r&&"string"==typeof o.url?new URL(o.url):t,SDA:r&&"string"==typeof o.sendDataAs?o.sendDataAs:void 0,data:r&&o.data?o.data:r&&o.form?stringify(o.form):void 0,parse:r&&o.parse?o.parse:void 0,follow:!(!r||!o.followRedirects),rHeaders:r&&"object"==typeof o.headers?o.headers:{},streamed:!(!r||!o.streamed),compressed:!(!r||!o.compressed),timeoutTime:r&&"number"==typeof o.timeout?o.timeout:null,coreOptions:r&&"object"==typeof o.coreOptions?o.coreOptions:{}},"object"==typeof o.core&&Object.keys(o.core).forEach(t=>this.option(t,o.core[t])),this}query(t,e){return"object"==typeof t?Object.keys(t).forEach(e=>this.o.url.searchParams.append(e,t[e])):this.o.url.searchParams.append(t,e),this}body(t,e){return this.o.SDA="object"!=typeof t||e||Buffer.isBuffer(t)?e?e.toLowerCase():"buffer":"json",this.o.data="form"===this.SDA?stringify(t):"json"===this.SDA?JSON.stringify(t):t,this}header(t,e){return"object"==typeof t?Object.keys(t).forEach(e=>this.o.rHeaders[e.toLowerCase()]=t[e]):this.o.rHeaders[t.toLowerCase()]=e,this}compress(){return this.compressed=!0,this.o.rHeaders["accept-encoding"]||(this.o.rHeaders["accept-encoding"]=c.join(", ")),this}path(t){return this.o.url.pathname=join(this.o.url.pathname,t),this}stream(){return this.o.streamed=!0,this}option(t,e){return this.o.coreOptions[t]=e,this}timeout(t){return this.o.timeoutTime=t,this}send(){return new Promise((t,e)=>{let o;this.o.data&&(this.o.rHeaders.hasOwnProperty("user-agent")||(this.o.rHeaders["User-Agent"]="wumpfetch/0.0.1 (https://github.com/PassTheWessel/wumpfetch)"),"json"!==this.o.SDA||this.o.rHeaders.hasOwnProperty("content-type")||(this.o.rHeaders["Content-Type"]="application/json"),"form"===this.o.SDA&&(this.o.rHeaders.hasOwnProperty("content-type")||(this.o.rHeaders["Content-Type"]="application/x-www-form-urlencoded"),this.o.rHeaders.hasOwnProperty("content-length")||(this.o.rHeaders["Content-Length"]=Buffer.byteLength(this.o.data))));const r=Object.assign({host:this.o.url.hostname,port:this.o.url.port,path:this.o.url.pathname+this.o.url.search,method:this.o.m,headers:this.o.rHeaders,protocol:this.o.url.protocol},this.o.coreOptions),s=async o=>{let r,s=o;if(this.o.compressed&&("gzip"===o.headers["content-encoding"]?s=o.pipe(createGunzip()):"deflate"===o.headers["content-encoding"]&&(s=o.pipe(createInflate()))),this.o.streamed)t(s);else{if(r=new WumpResponse(o),o.headers.hasOwnProperty("location")&&this.o.follow)return this.o.url=new URL(o.headers.location,this.o.url).toString(),await w(this.o);s.on("error",t=>e(t)),s.on("data",t=>r._addChunk(t)),s.on("end",()=>{this.o.parse&&("json"===this.o.parse?r.body=JSON.parse(r.body):"text"===this.o.parse?r.body=r.body.toString():r.body=r.body),t(r)})}};if("http:"===this.o.url.protocol)o=http.request(r,s);else{if("https:"!==this.o.url.protocol)throw new Error(`Bad URL protocol: ${this.o.url.protocol}`);o=https.request(r,s)}this.o.timeoutTime&&o.setTimeout(this.o.timeoutTime,()=>{o.abort(),this.o.streamed||e(new Error("Timeout reached"))}),o.on("error",t=>e(t)),this.o.data&&o.write("json"===this.o.SDA?JSON.stringify(this.o.data):this.o.data),o.end()})}};function w(t,e){return new WumpRequest(t,e)}module.exports=w,common.forEach(t=>{module.exports[t.toLowerCase()]=((e,o=t)=>new request(e,Object.assign({method:t},o)))});
|
||||
Reference in New Issue
Block a user