Merge pull request #159 from jamesgeorge007/feat/minor-refactor
chore: minor code refactor
This commit is contained in:
@@ -581,7 +581,7 @@
|
|||||||
key,
|
key,
|
||||||
value
|
value
|
||||||
}) => `${key}: ${value}`).join(',\n')
|
}) => `${key}: ${value}`).join(',\n')
|
||||||
return result == '' ? '' : `${result}`
|
return result === '' ? '' : `${result}`
|
||||||
},
|
},
|
||||||
queryString() {
|
queryString() {
|
||||||
const result = this.params
|
const result = this.params
|
||||||
@@ -613,7 +613,7 @@
|
|||||||
requestString.push('xhr.setRequestHeader(' + element.key + ', ' + element.value + ')');
|
requestString.push('xhr.setRequestHeader(' + element.key + ', ' + element.value + ')');
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if (this.method === 'POST' || this.method === 'PUT') {
|
if (['POST', 'PUT'].includes(this.method)) {
|
||||||
const requestBody = this.rawInput ? this.rawParams : this.rawRequestBody;
|
const requestBody = this.rawInput ? this.rawParams : this.rawRequestBody;
|
||||||
requestString.push("xhr.setRequestHeader('Content-Length', " + requestBody.length + ")")
|
requestString.push("xhr.setRequestHeader('Content-Length', " + requestBody.length + ")")
|
||||||
requestString.push("xhr.setRequestHeader('Content-Type', `" + this.contentType + "; charset=utf-8`)")
|
requestString.push("xhr.setRequestHeader('Content-Type', `" + this.contentType + "; charset=utf-8`)")
|
||||||
@@ -633,7 +633,7 @@
|
|||||||
} else if (this.auth === 'Bearer Token') {
|
} else if (this.auth === 'Bearer Token') {
|
||||||
headers.push(' "Authorization": "Bearer Token ' + this.bearerToken + ',\n')
|
headers.push(' "Authorization": "Bearer Token ' + this.bearerToken + ',\n')
|
||||||
}
|
}
|
||||||
if (this.method === 'POST' || this.method === 'PUT') {
|
if (['POST', 'PUT'].includes(this.method)) {
|
||||||
const requestBody = this.rawInput ? this.rawParams : this.rawRequestBody;
|
const requestBody = this.rawInput ? this.rawParams : this.rawRequestBody;
|
||||||
requestString.push(' body: ' + requestBody + ',\n')
|
requestString.push(' body: ' + requestBody + ',\n')
|
||||||
headers.push(' "Content-Length": ' + requestBody.length + ',\n')
|
headers.push(' "Content-Length": ' + requestBody.length + ',\n')
|
||||||
@@ -673,7 +673,7 @@
|
|||||||
requestString.push(" -H '" + element.key + ": " + element.value + "' \\\n");
|
requestString.push(" -H '" + element.key + ": " + element.value + "' \\\n");
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if (this.method === 'POST' || this.method === 'PUT') {
|
if (['POST', 'PUT'].includes(this.method)) {
|
||||||
const requestBody = this.rawInput ? this.rawParams : this.rawRequestBody;
|
const requestBody = this.rawInput ? this.rawParams : this.rawRequestBody;
|
||||||
requestString.push(" -H 'Content-Length: " + requestBody.length + "' \\\n")
|
requestString.push(" -H 'Content-Length: " + requestBody.length + "' \\\n")
|
||||||
requestString.push(" -H 'Content-Type: " + this.contentType + "; charset=utf-8' \\\n")
|
requestString.push(" -H 'Content-Type: " + this.contentType + "; charset=utf-8' \\\n")
|
||||||
@@ -723,7 +723,7 @@
|
|||||||
|
|
||||||
let headers = {};
|
let headers = {};
|
||||||
|
|
||||||
// If the request has a request body, we want to ensure Content-Length and
|
// If the request has a body, we want to ensure Content-Length and
|
||||||
// Content-Type are sent.
|
// Content-Type are sent.
|
||||||
let requestBody;
|
let requestBody;
|
||||||
if (this.hasRequestBody) {
|
if (this.hasRequestBody) {
|
||||||
@@ -966,7 +966,7 @@
|
|||||||
setRouteQueries(queries) {
|
setRouteQueries(queries) {
|
||||||
if (typeof (queries) !== 'object') throw new Error('Route query parameters must be a Object')
|
if (typeof (queries) !== 'object') throw new Error('Route query parameters must be a Object')
|
||||||
for (const key in queries) {
|
for (const key in queries) {
|
||||||
if (key === 'headers' || key === 'params' || key === 'bodyParams') this[key] = JSON.parse(queries[key])
|
if (['headers', 'params', 'bodyParams'].includes(key)) this[key] = JSON.parse(queries[key])
|
||||||
if (key === 'rawParams') {
|
if (key === 'rawParams') {
|
||||||
this.rawInput = true
|
this.rawInput = true
|
||||||
this.rawParams = queries['rawParams']
|
this.rawParams = queries['rawParams']
|
||||||
@@ -992,7 +992,7 @@
|
|||||||
try {
|
try {
|
||||||
let parsedCurl = parseCurlCommand(text);
|
let parsedCurl = parseCurlCommand(text);
|
||||||
this.url = parsedCurl.url.replace(/"/g,"").replace(/'/g,"");
|
this.url = parsedCurl.url.replace(/"/g,"").replace(/'/g,"");
|
||||||
this.url = this.url[this.url.length -1] == '/' ? this.url.slice(0, -1): this.url;
|
this.url = this.url.slice(-1).pop() == '/' ? this.url.slice(0, -1): this.url;
|
||||||
this.path = "";
|
this.path = "";
|
||||||
this.headers = [];
|
this.headers = [];
|
||||||
for (const key of Object.keys(parsedCurl.headers)) {
|
for (const key of Object.keys(parsedCurl.headers)) {
|
||||||
|
|||||||
@@ -48,16 +48,15 @@ export const state = () => ({
|
|||||||
export const mutations = {
|
export const mutations = {
|
||||||
|
|
||||||
applySetting (state, setting) {
|
applySetting (state, setting) {
|
||||||
if(setting == null || !(setting instanceof Array) || setting.length !== 2)
|
if (setting == null || !(setting instanceof Array) || setting.length !== 2)
|
||||||
throw new Error("You must provide a setting (array in the form [key, value])");
|
throw new Error("You must provide a setting (array in the form [key, value])");
|
||||||
|
|
||||||
let key = setting[0];
|
const [key, value] = setting;
|
||||||
let value = setting[1];
|
|
||||||
// Do not just remove this check.
|
// Do not just remove this check.
|
||||||
// Add your settings key to the SETTINGS_KEYS array at the
|
// Add your settings key to the SETTINGS_KEYS array at the
|
||||||
// top of the file.
|
// top of the file.
|
||||||
// This is to ensure that application settings remain documented.
|
// This is to ensure that application settings remain documented.
|
||||||
if(!SETTINGS_KEYS.includes(key)) throw new Error("The settings structure does not include the key " + key);
|
if (!SETTINGS_KEYS.includes(key)) throw new Error("The settings structure does not include the key " + key);
|
||||||
|
|
||||||
state.settings[key] = value;
|
state.settings[key] = value;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user