Created
November 29, 2023 03:49
-
-
Save geraldyeo/8ff0686be3dfbc2ceb9ae2c7f876d99e to your computer and use it in GitHub Desktop.
Simple template replacement
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
function replaceMe(template, data) { | |
const pattern = /{\s*(\w+?)\s*}/g; // {property} | |
return template.replace(pattern, (_, token) => data.hasOwnProperty(token) ? data[token] : ''); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment