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() {
let reader = new FileReader()
reader.onload = event => {
reader.onload = (event) => {
let content = event.target.result
let 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.result
let 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.header
if (requestObjectHeaders) {
pwRequest.headers = requestObjectHeaders
for (let header of pwRequest.headers) {
@@ -262,23 +260,23 @@ export default {
delete header.type
}
}
let requestObjectParams = requestObject.request.url.query
let requestObjectParams = request.url.query
if (requestObjectParams) {
pwRequest.params = requestObjectParams
for (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.urlencoded
pwRequest.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 pwRequest

View File

@@ -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()

View File

@@ -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()}`
},

View File

@@ -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)
},
},
}

View File

@@ -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 &&
section.offsetTop <= fromTop &&
section.offsetTop + section.offsetHeight > fromTop
) {
link.classList.add("current")
classList.add("current")
} else {
link.classList.remove("current")
classList.remove("current")
}
})
})

View File

@@ -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(),
})

View File

@@ -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.length
switch (direction) {
case "up":

View File

@@ -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: {

View File

@@ -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)

View File

@@ -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}.`)

View File

@@ -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")
}
return params.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 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",

View File

@@ -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;
}
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
}

View File

@@ -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 = {

View File

@@ -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,

View File

@@ -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 } = collection
const 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 } = payload
const { name } = collection
const duplicateCollection = collections.some(
item => item.name.toLowerCase() === name.toLowerCase()
(item) => item.name.toLowerCase() === name.toLowerCase()
)
if (duplicateCollection) {
this.$toast.info("Duplicate collection")