forked from MapComplete/MapComplete
Add translation buttons
This commit is contained in:
parent
592bc4ae0b
commit
2c7fb556dc
31 changed files with 442 additions and 150 deletions
31
Utils.ts
31
Utils.ts
|
@ -513,6 +513,37 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be
|
|||
return cp
|
||||
}
|
||||
|
||||
/**
|
||||
* Walks an object recursively. Will hang on objects with loops
|
||||
*/
|
||||
static WalkObject(json: any, collect: (v: number | string | boolean | undefined, path: string[]) => any, isLeaf: (object) => boolean = undefined, path = []) {
|
||||
if (json === undefined) {
|
||||
return;
|
||||
}
|
||||
const jtp = typeof json
|
||||
if (isLeaf !== undefined) {
|
||||
if (jtp !== "object") {
|
||||
return
|
||||
}
|
||||
|
||||
if (isLeaf(json)) {
|
||||
return collect(json, path)
|
||||
}
|
||||
} else if (jtp === "boolean" || jtp === "string" || jtp === "number") {
|
||||
return collect(json,path)
|
||||
}
|
||||
if (Array.isArray(json)) {
|
||||
return json.map((sub,i) => {
|
||||
return Utils.WalkObject(sub, collect, isLeaf,[...path, i]);
|
||||
})
|
||||
}
|
||||
|
||||
for (const key in json) {
|
||||
Utils.WalkObject(json[key], collect, isLeaf, [...path,key])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static getOrSetDefault<K, V>(dict: Map<K, V>, k: K, v: () => V) {
|
||||
let found = dict.get(k);
|
||||
if (found !== undefined) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue