forked from MapComplete/MapComplete
Chore: reformat all files with prettier
This commit is contained in:
parent
5757ae5dea
commit
d008dcb54d
214 changed files with 8926 additions and 8196 deletions
69
Utils.ts
69
Utils.ts
|
@ -1,5 +1,5 @@
|
|||
import colors from "./assets/colors.json"
|
||||
import {HTMLElement} from "node-html-parser";
|
||||
import { HTMLElement } from "node-html-parser"
|
||||
|
||||
export class Utils {
|
||||
/**
|
||||
|
@ -687,10 +687,10 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be
|
|||
if (Array.isArray(leaf)) {
|
||||
for (let i = 0; i < (<any[]>leaf).length; i++) {
|
||||
const l = (<any[]>leaf)[i]
|
||||
collectedList.push({leaf: l, path: [...travelledPath, "" + i]})
|
||||
collectedList.push({ leaf: l, path: [...travelledPath, "" + i] })
|
||||
}
|
||||
} else {
|
||||
collectedList.push({leaf, path: travelledPath})
|
||||
collectedList.push({ leaf, path: travelledPath })
|
||||
}
|
||||
return collectedList
|
||||
}
|
||||
|
@ -768,7 +768,7 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be
|
|||
})
|
||||
}
|
||||
|
||||
const cp = {...json}
|
||||
const cp = { ...json }
|
||||
for (const key in json) {
|
||||
cp[key] = Utils.WalkJson(json[key], f, isLeaf, [...path, key])
|
||||
}
|
||||
|
@ -898,11 +898,11 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be
|
|||
const xhr = new XMLHttpRequest()
|
||||
xhr.onload = () => {
|
||||
if (xhr.status == 200) {
|
||||
resolve({content: xhr.response})
|
||||
resolve({ content: xhr.response })
|
||||
} else if (xhr.status === 302) {
|
||||
resolve({redirect: xhr.getResponseHeader("location")})
|
||||
resolve({ redirect: xhr.getResponseHeader("location") })
|
||||
} else if (xhr.status === 509 || xhr.status === 429) {
|
||||
resolve({error: "rate limited", url, statuscode: xhr.status})
|
||||
resolve({ error: "rate limited", url, statuscode: xhr.status })
|
||||
} else {
|
||||
resolve({
|
||||
error: "other error: " + xhr.statusText,
|
||||
|
@ -972,10 +972,10 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be
|
|||
}
|
||||
const promise =
|
||||
/*NO AWAIT as we work with the promise directly */ Utils.downloadJsonAdvanced(
|
||||
url,
|
||||
headers
|
||||
)
|
||||
Utils._download_cache.set(url, {promise, timestamp: new Date().getTime()})
|
||||
url,
|
||||
headers
|
||||
)
|
||||
Utils._download_cache.set(url, { promise, timestamp: new Date().getTime() })
|
||||
return await promise
|
||||
}
|
||||
|
||||
|
@ -994,11 +994,11 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be
|
|||
const injected = Utils.injectedDownloads[url]
|
||||
if (injected !== undefined) {
|
||||
console.log("Using injected resource for test for URL", url)
|
||||
return new Promise((resolve, _) => resolve({content: injected}))
|
||||
return new Promise((resolve, _) => resolve({ content: injected }))
|
||||
}
|
||||
const result = await Utils.downloadAdvanced(
|
||||
url,
|
||||
Utils.Merge({accept: "application/json"}, headers ?? {})
|
||||
Utils.Merge({ accept: "application/json" }, headers ?? {})
|
||||
)
|
||||
if (result["error"] !== undefined) {
|
||||
return <{ error: string; url: string; statuscode?: number }>result
|
||||
|
@ -1006,12 +1006,12 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be
|
|||
const data = result["content"]
|
||||
try {
|
||||
if (typeof data === "string") {
|
||||
return {content: JSON.parse(data)}
|
||||
return { content: JSON.parse(data) }
|
||||
}
|
||||
return {content: data}
|
||||
return { content: data }
|
||||
} catch (e) {
|
||||
console.error("Could not parse ", data, "due to", e, "\n", e.stack)
|
||||
return {error: "malformed", url}
|
||||
return { error: "malformed", url }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1035,7 +1035,7 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be
|
|||
const element = document.createElement("a")
|
||||
let file
|
||||
if (typeof contents === "string") {
|
||||
file = new Blob([contents], {type: options?.mimetype ?? "text/plain"})
|
||||
file = new Blob([contents], { type: options?.mimetype ?? "text/plain" })
|
||||
} else {
|
||||
file = contents
|
||||
}
|
||||
|
@ -1152,7 +1152,12 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be
|
|||
if (typeof window === "undefined") {
|
||||
return "https://mapcomplete.osm.be"
|
||||
}
|
||||
const path = (window.location.protocol + "//" + window.location.host + window.location.pathname).split("/")
|
||||
const path = (
|
||||
window.location.protocol +
|
||||
"//" +
|
||||
window.location.host +
|
||||
window.location.pathname
|
||||
).split("/")
|
||||
path.pop()
|
||||
path.push("index.html")
|
||||
return path.join("/")
|
||||
|
@ -1301,7 +1306,7 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be
|
|||
if (match == undefined) {
|
||||
return undefined
|
||||
}
|
||||
return {r: Number(match[1]), g: Number(match[2]), b: Number(match[3])}
|
||||
return { r: Number(match[1]), g: Number(match[2]), b: Number(match[3]) }
|
||||
}
|
||||
|
||||
if (!hex.startsWith("#")) {
|
||||
|
@ -1351,9 +1356,7 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be
|
|||
|
||||
public static scrollIntoView(element: HTMLBaseElement) {
|
||||
// Is the element completely in the view?
|
||||
const parentRect = Utils.findParentWithScrolling(
|
||||
element
|
||||
).getBoundingClientRect()
|
||||
const parentRect = Utils.findParentWithScrolling(element).getBoundingClientRect()
|
||||
const elementRect = element.getBoundingClientRect()
|
||||
|
||||
// Check if the element is within the vertical bounds of the parent element
|
||||
|
@ -1363,7 +1366,7 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be
|
|||
if (inView) {
|
||||
return
|
||||
}
|
||||
element.scrollIntoView({behavior: "smooth", block: "nearest"})
|
||||
element.scrollIntoView({ behavior: "smooth", block: "nearest" })
|
||||
}
|
||||
|
||||
public static findParentWithScrolling(element: HTMLBaseElement): HTMLBaseElement {
|
||||
|
@ -1411,7 +1414,7 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be
|
|||
return true
|
||||
}
|
||||
|
||||
public static SameObject(a: any, b: any) {
|
||||
public static SameObject(a: any, b: any) {
|
||||
if (a === b) {
|
||||
return true
|
||||
}
|
||||
|
@ -1453,19 +1456,21 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be
|
|||
* Utils.splitIntoSubstitutionParts("abc {search} def") // => [{message: "abc "}, {subs: "search"}, {message: " def"}]
|
||||
*
|
||||
*/
|
||||
public static splitIntoSubstitutionParts(template: string): ({ message: string } | {subs: string})[]{
|
||||
public static splitIntoSubstitutionParts(
|
||||
template: string
|
||||
): ({ message: string } | { subs: string })[] {
|
||||
const preparts = template.split("{")
|
||||
const spec : ({ message: string } | {subs: string})[] = []
|
||||
const spec: ({ message: string } | { subs: string })[] = []
|
||||
for (const prepart of preparts) {
|
||||
const postParts = prepart.split("}")
|
||||
if(postParts.length === 1){
|
||||
if (postParts.length === 1) {
|
||||
// This was a normal part
|
||||
spec.push({message: postParts[0]})
|
||||
}else{
|
||||
spec.push({ message: postParts[0] })
|
||||
} else {
|
||||
const [subs, message] = postParts
|
||||
spec.push({subs})
|
||||
if(message !== ""){
|
||||
spec.push({message})
|
||||
spec.push({ subs })
|
||||
if (message !== "") {
|
||||
spec.push({ message })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue