From f42e0329da7112920126401abdd89ccb57ab8af3 Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Mon, 23 Sep 2019 23:42:07 +0530 Subject: [PATCH 01/11] use array destructuring approach --- store/postwoman.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/store/postwoman.js b/store/postwoman.js index dcd07b9e1..83ee2714b 100644 --- a/store/postwoman.js +++ b/store/postwoman.js @@ -51,8 +51,7 @@ export const mutations = { if(setting == null || !(setting instanceof Array) || setting.length !== 2) throw new Error("You must provide a setting (array in the form [key, value])"); - let key = setting[0]; - let value = setting[1]; + const [key, value] = setting; // Do not just remove this check. // Add your settings key to the SETTINGS_KEYS array at the // top of the file. From 20a8296cd5ebd5bcf48c55910856bcff36394a6c Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Mon, 23 Sep 2019 23:45:18 +0530 Subject: [PATCH 02/11] avoid redundant checks --- pages/index.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/index.vue b/pages/index.vue index 0aee73ea4..6a32925be 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -965,7 +965,7 @@ setRouteQueries(queries) { if (typeof (queries) !== 'object') throw new Error('Route query parameters must be a Object') 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') { this.rawInput = true this.rawParams = queries['rawParams'] From 74d2119f3128bbcdf6c3f72dd984c4ad9ad6e10e Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Mon, 23 Sep 2019 23:50:05 +0530 Subject: [PATCH 03/11] use a concise approach to fetch the last element --- pages/index.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/index.vue b/pages/index.vue index 6a32925be..fde4e0de3 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -991,7 +991,7 @@ try { let parsedCurl = parseCurlCommand(text); 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.headers = []; for (const key of Object.keys(parsedCurl.headers)) { From 0c873a1c027fefb8cbb340510583fd24cf324822 Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Mon, 23 Sep 2019 23:54:24 +0530 Subject: [PATCH 04/11] remove redundant wording --- pages/index.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/index.vue b/pages/index.vue index fde4e0de3..f0b230f2b 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -722,7 +722,7 @@ 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. let requestBody; if (this.hasRequestBody) { From 8857821716094c6fca6a21525b6d20ded4d91257 Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Mon, 23 Sep 2019 23:58:04 +0530 Subject: [PATCH 05/11] minor refactor --- pages/index.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/index.vue b/pages/index.vue index f0b230f2b..5b6d084c9 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -612,7 +612,7 @@ 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; requestString.push("xhr.setRequestHeader('Content-Length', " + requestBody.length + ")") requestString.push("xhr.setRequestHeader('Content-Type', `" + this.contentType + "; charset=utf-8`)") From 13be809cfe84d7e5d5dbdf328c36422efd72f17f Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Mon, 23 Sep 2019 23:58:52 +0530 Subject: [PATCH 06/11] minor refactor --- pages/index.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/index.vue b/pages/index.vue index 5b6d084c9..838e00afc 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -632,7 +632,7 @@ } else if (this.auth === 'Bearer Token') { 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; requestString.push(' body: ' + requestBody + ',\n') headers.push(' "Content-Length": ' + requestBody.length + ',\n') From 901162c8b645a2875fca49d2834bf0bf309b820a Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Mon, 23 Sep 2019 23:59:24 +0530 Subject: [PATCH 07/11] minor refactor --- pages/index.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/index.vue b/pages/index.vue index 838e00afc..e25fb267d 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -672,7 +672,7 @@ 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; requestString.push(" -H 'Content-Length: " + requestBody.length + "' \\\n") requestString.push(" -H 'Content-Type: " + this.contentType + "; charset=utf-8' \\\n") From 53f3af6944e7d83ce4995cb6b70c300e2e09c590 Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Tue, 24 Sep 2019 00:00:44 +0530 Subject: [PATCH 08/11] Minor stylistic update --- pages/index.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/index.vue b/pages/index.vue index e25fb267d..2b2c95f52 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -580,7 +580,7 @@ key, value }) => `${key}: ${value}`).join(',\n') - return result == '' ? '' : `${result}` + return result === '' ? '' : `${result}` }, queryString() { const result = this.params From e6387c694e980856e190a595ba0e9998c78014ea Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Tue, 24 Sep 2019 00:01:50 +0530 Subject: [PATCH 09/11] Use includes() to check for existence --- pages/index.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/index.vue b/pages/index.vue index 2b2c95f52..741da63b7 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -517,7 +517,7 @@ value }) => `${key}=${value}`).join('&') queryString = queryString === '' ? '' : `?${queryString}` - if(path.indexOf('?') !== -1) { + if(path.includes('?')) { path = path.slice(0, path.indexOf('?')) + queryString; } else { path = path + queryString From 948158715141333751857f21c31c4ba0c20688fb Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Tue, 24 Sep 2019 00:05:12 +0530 Subject: [PATCH 10/11] Minor stylistic update --- store/postwoman.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/store/postwoman.js b/store/postwoman.js index 83ee2714b..034333253 100644 --- a/store/postwoman.js +++ b/store/postwoman.js @@ -48,7 +48,7 @@ export const state = () => ({ export const mutations = { 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])"); const [key, value] = setting; @@ -56,7 +56,7 @@ export const mutations = { // Add your settings key to the SETTINGS_KEYS array at the // top of the file. // 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; } From 51c500fd837c806d8341e0b5053a7e34ea285984 Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Tue, 24 Sep 2019 00:12:21 +0530 Subject: [PATCH 11/11] fix: typo --- pages/index.vue | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pages/index.vue b/pages/index.vue index 741da63b7..f6270485a 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -612,7 +612,7 @@ requestString.push('xhr.setRequestHeader(' + element.key + ', ' + element.value + ')'); }) } - if (['POST', 'PUT'].includes(this.method)]) { + if (['POST', 'PUT'].includes(this.method)) { const requestBody = this.rawInput ? this.rawParams : this.rawRequestBody; requestString.push("xhr.setRequestHeader('Content-Length', " + requestBody.length + ")") requestString.push("xhr.setRequestHeader('Content-Type', `" + this.contentType + "; charset=utf-8`)") @@ -632,7 +632,7 @@ } else if (this.auth === 'Bearer Token') { headers.push(' "Authorization": "Bearer Token ' + this.bearerToken + ',\n') } - if (['POST', 'PUT'].includes(this.method)]) { + if (['POST', 'PUT'].includes(this.method)) { const requestBody = this.rawInput ? this.rawParams : this.rawRequestBody; requestString.push(' body: ' + requestBody + ',\n') headers.push(' "Content-Length": ' + requestBody.length + ',\n') @@ -672,7 +672,7 @@ requestString.push(" -H '" + element.key + ": " + element.value + "' \\\n"); }) } - if (['POST', 'PUT'].includes(this.method)]) { + if (['POST', 'PUT'].includes(this.method)) { const requestBody = this.rawInput ? this.rawParams : this.rawRequestBody; requestString.push(" -H 'Content-Length: " + requestBody.length + "' \\\n") requestString.push(" -H 'Content-Type: " + this.contentType + "; charset=utf-8' \\\n")