2023-11-25 16:25:19 +01:00
|
|
|
|
export function interpolate(text, values, config) {
|
2024-05-08 13:16:23 +02:00
|
|
|
|
return Object.entries(extract(values || {})).reduce((text, [key, value]) => text.replace(new RegExp(`{{[ ]*${key}[ ]*}}`, `gm`), String(extract(value))), text)
|
2023-11-25 16:25:19 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function lookup(key, config) {
|
2024-05-08 13:16:23 +02:00
|
|
|
|
const parts = key.split(".")
|
|
|
|
|
let string = config.strings
|
|
|
|
|
|
|
|
|
|
while (string != null && parts.length > 0) {
|
|
|
|
|
string = string[parts.shift()]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return string != null ? string.toString() : null
|
2023-11-25 16:25:19 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function extract(obj) {
|
2024-05-08 13:16:23 +02:00
|
|
|
|
return (typeof obj === "function") ? obj() : obj
|
2023-11-25 16:25:19 +01:00
|
|
|
|
}
|