mirror of
https://github.com/Wessel/wumpfetch.git
synced 2026-07-21 23:57:11 +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
|
# Wumpfetch
|
||||||
> A lightweight and fast Node.js HTTP client which can be used in various ways
|
> 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
|
## Installing
|
||||||
```sh
|
```sh
|
||||||
@@ -66,10 +66,10 @@ const w = require('wumpfetch');
|
|||||||
;(async() => {
|
;(async() => {
|
||||||
const r = await w('https://my-site.com/postboi', { method: 'GET' });
|
const r = await w('https://my-site.com/postboi', { method: 'GET' });
|
||||||
console.log(r.json());
|
console.log(r.json());
|
||||||
})();
|
})();z
|
||||||
```
|
```
|
||||||
|
|
||||||
### Why should i use wumpfetch?
|
### Why 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
|
Wumpfetch is a lightweight and fast request library comparing to other packages such as request which is 4.46mb!
|
||||||
<br />
|
<br>
|
||||||
[](https://packagephobia.now.sh/result?p=wumpfetch) (6.2kb concatenated and 4.4kb minified, both in **/dest**)
|
[](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`);
|
console.log(`Using wumpfetch v${wump.version} [${wump.userAgent}]\n\n`);
|
||||||
|
|
||||||
|
|
||||||
;(async() => {
|
;(async() => {
|
||||||
const requests = [
|
const requests = [
|
||||||
await wump({ url: 'https://jsonplaceholder.typicode.com/todos/1', parse: 'json' }).send(),
|
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>`
|
// Fetch `url` and save it to `dump/<index>.<fileType>`
|
||||||
const get = async(url, index) => {
|
const get = async(url, index) => {
|
||||||
const req = await wump(url).send();
|
const req = await wump(url).send();
|
||||||
if (req.statusCode !== 200) {
|
if (req.statusCode !== 200) return console.log(`[${process.name}] Failed on "${url}": ${req.statusCode}`)
|
||||||
return console.log(`[${process.name}] Failed on "${url}": ${req.statusCode}`)
|
else {
|
||||||
} else {
|
|
||||||
fs.writeFileSync(`dump/${index}.${settings.fileType}`, req.body);
|
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`);
|
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', () => {
|
gulp.task('concat', () => {
|
||||||
return gulp
|
return gulp
|
||||||
.src('lib/**/*.js')
|
.src('lib/**/*.js')
|
||||||
.pipe(concat('wumpfetch.concat.js'))
|
.pipe(concat('wumpfetch.concat.js'))
|
||||||
.pipe(gulp.dest('dist'));
|
.pipe(gulp.dest('dist'));
|
||||||
});
|
});
|
||||||
@@ -8,11 +8,8 @@ module.exports = (url, method) => {
|
|||||||
|
|
||||||
common.forEach((v) => {
|
common.forEach((v) => {
|
||||||
module.exports[v.toLowerCase()] = (url, method) => {
|
module.exports[v.toLowerCase()] = (url, method) => {
|
||||||
if (typeof url === 'string') {
|
if (typeof url === 'string') return new request(url, { method: v, ...method });
|
||||||
return new request(url, { method: v, ...method });
|
else return new request({ method: v, ...url }, 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 o = (typeof url === 'string' ? method : url);
|
||||||
const obj = (typeof o === 'object');
|
const obj = (typeof o === 'object');
|
||||||
|
|
||||||
if (typeof url !== 'string' && !o.hasOwnProperty('url')) {
|
if (typeof url !== 'string' && !o.hasOwnProperty('url')) throw new Error('Missing URL parameter');
|
||||||
throw new Error('Missing url parameter');
|
|
||||||
}
|
|
||||||
|
|
||||||
this.o = {
|
this.o = {
|
||||||
'm': typeof o === 'string' ? o : obj && o.method ? o.method : 'GET',
|
'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 : {}
|
'coreOptions': obj && typeof o.coreOptions === 'object' ? o.coreOptions : {}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (typeof o.core === 'object') {
|
if (typeof o.core === 'object') Object.keys(o.core).forEach((v) => this.option(v, o.core[v]));
|
||||||
Object.keys(o.core).forEach((v) => this.option(v, o.core[v]));
|
|
||||||
}
|
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -94,9 +90,7 @@ module.exports = class WumpRequest {
|
|||||||
send () {
|
send () {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (this.o.data) {
|
if (this.o.data) {
|
||||||
if (!this.o.rHeaders.hasOwnProperty('user-agent')) {
|
if (!this.o.rHeaders.hasOwnProperty('user-agent')) this.o.rHeaders['User-Agent'] = w.userAgent || 'Wumpfetch/2.0.1 (https://github.com/PassTheWessel/wumpfetch)';
|
||||||
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 === 'json' && !this.o.rHeaders.hasOwnProperty('content-type')) this.o.rHeaders['Content-Type'] = 'application/json';
|
||||||
if (this.o.SDA === 'form') {
|
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 if (this.o.url.protocol === 'https:') req = https.request(options, handler);
|
||||||
else throw new Error(`Bad URL protocol: ${this.o.url.protocol}`);
|
else throw new Error(`Bad URL protocol: ${this.o.url.protocol}`);
|
||||||
|
|
||||||
|
|
||||||
if (this.o.timeoutTime) {
|
if (this.o.timeoutTime) {
|
||||||
req.setTimeout(this.o.timeoutTime, () => {
|
req.setTimeout(this.o.timeoutTime, () => {
|
||||||
req.abort();
|
req.abort();
|
||||||
@@ -164,14 +157,10 @@ module.exports = class WumpRequest {
|
|||||||
req.on('error', (e) => reject(e));
|
req.on('error', (e) => reject(e));
|
||||||
|
|
||||||
if (this.o.data) {
|
if (this.o.data) {
|
||||||
if (this.o.SDA === 'json') {
|
if (this.o.SDA === 'json') req.write(JSON.stringify(this.o.data));
|
||||||
req.write(JSON.stringify(this.o.data));
|
else {
|
||||||
} else {
|
if (typeof this.o.data === 'object') req.write(JSON.stringify(this.o.data));
|
||||||
if (typeof this.o.data === 'object') {
|
else req.write(this.o.data);
|
||||||
req.write(JSON.stringify(this.o.data));
|
|
||||||
} else {
|
|
||||||
req.write(this.o.data);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,12 +10,12 @@
|
|||||||
"lib/"
|
"lib/"
|
||||||
],
|
],
|
||||||
"bugs": {
|
"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": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://www.github.com/PassTheWessel/wumpfetch"
|
"url": "https://github.com/PassTheWessel/wumpfetch"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"http",
|
"http",
|
||||||
@@ -32,8 +32,5 @@
|
|||||||
"gulp": "^4.0.0",
|
"gulp": "^4.0.0",
|
||||||
"gulp-concat": "^2.6.1",
|
"gulp-concat": "^2.6.1",
|
||||||
"gulp-minify": "^3.1.0"
|
"gulp-minify": "^3.1.0"
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"wumpfetch": "^0.2.0"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user