Skip to content

Instantly share code, notes, and snippets.

@simple17
Last active May 29, 2020 11:44
Show Gist options
  • Save simple17/5f31d89d2f4b2c1c24bf014c9cd406fb to your computer and use it in GitHub Desktop.
Save simple17/5f31d89d2f4b2c1c24bf014c9cd406fb to your computer and use it in GitHub Desktop.
[fillTemplate]
export const fillTemplate = (templateString, templateVars) => {
return templateString ? templateString.replace(/{([^{}]*)}/g,
function(a, b) {
var r = templateVars[b];
return typeof r === 'string' || typeof r === 'number' ? r : a;
}
) : '';
};
////
const tyText = fillTemplate(thankYouTextTemplate, {Name: 'Alex', DealerName: 'Mersedes SPB'});
console.log(tyText);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment