Transpiled ES5 code to ES6/ES7

This commit is contained in:
Liyas Thomas
2020-06-11 19:55:40 +05:30
parent 9bc0ae975a
commit 0644a8c9fb
16 changed files with 108 additions and 123 deletions

View File

@@ -107,7 +107,7 @@ export default {
}, },
replaceWithJSON() { replaceWithJSON() {
let reader = new FileReader() let reader = new FileReader()
reader.onload = event => { reader.onload = (event) => {
let content = event.target.result let content = event.target.result
let collections = JSON.parse(content) let collections = JSON.parse(content)
if (collections[0]) { if (collections[0]) {
@@ -127,7 +127,7 @@ export default {
}, },
importFromJSON() { importFromJSON() {
let reader = new FileReader() let reader = new FileReader()
reader.onload = event => { reader.onload = (event) => {
let content = event.target.result let content = event.target.result
let collections = JSON.parse(content) let collections = JSON.parse(content)
if (collections[0]) { if (collections[0]) {
@@ -177,7 +177,7 @@ export default {
icon: "error", icon: "error",
}) })
}, },
parsePostmanCollection(collection, folders = true) { parsePostmanCollection({ item, info, name }, folders = true) {
let postwomanCollection = folders let postwomanCollection = folders
? [ ? [
{ {
@@ -190,13 +190,13 @@ export default {
name: "", name: "",
requests: [], requests: [],
} }
for (let collectionItem of collection.item) { for (let collectionItem of item) {
if (collectionItem.request) { if (collectionItem.request) {
if (postwomanCollection[0]) { if (postwomanCollection[0]) {
postwomanCollection[0].name = collection.info ? collection.info.name : "" postwomanCollection[0].name = info ? info.name : ""
postwomanCollection[0].requests.push(this.parsePostmanRequest(collectionItem)) postwomanCollection[0].requests.push(this.parsePostmanRequest(collectionItem))
} else { } else {
postwomanCollection.name = collection.name ? collection.name : "" postwomanCollection.name = name ? name : ""
postwomanCollection.requests.push(this.parsePostmanRequest(collectionItem)) postwomanCollection.requests.push(this.parsePostmanRequest(collectionItem))
} }
} else if (collectionItem.item) { } else if (collectionItem.item) {
@@ -207,7 +207,7 @@ export default {
} }
return postwomanCollection return postwomanCollection
}, },
parsePostmanRequest(requestObject) { parsePostmanRequest({ name, request }) {
let pwRequest = { let pwRequest = {
url: "", url: "",
path: "", path: "",
@@ -227,16 +227,14 @@ export default {
name: "", name: "",
} }
pwRequest.name = requestObject.name pwRequest.name = name
let requestObjectUrl = requestObject.request.url.raw.match( let requestObjectUrl = request.url.raw.match(/^(.+:\/\/[^\/]+|{[^\/]+})(\/[^\?]+|).*$/)
/^(.+:\/\/[^\/]+|{[^\/]+})(\/[^\?]+|).*$/
)
if (requestObjectUrl) { if (requestObjectUrl) {
pwRequest.url = requestObjectUrl[1] pwRequest.url = requestObjectUrl[1]
pwRequest.path = requestObjectUrl[2] ? requestObjectUrl[2] : "" pwRequest.path = requestObjectUrl[2] ? requestObjectUrl[2] : ""
} }
pwRequest.method = requestObject.request.method pwRequest.method = request.method
let itemAuth = requestObject.request.auth ? requestObject.request.auth : "" let itemAuth = request.auth ? request.auth : ""
let authType = itemAuth ? itemAuth.type : "" let authType = itemAuth ? itemAuth.type : ""
if (authType === "basic") { if (authType === "basic") {
pwRequest.auth = "Basic Auth" pwRequest.auth = "Basic Auth"
@@ -254,7 +252,7 @@ export default {
pwRequest.auth = "Bearer Token" pwRequest.auth = "Bearer Token"
pwRequest.bearerToken = itemAuth.bearer[0].value pwRequest.bearerToken = itemAuth.bearer[0].value
} }
let requestObjectHeaders = requestObject.request.header let requestObjectHeaders = request.header
if (requestObjectHeaders) { if (requestObjectHeaders) {
pwRequest.headers = requestObjectHeaders pwRequest.headers = requestObjectHeaders
for (let header of pwRequest.headers) { for (let header of pwRequest.headers) {
@@ -262,23 +260,23 @@ export default {
delete header.type delete header.type
} }
} }
let requestObjectParams = requestObject.request.url.query let requestObjectParams = request.url.query
if (requestObjectParams) { if (requestObjectParams) {
pwRequest.params = requestObjectParams pwRequest.params = requestObjectParams
for (let param of pwRequest.params) { for (let param of pwRequest.params) {
delete param.disabled delete param.disabled
} }
} }
if (requestObject.request.body) { if (request.body) {
if (requestObject.request.body.mode === "urlencoded") { if (request.body.mode === "urlencoded") {
let params = requestObject.request.body.urlencoded let params = request.body.urlencoded
pwRequest.bodyParams = params ? params : [] pwRequest.bodyParams = params ? params : []
for (let param of pwRequest.bodyParams) { for (let param of pwRequest.bodyParams) {
delete param.type delete param.type
} }
} else if (requestObject.request.body.mode === "raw") { } else if (request.body.mode === "raw") {
pwRequest.rawInput = true pwRequest.rawInput = true
pwRequest.rawParams = requestObject.request.body.raw pwRequest.rawParams = request.body.raw
} }
} }
return pwRequest return pwRequest

View File

@@ -77,34 +77,33 @@ export default {
} }
self.showLoginSuccess() self.showLoginSuccess()
}) })
.catch(err => { .catch((err) => {
// An error happened. // An error happened.
if (err.code === "auth/account-exists-with-different-credential") { if (err.code === "auth/account-exists-with-different-credential") {
// Step 2. // Step 2.
// User's email already exists. // User's email already exists.
// The pending Google credential. // The pending Google credential.
var pendingCred = err.credential const pendingCred = err.credential
// The provider account's email address. // The provider account's email address.
var email = err.email const email = err.email
// Get sign-in methods for this email. // Get sign-in methods for this email.
firebase firebase
.auth() .auth()
.fetchSignInMethodsForEmail(email) .fetchSignInMethodsForEmail(email)
.then(function(methods) { .then((methods) => {
// Step 3. // Step 3.
// If the user has several sign-in methods, // If the user has several sign-in methods,
// the first method in the list will be the "recommended" method to use. // the first method in the list will be the "recommended" method to use.
if (methods[0] === "password") { if (methods[0] === "password") {
// Asks the user their password. // Asks the user their password.
// In real scenario, you should handle this asynchronously. // In real scenario, you should handle this asynchronously.
var password = promptUserForPassword() // TODO: implement promptUserForPassword. const password = promptUserForPassword() // TODO: implement promptUserForPassword.
auth auth
.signInWithEmailAndPassword(email, password) .signInWithEmailAndPassword(email, password)
.then(function(user) { .then((
// Step 4a. user // Step 4a.
return user.linkWithCredential(pendingCred) ) => user.linkWithCredential(pendingCred))
}) .then(() => {
.then(function() {
// Google account successfully linked to the existing Firebase user. // Google account successfully linked to the existing Firebase user.
self.showLoginSuccess() self.showLoginSuccess()
}) })
@@ -121,7 +120,7 @@ export default {
// All the other cases are external providers. // All the other cases are external providers.
// Construct provider object for that provider. // Construct provider object for that provider.
// TODO: implement getProviderForProviderId. // 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 // 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 // but with a different provider, and let them validate the fact they want to
// sign in with this provider. // sign in with this provider.
@@ -131,19 +130,17 @@ export default {
firebase firebase
.auth() .auth()
.signInWithPopup(provider) .signInWithPopup(provider)
.then(function(result) { .then(({ user }) => {
// Remember that the user may have signed in with an account that has a different email // 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 // 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. // sign in flow and the user is free to login using whichever account they own.
// Step 4b. // Step 4b.
// Link to Google credential. // Link to Google credential.
// As we have access to the pending credential, we can directly call the link method. // As we have access to the pending credential, we can directly call the link method.
result.user user.linkAndRetrieveDataWithCredential(pendingCred).then((usercred) => {
.linkAndRetrieveDataWithCredential(pendingCred) // Google account successfully linked to the existing Firebase user.
.then(function(usercred) { self.showLoginSuccess()
// Google account successfully linked to the existing Firebase user. })
self.showLoginSuccess()
})
}) })
toastObject.remove() toastObject.remove()
@@ -180,35 +177,34 @@ export default {
} }
self.showLoginSuccess() self.showLoginSuccess()
}) })
.catch(err => { .catch((err) => {
// An error happened. // An error happened.
if (err.code === "auth/account-exists-with-different-credential") { if (err.code === "auth/account-exists-with-different-credential") {
// Step 2. // Step 2.
// User's email already exists. // User's email already exists.
// The pending Google credential. // The pending Google credential.
var pendingCred = err.credential const pendingCred = err.credential
// The provider account's email address. // The provider account's email address.
var email = err.email const email = err.email
// Get sign-in methods for this email. // Get sign-in methods for this email.
firebase firebase
.auth() .auth()
.fetchSignInMethodsForEmail(email) .fetchSignInMethodsForEmail(email)
.then(function(methods) { .then((methods) => {
// Step 3. // Step 3.
// If the user has several sign-in methods, // If the user has several sign-in methods,
// the first method in the list will be the "recommended" method to use. // the first method in the list will be the "recommended" method to use.
if (methods[0] === "password") { if (methods[0] === "password") {
// Asks the user their password. // Asks the user their password.
// In real scenario, you should handle this asynchronously. // In real scenario, you should handle this asynchronously.
var password = promptUserForPassword() // TODO: implement promptUserForPassword. const password = promptUserForPassword() // TODO: implement promptUserForPassword.
firebase firebase
.auth() .auth()
.signInWithEmailAndPassword(email, password) .signInWithEmailAndPassword(email, password)
.then(function(user) { .then((
// Step 4a. user // Step 4a.
return user.linkWithCredential(pendingCred) ) => user.linkWithCredential(pendingCred))
}) .then(() => {
.then(function() {
// Google account successfully linked to the existing Firebase user. // Google account successfully linked to the existing Firebase user.
self.showLoginSuccess() self.showLoginSuccess()
}) })
@@ -225,7 +221,7 @@ export default {
// All the other cases are external providers. // All the other cases are external providers.
// Construct provider object for that provider. // Construct provider object for that provider.
// TODO: implement getProviderForProviderId. // 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 // 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 // but with a different provider, and let them validate the fact they want to
// sign in with this provider. // sign in with this provider.
@@ -235,18 +231,16 @@ export default {
firebase firebase
.auth() .auth()
.signInWithPopup(provider) .signInWithPopup(provider)
.then(function(result) { .then(({ user }) => {
// Remember that the user may have signed in with an account that has a different email // 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 // 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. // sign in flow and the user is free to login using whichever account they own.
// Step 4b. // Step 4b.
// Link to Google credential. // Link to Google credential.
// As we have access to the pending credential, we can directly call the link method. // As we have access to the pending credential, we can directly call the link method.
result.user user.linkAndRetrieveDataWithCredential(pendingCred).then((usercred) => {
.linkAndRetrieveDataWithCredential(pendingCred) self.showLoginSuccess()
.then(function(usercred) { })
self.showLoginSuccess()
})
}) })
toastObject.remove() toastObject.remove()

View File

@@ -64,14 +64,11 @@ export default {
computed: { computed: {
fieldString() { fieldString() {
const args = (this.gqlField.args || []).reduce((acc, arg, index) => { const args = (this.gqlField.args || []).reduce(
return ( (acc, { name, type }, index) =>
acc + acc + `${name}: ${type.toString()}${index !== this.gqlField.args.length - 1 ? ", " : ""}`,
`${arg.name}: ${arg.type.toString()}${ ""
index !== this.gqlField.args.length - 1 ? ", " : "" )
}`
)
}, "")
const argsString = args.length > 0 ? `(${args})` : "" const argsString = args.length > 0 ? `(${args})` : ""
return `${this.gqlField.name}${argsString}: ${this.gqlField.type.toString()}` return `${this.gqlField.name}${argsString}: ${this.gqlField.type.toString()}`
}, },

View File

@@ -91,7 +91,7 @@ export default {
computed: { computed: {
availableLocales() { availableLocales() {
return this.$i18n.locales.filter(i => i.code !== this.$i18n.locale) return this.$i18n.locales.filter(({ code }) => code !== this.$i18n.locale)
}, },
}, },
} }

View File

@@ -276,20 +276,20 @@ export default {
}, },
mounted() { mounted() {
window.addEventListener("scroll", event => { window.addEventListener("scroll", (event) => {
let mainNavLinks = document.querySelectorAll("nav ul li a") let mainNavLinks = document.querySelectorAll("nav ul li a")
let fromTop = window.scrollY let fromTop = window.scrollY
mainNavLinks.forEach(link => { mainNavLinks.forEach(({ hash, classList }) => {
let section = document.querySelector(link.hash) let section = document.querySelector(hash)
if ( if (
section && section &&
section.offsetTop <= fromTop && section.offsetTop <= fromTop &&
section.offsetTop + section.offsetHeight > fromTop section.offsetTop + section.offsetHeight > fromTop
) { ) {
link.classList.add("current") classList.add("current")
} else { } else {
link.classList.remove("current") classList.remove("current")
} }
}) })
}) })

View File

@@ -110,9 +110,9 @@ export default {
icon: "sync_disabled", icon: "sync_disabled",
}) })
} }
this.sse.onmessage = (event) => { this.sse.onmessage = ({ data }) => {
this.events.log.push({ this.events.log.push({
payload: event.data, payload: data,
source: "server", source: "server",
ts: new Date().toLocaleTimeString(), ts: new Date().toLocaleTimeString(),
}) })

View File

@@ -136,9 +136,9 @@ export default {
icon: "sync_disabled", icon: "sync_disabled",
}) })
} }
this.socket.onmessage = (event) => { this.socket.onmessage = ({ data }) => {
this.communication.log.push({ this.communication.log.push({
payload: event.data, payload: data,
source: "server", source: "server",
ts: new Date().toLocaleTimeString(), ts: new Date().toLocaleTimeString(),
}) })
@@ -181,7 +181,7 @@ export default {
this.communication.input = "" this.communication.input = ""
}, },
walkHistory(direction) { walkHistory(direction) {
const clientMessages = this.communication.log.filter((msg) => msg.source === "client") const clientMessages = this.communication.log.filter(({ source }) => source === "client")
const length = clientMessages.length const length = clientMessages.length
switch (direction) { switch (direction) {
case "up": case "up":

View File

@@ -1,9 +1,9 @@
// Docs on event and context https://www.netlify.com/docs/functions/#the-handler-method // Docs on event and context https://www.netlify.com/docs/functions/#the-handler-method
exports.handler = async (event, context) => { export async function handler({ httpMethod, queryStringParameters }, context) {
switch (event.httpMethod) { switch (httpMethod) {
case "GET": case "GET":
try { try {
const name = event.queryStringParameters.name || "World" const name = queryStringParameters.name || "World"
return { return {
statusCode: 200, statusCode: 200,
headers: { headers: {

View File

@@ -105,7 +105,7 @@ export const fb = {
author: fb.currentUser.uid, author: fb.currentUser.uid,
author_name: fb.currentUser.displayName, author_name: fb.currentUser.displayName,
author_image: fb.currentUser.photoURL, author_image: fb.currentUser.photoURL,
collection: collection, collection,
} }
usersCollection usersCollection
.doc(fb.currentUser.uid) .doc(fb.currentUser.uid)
@@ -120,7 +120,7 @@ export const fb = {
author: fb.currentUser.uid, author: fb.currentUser.uid,
author_name: fb.currentUser.displayName, author_name: fb.currentUser.displayName,
author_image: fb.currentUser.photoURL, author_image: fb.currentUser.photoURL,
environment: environment, environment,
} }
usersCollection usersCollection
.doc(fb.currentUser.uid) .doc(fb.currentUser.uid)

View File

@@ -120,10 +120,10 @@ function expect(str) {
if (kind === "EOF") { if (kind === "EOF") {
found = "[end of file]" found = "[end of file]"
} else if (end - start > 1) { } else if (end - start > 1) {
found = "`" + string.slice(start, end) + "`" found = `\`${string.slice(start, end)}\``
} else { } else {
const match = string.slice(start).match(/^.+?\b/) 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}.`) throw syntaxError(`Expected ${str} but found ${found}.`)

View File

@@ -1,17 +1,15 @@
export function hasPathParams(params) { export function hasPathParams(params) {
return params.some((p) => p.type === "path") return params.some(({ type }) => type === "path")
} }
export function addPathParamsToVariables(params, variables) { export function addPathParamsToVariables(params, variables) {
params params
.filter(({ key }) => !!key) .filter(({ key }) => !!key)
.filter(({ type }) => type === "path") .filter(({ type }) => type === "path")
.forEach(p => variables[p.key] = p.value) .forEach(({ key, value }) => (variables[key] = value))
return variables; return variables
} }
export function getQueryParams(params) { export function getQueryParams(params) {
return params return params.filter(({ key }) => !!key).filter(({ type }) => type != "path")
.filter(({ key }) => !!key) }
.filter(({ type }) => type != "path")
}

View File

@@ -9,16 +9,16 @@ export function defineGQLLanguageMode(ace) {
const TextHighlightRules = aceRequire("ace/mode/text_highlight_rules").TextHighlightRules const TextHighlightRules = aceRequire("ace/mode/text_highlight_rules").TextHighlightRules
const GQLQueryTextHighlightRules = function () { const GQLQueryTextHighlightRules = function () {
var keywords = const keywords =
"type|interface|union|enum|schema|input|implements|extends|scalar|fragment|query|mutation|subscription" "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, keyword: keywords,
"storage.type": dataTypes, "storage.type": dataTypes,
@@ -48,7 +48,7 @@ export function defineGQLLanguageMode(ace) {
}, },
{ {
token: "string", // character token: "string", // character
regex: "'(?:" + escapeRe + "|.)?'", regex: `'(?:${escapeRe}|.)?'`,
}, },
{ {
token: "string.start", token: "string.start",

View File

@@ -1,13 +1,13 @@
export function parseUrlAndPath(value) { export function parseUrlAndPath(value) {
let result = {} let result = {}
try { try {
let url = new URL(value) let url = new URL(value)
result.url = url.origin result.url = url.origin
result.path = url.pathname result.path = url.pathname
} catch (error) { } catch (error) {
let uriRegex = value.match(/^((http[s]?:\/\/)?(<<[^\/]+>>)?[^\/]*|)(\/?.*)$/) let uriRegex = value.match(/^((http[s]?:\/\/)?(<<[^\/]+>>)?[^\/]*|)(\/?.*)$/)
result.url = uriRegex[1] result.url = uriRegex[1]
result.path = uriRegex[4] result.path = uriRegex[4]
} }
return result; return result
} }

View File

@@ -522,8 +522,8 @@ export default {
try { try {
let headers = {} let headers = {}
this.headers.forEach((header) => { this.headers.forEach(({ key, value }) => {
headers[header.key] = header.value headers[key] = value
}) })
let variables = JSON.parse(this.variableString || "{}") let variables = JSON.parse(this.variableString || "{}")
@@ -624,8 +624,8 @@ export default {
}) })
let headers = {} let headers = {}
this.headers.forEach((header) => { this.headers.forEach(({ key, value }) => {
headers[header.key] = header.value headers[key] = value
}) })
const reqOptions = { const reqOptions = {

View File

@@ -1409,7 +1409,7 @@ const parseHeaders = (xhr) => {
return headerMap return headerMap
} }
export const findStatusGroup = (responseStatus) => export const findStatusGroup = (responseStatus) =>
statusCategories.find((status) => status.statusCodeRegex.test(responseStatus)) statusCategories.find(({ statusCodeRegex }) => statusCodeRegex.test(responseStatus))
export default { export default {
directives: { directives: {
textareaAutoHeight, textareaAutoHeight,

View File

@@ -138,11 +138,9 @@ export const mutations = {
}, },
importAddEnvironments(state, { environments, confirmation }) { importAddEnvironments(state, { environments, confirmation }) {
const duplicateEnvironment = environments.some(item => { const duplicateEnvironment = environments.some(({ name }) =>
return state.environments.some(item2 => { state.environments.some(({ name }) => name.toLowerCase() === name.toLowerCase())
return item.name.toLowerCase() === item2.name.toLowerCase() )
})
})
if (duplicateEnvironment) { if (duplicateEnvironment) {
this.$toast.info("Duplicate environment") this.$toast.info("Duplicate environment")
return return
@@ -170,7 +168,7 @@ export const mutations = {
environments.length === 1 environments.length === 1
? false ? false
: environments.some( : environments.some(
item => (item) =>
item.environmentIndex !== environmentIndex && item.environmentIndex !== environmentIndex &&
item.name.toLowerCase() === name.toLowerCase() item.name.toLowerCase() === name.toLowerCase()
) )
@@ -198,7 +196,7 @@ export const mutations = {
addNewCollection({ collections }, collection) { addNewCollection({ collections }, collection) {
const { name } = collection const { name } = collection
const duplicateCollection = collections.some( const duplicateCollection = collections.some(
item => item.name.toLowerCase() === name.toLowerCase() (item) => item.name.toLowerCase() === name.toLowerCase()
) )
if (duplicateCollection) { if (duplicateCollection) {
this.$toast.info("Duplicate collection") this.$toast.info("Duplicate collection")
@@ -221,7 +219,7 @@ export const mutations = {
const { collection, collectionIndex } = payload const { collection, collectionIndex } = payload
const { name } = collection const { name } = collection
const duplicateCollection = collections.some( const duplicateCollection = collections.some(
item => item.name.toLowerCase() === name.toLowerCase() (item) => item.name.toLowerCase() === name.toLowerCase()
) )
if (duplicateCollection) { if (duplicateCollection) {
this.$toast.info("Duplicate collection") this.$toast.info("Duplicate collection")