Skip to content

Instantly share code, notes, and snippets.

@geraldyeo
Created November 29, 2023 03:49
Show Gist options
  • Save geraldyeo/8ff0686be3dfbc2ceb9ae2c7f876d99e to your computer and use it in GitHub Desktop.
Save geraldyeo/8ff0686be3dfbc2ceb9ae2c7f876d99e to your computer and use it in GitHub Desktop.
Simple template replacement
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