Last active
May 29, 2020 11:44
-
-
Save simple17/5f31d89d2f4b2c1c24bf014c9cd406fb to your computer and use it in GitHub Desktop.
[fillTemplate]
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
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