Skip to content

Instantly share code, notes, and snippets.

@bnb
Created August 27, 2020 16:04
Show Gist options
  • Save bnb/e6e675baf9d89162bbc532f0a83b2dbb to your computer and use it in GitHub Desktop.
Save bnb/e6e675baf9d89162bbc532f0a83b2dbb to your computer and use it in GitHub Desktop.
async function replaceVariables (stringifiedTemplate, templateVariables, templateValues) {
// replace each template variable with the relevant variable
try {
// - replace name
if (stringifiedTemplate.includes(templateVariables.name)) {
const RegExNameBecauseReplaceAllDidntExistInJavaScriptUntilRecently = new RegExp(templateVariables.name, 'g')
stringifiedTemplate = stringifiedTemplate.replace(RegExNameBecauseReplaceAllDidntExistInJavaScriptUntilRecently, templateValues.name)
}
return stringifiedTemplate
} catch (error) {
throw new Error(error)
}
}
module.exports = replaceVariables
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment