2019-10-30 01:28:44 +00:00
|
|
|
export default function parseTemplateString(string, variables) {
|
2019-11-12 04:52:50 +00:00
|
|
|
if (!variables || !string) {
|
2020-02-24 18:44:50 +00:00
|
|
|
return string
|
2019-11-12 04:52:50 +00:00
|
|
|
}
|
2020-02-24 18:44:50 +00:00
|
|
|
const searchTerm = /<<([^>]*)>>/g // "<<myVariable>>"
|
2021-05-18 09:27:29 +00:00
|
|
|
return decodeURI(encodeURI(string)).replace(
|
|
|
|
|
searchTerm,
|
|
|
|
|
(_, p1) => variables[p1] || ""
|
|
|
|
|
)
|
2019-10-30 01:28:44 +00:00
|
|
|
}
|