mirror of
https://github.com/Wessel/wumpfetch.git
synced 2026-06-06 07:35:42 +02:00
Improvements
Changes: * Fixed gulpfile.js formatting * Fixed package.json and made it lighter * Made index.js and WumpRequest.js lighter * Made example lighter * Fixed grammar issue in WumpRequest.js * Fixed spacing issue in test * Improved README.md and made it lighter
This commit is contained in:
@@ -8,11 +8,8 @@ module.exports = (url, method) => {
|
||||
|
||||
common.forEach((v) => {
|
||||
module.exports[v.toLowerCase()] = (url, method) => {
|
||||
if (typeof url === 'string') {
|
||||
return new request(url, { method: v, ...method });
|
||||
} else {
|
||||
return new request({ method: v, ...url }, method);
|
||||
}
|
||||
if (typeof url === 'string') return new request(url, { method: v, ...method });
|
||||
else return new request({ method: v, ...url }, method);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -15,9 +15,7 @@ module.exports = class WumpRequest {
|
||||
const o = (typeof url === 'string' ? method : url);
|
||||
const obj = (typeof o === 'object');
|
||||
|
||||
if (typeof url !== 'string' && !o.hasOwnProperty('url')) {
|
||||
throw new Error('Missing url parameter');
|
||||
}
|
||||
if (typeof url !== 'string' && !o.hasOwnProperty('url')) throw new Error('Missing URL parameter');
|
||||
|
||||
this.o = {
|
||||
'm': typeof o === 'string' ? o : obj && o.method ? o.method : 'GET',
|
||||
@@ -33,9 +31,7 @@ module.exports = class WumpRequest {
|
||||
'coreOptions': obj && typeof o.coreOptions === 'object' ? o.coreOptions : {}
|
||||
};
|
||||
|
||||
if (typeof o.core === 'object') {
|
||||
Object.keys(o.core).forEach((v) => this.option(v, o.core[v]));
|
||||
}
|
||||
if (typeof o.core === 'object') Object.keys(o.core).forEach((v) => this.option(v, o.core[v]));
|
||||
|
||||
return this;
|
||||
}
|
||||
@@ -94,9 +90,7 @@ module.exports = class WumpRequest {
|
||||
send () {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (this.o.data) {
|
||||
if (!this.o.rHeaders.hasOwnProperty('user-agent')) {
|
||||
this.o.rHeaders['User-Agent'] = w.userAgent || 'Wumpfetch/2.0.1 (https://github.com/PassTheWessel/wumpfetch)';
|
||||
}
|
||||
if (!this.o.rHeaders.hasOwnProperty('user-agent')) this.o.rHeaders['User-Agent'] = w.userAgent || 'Wumpfetch/2.0.1 (https://github.com/PassTheWessel/wumpfetch)';
|
||||
|
||||
if (this.o.SDA === 'json' && !this.o.rHeaders.hasOwnProperty('content-type')) this.o.rHeaders['Content-Type'] = 'application/json';
|
||||
if (this.o.SDA === 'form') {
|
||||
@@ -153,7 +147,6 @@ module.exports = class WumpRequest {
|
||||
else if (this.o.url.protocol === 'https:') req = https.request(options, handler);
|
||||
else throw new Error(`Bad URL protocol: ${this.o.url.protocol}`);
|
||||
|
||||
|
||||
if (this.o.timeoutTime) {
|
||||
req.setTimeout(this.o.timeoutTime, () => {
|
||||
req.abort();
|
||||
@@ -164,14 +157,10 @@ module.exports = class WumpRequest {
|
||||
req.on('error', (e) => reject(e));
|
||||
|
||||
if (this.o.data) {
|
||||
if (this.o.SDA === 'json') {
|
||||
req.write(JSON.stringify(this.o.data));
|
||||
} else {
|
||||
if (typeof this.o.data === 'object') {
|
||||
req.write(JSON.stringify(this.o.data));
|
||||
} else {
|
||||
req.write(this.o.data);
|
||||
}
|
||||
if (this.o.SDA === 'json') req.write(JSON.stringify(this.o.data));
|
||||
else {
|
||||
if (typeof this.o.data === 'object') req.write(JSON.stringify(this.o.data));
|
||||
else req.write(this.o.data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user