Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia
TypeScript apiapi-clientapi-restapi-testingdeveloper-toolsgraphqlhttphttp-clientpwarestrest-apispatestingtesting-toolstoolsvuevuejswebsocket
Transpiled ES5 code to ES6/ES7
Liyas Thomas0644a8c9fb93
diff --git a/components/collections/importExportCollections.vue b/components/collections/importExportCollections.vueindex a7cada355..6eba82a60 100644--- a/components/collections/importExportCollections.vue+++ b/components/collections/importExportCollections.vue@@ -107,7 +107,7 @@ export default {},replaceWithJSON() {let reader = new FileReader()- reader.onload = event => {+ reader.onload = (event) => {let content = event.target.resultlet collections = JSON.parse(content)if (collections[0]) {@@ -127,7 +127,7 @@ export default {},importFromJSON() {let reader = new FileReader()- reader.onload = event => {+ reader.onload = (event) => {let content = event.target.resultlet collections = JSON.parse(content)if (collections[0]) {@@ -177,7 +177,7 @@ export default {icon: "error",})},- parsePostmanCollection(collection, folders = true) {+ parsePostmanCollection({ item, info, name }, folders = true) {let postwomanCollection = folders? [{@@ -190,13 +190,13 @@ export default {name: "",requests: [],}- for (let collectionItem of collection.item) {+ for (let collectionItem of item) {if (collectionItem.request) {if (postwomanCollection[0]) {- postwomanCollection[0].name = collection.info ? collection.info.name : ""+ postwomanCollection[0].name = info ? info.name : ""postwomanCollection[0].requests.push(this.parsePostmanRequest(collectionItem))} else {- postwomanCollection.name = collection.name ? collection.name : ""+ postwomanCollection.name = name ? name : ""postwomanCollection.requests.push(this.parsePostmanRequest(collectionItem))}} else if (collectionItem.item) {@@ -207,7 +207,7 @@ export default {}return postwomanCollection},- parsePostmanRequest(requestObject) {+ parsePostmanRequest({ name, request }) {let pwRequest = {url: "",path: "",@@ -227,16 +227,14 @@ export default {name: "",}- pwRequest.name = requestObject.name- let requestObjectUrl = requestObject.request.url.raw.match(- /^(.+:\/\/[^\/]+|{[^\/]+})(\/[^\?]+|).*$/- )+ pwRequest.name = name+ let requestObjectUrl = request.url.raw.match(/^(.+:\/\/[^\/]+|{[^\/]+})(\/[^\?]+|).*$/)if (requestObjectUrl) {pwRequest.url = requestObjectUrl[1]pwRequest.path = requestObjectUrl[2] ? requestObjectUrl[2] : ""}- pwRequest.method = requestObject.request.method- let itemAuth = requestObject.request.auth ? requestObject.request.auth : ""+ pwRequest.method = request.method+ let itemAuth = request.auth ? request.auth : ""let authType = itemAuth ? itemAuth.type : ""if (authType === "basic") {pwRequest.auth = "Basic Auth"@@ -254,7 +252,7 @@ export default {pwRequest.auth = "Bearer Token"pwRequest.bearerToken = itemAuth.bearer[0].value}- let requestObjectHeaders = requestObject.request.header+ let requestObjectHeaders = request.headerif (requestObjectHeaders) {pwRequest.headers = requestObjectHeadersfor (let header of pwRequest.headers) {@@ -262,23 +260,23 @@ export default {delete header.type}}- let requestObjectParams = requestObject.request.url.query+ let requestObjectParams = request.url.queryif (requestObjectParams) {pwRequest.params = requestObjectParamsfor (let param of pwRequest.params) {delete param.disabled}}- if (requestObject.request.body) {- if (requestObject.request.body.mode === "urlencoded") {- let params = requestObject.request.body.urlencoded+ if (request.body) {+ if (request.body.mode === "urlencoded") {+ let params = request.body.urlencodedpwRequest.bodyParams = params ? params : []for (let param of pwRequest.bodyParams) {delete param.type}- } else if (requestObject.request.body.mode === "raw") {+ } else if (request.body.mode === "raw") {pwRequest.rawInput = true- pwRequest.rawParams = requestObject.request.body.raw+ pwRequest.rawParams = request.body.raw}}return pwRequestdiff --git a/components/firebase/login.vue b/components/firebase/login.vueindex c7e4dafd5..015062ec3 100644--- a/components/firebase/login.vue+++ b/components/firebase/login.vue@@ -77,34 +77,33 @@ export default {}self.showLoginSuccess()})- .catch(err => {+ .catch((err) => {// An error happened.if (err.code === "auth/account-exists-with-different-credential") {// Step 2.// User's email already exists.// The pending Google credential.- var pendingCred = err.credential+ const pendingCred = err.credential// The provider account's email address.- var email = err.email+ const email = err.email// Get sign-in methods for this email.firebase.auth().fetchSignInMethodsForEmail(email)- .then(function(methods) {+ .then((methods) => {// Step 3.// If the user has several sign-in methods,// the first method in the list will be the "recommended" method to use.if (methods[0] === "password") {// Asks the user their password.// In real scenario, you should handle this asynchronously.- var password = promptUserForPassword() // TODO: implement promptUserForPassword.+ const password = promptUserForPassword() // TODO: implement promptUserForPassword.auth.signInWithEmailAndPassword(email, password)- .then(function(user) {- // Step 4a.- return user.linkWithCredential(pendingCred)- })- .then(function() {+ .then((+ user // Step 4a.+ ) => user.linkWithCredential(pendingCred))+ .then(() => {// Google account successfully linked to the existing Firebase user.self.showLoginSuccess()})@@ -121,7 +120,7 @@ export default {// All the other cases are external providers.// Construct provider object for that provider.// TODO: implement getProviderForProviderId.- var provider = new firebase.auth.GithubAuthProvider()+ const provider = new firebase.auth.GithubAuthProvider()// At this point, you should let the user know that they already has an account// but with a different provider, and let them validate the fact they want to// sign in with this provider.@@ -131,19 +130,17 @@ export default {firebase.auth().signInWithPopup(provider)- .then(function(result) {+ .then(({ user }) => {// Remember that the user may have signed in with an account that has a different email// address than the first one. This can happen as Firebase doesn't control the provider's// sign in flow and the user is free to login using whichever account they own.// Step 4b.// Link to Google credential.// As we have access to the pending credential, we can directly call the link method.- result.user- .linkAndRetrieveDataWithCredential(pendingCred)- .then(function(usercred) {- // Google account successfully linked to the existing Firebase user.- self.showLoginSuccess()- })+ user.linkAndRetrieveDataWithCredential(pendingCred).then((usercred) => {+ // Google account successfully linked to the existing Firebase user.+ self.showLoginSuccess()+ })})toastObject.remove()@@ -180,35 +177,34 @@ export default {}self.showLoginSuccess()})- .catch(err => {+ .catch((err) => {// An error happened.if (err.code === "auth/account-exists-with-different-credential") {// Step 2.// User's email already exists.// The pending Google credential.- var pendingCred = err.credential+ const pendingCred = err.credential// The provider account's email address.- var email = err.email+ const email = err.email// Get sign-in methods for this email.firebase.auth().fetchSignInMethodsForEmail(email)- .then(function(methods) {+ .then((methods) => {// Step 3.// If the user has several sign-in methods,// the first method in the list will be the "recommended" method to use.if (methods[0] === "password") {// Asks the user their password.// In real scenario, you should handle this asynchronously.- var password = promptUserForPassword() // TODO: implement promptUserForPassword.+ const password = promptUserForPassword() // TODO: implement promptUserForPassword.firebase.auth().signInWithEmailAndPassword(email, password)- .then(function(user) {- // Step 4a.- return user.linkWithCredential(pendingCred)- })- .then(function() {+ .then((+ user // Step 4a.+ ) => user.linkWithCredential(pendingCred))+ .then(() => {// Google account successfully linked to the existing Firebase user.self.showLoginSuccess()})@@ -225,7 +221,7 @@ export default {// All the other cases are external providers.// Construct provider object for that provider.// TODO: implement getProviderForProviderId.- var provider = new firebase.auth.GoogleAuthProvider()+ const provider = new firebase.auth.GoogleAuthProvider()// At this point, you should let the user know that they already has an account// but with a different provider, and let them validate the fact they want to// sign in with this provider.@@ -235,18 +231,16 @@ export default {firebase.auth().signInWithPopup(provider)- .then(function(result) {+ .then(({ user }) => {// Remember that the user may have signed in with an account that has a different email// address than the first one. This can happen as Firebase doesn't control the provider's// sign in flow and the user is free to login using whichever account they own.// Step 4b.// Link to Google credential.// As we have access to the pending credential, we can directly call the link method.- result.user- .linkAndRetrieveDataWithCredential(pendingCred)- .then(function(usercred) {- self.showLoginSuccess()- })+ user.linkAndRetrieveDataWithCredential(pendingCred).then((usercred) => {+ self.showLoginSuccess()+ })})toastObject.remove()diff --git a/components/graphql/field.vue b/components/graphql/field.vueindex 05c7708f5..5200a1d3f 100644--- a/components/graphql/field.vue+++ b/components/graphql/field.vue@@ -64,14 +64,11 @@ export default {computed: {fieldString() {- const args = (this.gqlField.args || []).reduce((acc, arg, index) => {- return (- acc +- `${arg.name}: ${arg.type.toString()}${- index !== this.gqlField.args.length - 1 ? ", " : ""- }`- )- }, "")+ const args = (this.gqlField.args || []).reduce(+ (acc, { name, type }, index) =>+ acc + `${name}: ${type.toString()}${index !== this.gqlField.args.length - 1 ? ", " : ""}`,+ ""+ )const argsString = args.length > 0 ? `(${args})` : ""return `${this.gqlField.name}${argsString}: ${this.gqlField.type.toString()}`},diff --git a/components/layout/footer.vue b/components/layout/footer.vueindex 6cf05d6c3..344923d1e 100644--- a/components/layout/footer.vue+++ b/components/layout/footer.vue@@ -91,7 +91,7 @@ export default {computed: {availableLocales() {- return this.$i18n.locales.filter(i => i.code !== this.$i18n.locale)+ return this.$i18n.locales.filter(({ code }) => code !== this.$i18n.locale)},},}diff --git a/components/layout/sidenav.vue b/components/layout/sidenav.vueindex 258cda5ab..05acb6960 100644--- a/components/layout/sidenav.vue+++ b/components/layout/sidenav.vue@@ -276,20 +276,20 @@ export default {},mounted() {- window.addEventListener("scroll", event => {+ window.addEventListener("scroll", (event) => {let mainNavLinks = document.querySelectorAll("nav ul li a")let fromTop = window.scrollY- mainNavLinks.forEach(link => {- let section = document.querySelector(link.hash)+ mainNavLinks.forEach(({ hash, classList }) => {+ let section = document.querySelector(hash)if (section &§ion.offsetTop <= fromTop &§ion.offsetTop + section.offsetHeight > fromTop) {- link.classList.add("current")+ classList.add("current")} else {- link.classList.remove("current")+ classList.remove("current")}})})diff --git a/components/realtime/sse.vue b/components/realtime/sse.vueindex 8fc678303..a7294d84b 100644--- a/components/realtime/sse.vue+++ b/components/realtime/sse.vue@@ -110,9 +110,9 @@ export default {icon: "sync_disabled",})}- this.sse.onmessage = (event) => {+ this.sse.onmessage = ({ data }) => {this.events.log.push({- payload: event.data,+ payload: data,source: "server",ts: new Date().toLocaleTimeString(),})diff --git a/components/realtime/websocket.vue b/components/realtime/websocket.vueindex a15d259fb..c53dd1aaa 100644--- a/components/realtime/websocket.vue+++ b/components/realtime/websocket.vue@@ -136,9 +136,9 @@ export default {icon: "sync_disabled",})}- this.socket.onmessage = (event) => {+ this.socket.onmessage = ({ data }) => {this.communication.log.push({- payload: event.data,+ payload: data,source: "server",ts: new Date().toLocaleTimeString(),})@@ -181,7 +181,7 @@ export default {this.communication.input = ""},walkHistory(direction) {- const clientMessages = this.communication.log.filter((msg) => msg.source === "client")+ const clientMessages = this.communication.log.filter(({ source }) => source === "client")const length = clientMessages.lengthswitch (direction) {case "up":diff --git a/functions/api.js b/functions/api.jsindex 5e95b8332..1b5cc68ca 100644--- a/functions/api.js+++ b/functions/api.js@@ -1,9 +1,9 @@// Docs on event and context https://www.netlify.com/docs/functions/#the-handler-method-exports.handler = async (event, context) => {- switch (event.httpMethod) {+export async function handler({ httpMethod, queryStringParameters }, context) {+ switch (httpMethod) {case "GET":try {- const name = event.queryStringParameters.name || "World"+ const name = queryStringParameters.name || "World"return {statusCode: 200,headers: {diff --git a/functions/fb.js b/functions/fb.jsindex 0b13ae306..d4de235b7 100644--- a/functions/fb.js+++ b/functions/fb.js@@ -105,7 +105,7 @@ export const fb = {author: fb.currentUser.uid,author_name: fb.currentUser.displayName,author_image: fb.currentUser.photoURL,- collection: collection,+ collection,}usersCollection.doc(fb.currentUser.uid)@@ -120,7 +120,7 @@ export const fb = {author: fb.currentUser.uid,author_name: fb.currentUser.displayName,author_image: fb.currentUser.photoURL,- environment: environment,+ environment,}usersCollection.doc(fb.currentUser.uid)diff --git a/functions/jsonParse.js b/functions/jsonParse.jsindex bc4b5d008..23ceb4de3 100644--- a/functions/jsonParse.js+++ b/functions/jsonParse.js@@ -120,10 +120,10 @@ function expect(str) {if (kind === "EOF") {found = "[end of file]"} else if (end - start > 1) {- found = "`" + string.slice(start, end) + "`"+ found = `\`${string.slice(start, end)}\``} else {const match = string.slice(start).match(/^.+?\b/)- found = "`" + (match ? match[0] : string[start]) + "`"+ found = `\`${match ? match[0] : string[start]}\``}throw syntaxError(`Expected ${str} but found ${found}.`)diff --git a/functions/requestParams.js b/functions/requestParams.jsindex 80ea19821..5bcbd46e3 100644--- a/functions/requestParams.js+++ b/functions/requestParams.js@@ -1,17 +1,15 @@export function hasPathParams(params) {- return params.some((p) => p.type === "path")+ return params.some(({ type }) => type === "path")}-+export function addPathParamsToVariables(params, variables) {- params- .filter(({ key }) => !!key)- .filter(({ type }) => type === "path")- .forEach(p => variables[p.key] = p.value)- return variables;+ params+ .filter(({ key }) => !!key)+ .filter(({ type }) => type === "path")+ .forEach(({ key, value }) => (variables[key] = value))+ return variables}export function getQueryParams(params) {- return params- .filter(({ key }) => !!key)- .filter(({ type }) => type != "path")-}\ No newline at end of file+ return params.filter(({ key }) => !!key).filter(({ type }) => type != "path")+}diff --git a/functions/syntax/gqlQueryLangMode.js b/functions/syntax/gqlQueryLangMode.jsindex 2adb43300..6fdb40f39 100644--- a/functions/syntax/gqlQueryLangMode.js+++ b/functions/syntax/gqlQueryLangMode.js@@ -9,16 +9,16 @@ export function defineGQLLanguageMode(ace) {const TextHighlightRules = aceRequire("ace/mode/text_highlight_rules").TextHighlightRulesconst GQLQueryTextHighlightRules = function () {- var keywords =+ const keywords ="type|interface|union|enum|schema|input|implements|extends|scalar|fragment|query|mutation|subscription"- var dataTypes = "Int|Float|String|ID|Boolean"+ const dataTypes = "Int|Float|String|ID|Boolean"- var literalValues = "true|false|null"+ const literalValues = "true|false|null"- var escapeRe = /\\(?:u[\da-fA-f]{4}|.)/+ const escapeRe = /\\(?:u[\da-fA-f]{4}|.)/- var keywordMapper = this.createKeywordMapper(+ const keywordMapper = this.createKeywordMapper({keyword: keywords,"storage.type": dataTypes,@@ -48,7 +48,7 @@ export function defineGQLLanguageMode(ace) {},{token: "string", // character- regex: "'(?:" + escapeRe + "|.)?'",+ regex: `'(?:${escapeRe}|.)?'`,},{token: "string.start",diff --git a/functions/utils/uri.js b/functions/utils/uri.jsindex 3fd4091de..d16cd0fb1 100644--- a/functions/utils/uri.js+++ b/functions/utils/uri.js@@ -1,13 +1,13 @@export function parseUrlAndPath(value) {- let result = {}- try {- let url = new URL(value)- result.url = url.origin- result.path = url.pathname- } catch (error) {- let uriRegex = value.match(/^((http[s]?:\/\/)?(<<[^\/]+>>)?[^\/]*|)(\/?.*)$/)- result.url = uriRegex[1]- result.path = uriRegex[4]- }- return result;-}\ No newline at end of file+ let result = {}+ try {+ let url = new URL(value)+ result.url = url.origin+ result.path = url.pathname+ } catch (error) {+ let uriRegex = value.match(/^((http[s]?:\/\/)?(<<[^\/]+>>)?[^\/]*|)(\/?.*)$/)+ result.url = uriRegex[1]+ result.path = uriRegex[4]+ }+ return result+}diff --git a/pages/graphql.vue b/pages/graphql.vueindex 4f5d2cc15..552bdba9f 100644--- a/pages/graphql.vue+++ b/pages/graphql.vue@@ -522,8 +522,8 @@ export default {try {let headers = {}- this.headers.forEach((header) => {- headers[header.key] = header.value+ this.headers.forEach(({ key, value }) => {+ headers[key] = value})let variables = JSON.parse(this.variableString || "{}")@@ -624,8 +624,8 @@ export default {})let headers = {}- this.headers.forEach((header) => {- headers[header.key] = header.value+ this.headers.forEach(({ key, value }) => {+ headers[key] = value})const reqOptions = {diff --git a/pages/index.vue b/pages/index.vueindex 1a0ae504e..f1d82597f 100644--- a/pages/index.vue+++ b/pages/index.vue@@ -1409,7 +1409,7 @@ const parseHeaders = (xhr) => {return headerMap}export const findStatusGroup = (responseStatus) =>- statusCategories.find((status) => status.statusCodeRegex.test(responseStatus))+ statusCategories.find(({ statusCodeRegex }) => statusCodeRegex.test(responseStatus))export default {directives: {textareaAutoHeight,diff --git a/store/postwoman.js b/store/postwoman.jsindex c9b58d43c..dc38e8dda 100644--- a/store/postwoman.js+++ b/store/postwoman.js@@ -138,11 +138,9 @@ export const mutations = {},importAddEnvironments(state, { environments, confirmation }) {- const duplicateEnvironment = environments.some(item => {- return state.environments.some(item2 => {- return item.name.toLowerCase() === item2.name.toLowerCase()- })- })+ const duplicateEnvironment = environments.some(({ name }) =>+ state.environments.some(({ name }) => name.toLowerCase() === name.toLowerCase())+ )if (duplicateEnvironment) {this.$toast.info("Duplicate environment")return@@ -170,7 +168,7 @@ export const mutations = {environments.length === 1? false: environments.some(- item =>+ (item) =>item.environmentIndex !== environmentIndex &&item.name.toLowerCase() === name.toLowerCase())@@ -198,7 +196,7 @@ export const mutations = {addNewCollection({ collections }, collection) {const { name } = collectionconst duplicateCollection = collections.some(- item => item.name.toLowerCase() === name.toLowerCase()+ (item) => item.name.toLowerCase() === name.toLowerCase())if (duplicateCollection) {this.$toast.info("Duplicate collection")@@ -221,7 +219,7 @@ export const mutations = {const { collection, collectionIndex } = payloadconst { name } = collectionconst duplicateCollection = collections.some(- item => item.name.toLowerCase() === name.toLowerCase()+ (item) => item.name.toLowerCase() === name.toLowerCase())if (duplicateCollection) {this.$toast.info("Duplicate collection")