mirror of
https://github.com/Wessel/wumpfetch.git
synced 2026-06-05 23:25:42 +02:00
Oopsie
This commit is contained in:
13
lib/index.js
13
lib/index.js
@@ -5,6 +5,15 @@ const MemoryCollection = require('./util/MemoryCollection');
|
|||||||
const profiles = new MemoryCollection();
|
const profiles = new MemoryCollection();
|
||||||
profiles.set('__default__', { headers: { 'User-Agent': `${metaData.name}/${metaData.version} (${metaData.repository.url})` } });
|
profiles.set('__default__', { headers: { 'User-Agent': `${metaData.name}/${metaData.version} (${metaData.repository.url})` } });
|
||||||
|
|
||||||
|
const mergeDefaults = (opts) => {
|
||||||
|
const defaults = profiles.get('__default__');
|
||||||
|
Object.keys(defaults).forEach((key) => {
|
||||||
|
if (!opts[key]) opts[key] = defaults[key];
|
||||||
|
});
|
||||||
|
|
||||||
|
return opts;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a request with a specific method
|
* Create a request with a specific method
|
||||||
*
|
*
|
||||||
@@ -14,8 +23,8 @@ profiles.set('__default__', { headers: { 'User-Agent': `${metaData.name}/${metaD
|
|||||||
*/
|
*/
|
||||||
module.exports = (url, method = profiles.get('__default__')) => {
|
module.exports = (url, method = profiles.get('__default__')) => {
|
||||||
if (typeof url === 'object' && typeof method === 'string') url.method = method;
|
if (typeof url === 'object' && typeof method === 'string') url.method = method;
|
||||||
if (typeof url === 'object' && !url.overwriteDefaults) Object.assign(url, profiles.get('__default__'));
|
if (typeof url === 'object' && !url.overwriteDefaults) url = mergeDefaults(url);
|
||||||
if (typeof method === 'object' && !method.overwriteDefaults) Object.assign(method, profiles.get('__default__'));
|
if (typeof method === 'object' && !method.overwriteDefaults) method = mergeDefaults(method);
|
||||||
|
|
||||||
return new req(url, method);
|
return new req(url, method);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "wumpfetch",
|
"name": "wumpfetch",
|
||||||
"version": "0.3.0",
|
"version": "0.3.1",
|
||||||
"description": "🚀🔗 A modern, lightweight, fast and easy to use Node.js HTTP client",
|
"description": "🚀🔗 A modern, lightweight, fast and easy to use Node.js HTTP client",
|
||||||
"author": "Wessel \"wesselgame\" T <discord@go2it.eu>",
|
"author": "Wessel \"wesselgame\" T <discord@go2it.eu>",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|||||||
Reference in New Issue
Block a user