Created
August 27, 2020 16:04
-
-
Save bnb/e6e675baf9d89162bbc532f0a83b2dbb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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