Created
December 19, 2022 11:19
-
-
Save pointofpresence/419364f64cc223012d28669d01c48127 to your computer and use it in GitHub Desktop.
Простой шаблонизатор с трок ES6
This file contains hidden or 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
/** | |
* Простой шаблонизатор строк | |
*/ | |
const formatString = (template, params = {}) => { | |
const names = Object.keys(params); | |
const vals = Object.values(params); | |
return new Function(...names, `return \`${template}\`;`)(...vals); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment