Some code base improvements

This commit is contained in:
Wessel Tip
2019-06-07 20:22:59 +02:00
parent f8fa21e384
commit faa6deb8a9
7 changed files with 145 additions and 91 deletions

View File

@@ -1,18 +1,15 @@
const req = require('./model/WumpRequest');
const pkg = require('../package.json');
const common = [ 'GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'CONNECT', 'OPTIONS', 'TRACE', 'PATCH' ];
const metaData = require('../package.json');
module.exports = (url, method) => {
return new req(url, method);
};
module.exports = (url, method) => { return new req(url, method); };
common.forEach((v) => {
module.exports[v.toLowerCase()] = (url, method) => {
if (typeof url === 'string') return new req(url, { method: v, ...method });
else return new req({ method: v, ...url }, method);
}
});
for (const method of common) {
module.exports[method.toLowerCase()] = (url, method) => {
if (typeof url === 'string') return new req(url, { method: method, ...method });
else return new req({ method: method, ...url }, method);
};
}
module.exports.version = pkg.version;
module.exports.userAgent = `${pkg.name}/${pkg.version} (${pkg.repository.url})`;
module.exports.version = metaData.version;
module.exports.userAgent = `${metaData.name}/${metaData.version} (${metaData.repository.url})`;