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":