mirror of
https://github.com/Wessel/wumpfetch.git
synced 2026-06-05 23:25: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:
10
README.md
10
README.md
@@ -1,7 +1,7 @@
|
||||
# Wumpfetch
|
||||
> A lightweight and fast Node.js HTTP client which can be used in various ways
|
||||
|
||||
> [Typings](https://www.github.com/PassTheWessel/wumpfetch-typings) [GitHub](https://www.github.com/PassTheWessel/wumpfetch) **|** [NPM](https://www.npmjs.com/package/wumpfetch)
|
||||
> [Typings](https://github.com/PassTheWessel/wumpfetch-typings) **|** [GitHub](https://github.com/PassTheWessel/wumpfetch) **|** [NPM](https://npmjs.com/package/wumpfetch)
|
||||
|
||||
## Installing
|
||||
```sh
|
||||
@@ -66,10 +66,10 @@ const w = require('wumpfetch');
|
||||
;(async() => {
|
||||
const r = await w('https://my-site.com/postboi', { method: 'GET' });
|
||||
console.log(r.json());
|
||||
})();
|
||||
})();z
|
||||
```
|
||||
|
||||
### Why should i use wumpfetch?
|
||||
Wumpfetch is a lightweight and fast request library comparing to other packages such as request and node-fetch which are both around 1.5-4mb in size
|
||||
<br />
|
||||
### Why use Wumpfetch?
|
||||
Wumpfetch is a lightweight and fast request library comparing to other packages such as request which is 4.46mb!
|
||||
<br>
|
||||
[](https://packagephobia.now.sh/result?p=wumpfetch) (6.2kb concatenated and 4.4kb minified, both in **/dest**)
|
||||
@@ -3,7 +3,6 @@ const wump = require('../lib');
|
||||
|
||||
console.log(`Using wumpfetch v${wump.version} [${wump.userAgent}]\n\n`);
|
||||
|
||||
|
||||
;(async() => {
|
||||
const requests = [
|
||||
await wump({ url: 'https://jsonplaceholder.typicode.com/todos/1', parse: 'json' }).send(),
|
||||
|
||||
@@ -35,9 +35,8 @@ const settings = {
|
||||
// Fetch `url` and save it to `dump/<index>.<fileType>`
|
||||
const get = async(url, index) => {
|
||||
const req = await wump(url).send();
|
||||
if (req.statusCode !== 200) {
|
||||
return console.log(`[${process.name}] Failed on "${url}": ${req.statusCode}`)
|
||||
} else {
|
||||
if (req.statusCode !== 200) return console.log(`[${process.name}] Failed on "${url}": ${req.statusCode}`)
|
||||
else {
|
||||
fs.writeFileSync(`dump/${index}.${settings.fileType}`, req.body);
|
||||
console.log(`[${process.name}] Successfully copied "${url}" to "dump/${index}.${settings.fileType}" in ${Date.now() - start}ms from queue`);
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ gulp.task('build:node', () => {
|
||||
|
||||
gulp.task('concat', () => {
|
||||
return gulp
|
||||
.src('lib/**/*.js')
|
||||
.pipe(concat('wumpfetch.concat.js'))
|
||||
.pipe(gulp.dest('dist'));
|
||||
.src('lib/**/*.js')
|
||||
.pipe(concat('wumpfetch.concat.js'))
|
||||
.pipe(gulp.dest('dist'));
|
||||
});
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,12 +10,12 @@
|
||||
"lib/"
|
||||
],
|
||||
"bugs": {
|
||||
"url": "https://www.github.com/PassTheWessel/wumpfetch/issues"
|
||||
"url": "https://github.com/PassTheWessel/wumpfetch/issues"
|
||||
},
|
||||
"homepage": "https://www.github.com/PassTheWessel/wumpfetch#readme",
|
||||
"homepage": "https://github.com/PassTheWessel/wumpfetch#readme",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://www.github.com/PassTheWessel/wumpfetch"
|
||||
"url": "https://github.com/PassTheWessel/wumpfetch"
|
||||
},
|
||||
"keywords": [
|
||||
"http",
|
||||
@@ -32,8 +32,5 @@
|
||||
"gulp": "^4.0.0",
|
||||
"gulp-concat": "^2.6.1",
|
||||
"gulp-minify": "^3.1.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"wumpfetch": "^0.2.0"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user