forked from MapComplete/MapComplete
Feature: allow a fallback value in substituting tags
This commit is contained in:
parent
35c4222466
commit
4d4a7e9d84
3 changed files with 32 additions and 32 deletions
13
src/Utils.ts
13
src/Utils.ts
|
@ -300,6 +300,10 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be
|
|||
* Utils.SubstituteKeys("abc{def}ghi", {def: '{XYZ}'}) // => "abc{XYZ}ghi"
|
||||
* Utils.SubstituteKeys("abc\n\n{def}ghi", {def: '{XYZ}'}) // => "abc\n\n{XYZ}ghi"
|
||||
*
|
||||
* // Should support a default value
|
||||
* Utils.SubstituteKeys("abc{def??XXX}ghi", {def: 'XYZ'}) // => "abcXYZghi"
|
||||
* Utils.SubstituteKeys("abc{def??XXX}ghi", {randomKey: 'XYZ'}) // => "abcXXXghi"
|
||||
*
|
||||
* @param txt
|
||||
* @param tags
|
||||
* @param useLang
|
||||
|
@ -322,8 +326,13 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be
|
|||
}
|
||||
let result = ""
|
||||
while (match) {
|
||||
const [_, normal, key, leftover] = match
|
||||
let v = tags?.[key]
|
||||
const [_, normal, keyFallback, leftover] = match
|
||||
let key = keyFallback
|
||||
let fallback = ""
|
||||
if (keyFallback.indexOf("??") >= 0) {
|
||||
[key, fallback] = keyFallback.split("??")
|
||||
}
|
||||
let v = tags?.[key] ?? fallback
|
||||
if (v !== undefined && v !== null) {
|
||||
if (v["toISOString"] != undefined) {
|
||||
// This is a date, probably the timestamp of the object
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue