This commit is contained in:
Wessel Tip
2019-10-26 14:45:22 +02:00
parent b76028b4c2
commit f165dade06
2 changed files with 12 additions and 3 deletions

View File

@@ -5,6 +5,15 @@ const MemoryCollection = require('./util/MemoryCollection');
const profiles = new MemoryCollection();
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
*
@@ -14,8 +23,8 @@ profiles.set('__default__', { headers: { 'User-Agent': `${metaData.name}/${metaD
*/
module.exports = (url, method = profiles.get('__default__')) => {
if (typeof url === 'object' && typeof method === 'string') url.method = method;
if (typeof url === 'object' && !url.overwriteDefaults) Object.assign(url, profiles.get('__default__'));
if (typeof method === 'object' && !method.overwriteDefaults) Object.assign(method, profiles.get('__default__'));
if (typeof url === 'object' && !url.overwriteDefaults) url = mergeDefaults(url);
if (typeof method === 'object' && !method.overwriteDefaults) method = mergeDefaults(method);
return new req(url, method);
};

View File

@@ -1,6 +1,6 @@
{
"name": "wumpfetch",
"version": "0.3.0",
"version": "0.3.1",
"description": "🚀🔗 A modern, lightweight, fast and easy to use Node.js HTTP client",
"author": "Wessel \"wesselgame\" T <discord@go2it.eu>",
"license": "MIT",