feat: effective url environment templates work with headers, url and params

This commit is contained in:
Andrew Bastin
2021-07-31 22:21:14 -04:00
parent 7354951d5a
commit fcb194d08a
4 changed files with 55 additions and 29 deletions

15
helpers/templating.ts Normal file
View File

@@ -0,0 +1,15 @@
import { Environment } from "~/newstore/environments"
export default function parseTemplateString(
str: string,
variables: Environment["variables"]
) {
if (!variables || !str) {
return str
}
const searchTerm = /<<([^>]*)>>/g // "<<myVariable>>"
return decodeURI(encodeURI(str)).replace(
searchTerm,
(_, p1) => variables.find((x) => x.key === p1)?.value || ""
)
}