Files
hoppscotch/helpers/templating.js
2021-05-18 14:57:29 +05:30

11 lines
278 B
JavaScript

export default function parseTemplateString(string, variables) {
if (!variables || !string) {
return string
}
const searchTerm = /<<([^>]*)>>/g // "<<myVariable>>"
return decodeURI(encodeURI(string)).replace(
searchTerm,
(_, p1) => variables[p1] || ""
)
}