tickle/modules/utils/print.mjs

19 lines
513 B
JavaScript
Raw Normal View History

2023-05-09 02:00:53 +00:00
/**
* Mini-mustache templating system. Simply replaces all occurrences of {{key}} with the value of the key.
* @param {string} str
* @param {Record<string, any>} replacements
*/
export const print = (str, replacements) =>
str.replace(/{{(.*?)}}/g, (_match, key) => replacements[key] || '')
/**
*
* @param {string} str
* @returns {(replacements: Record<string, any>) => string}
*/
export const makeTemplate = (str) => print.bind(null, str)
print.makeTemplate = makeTemplate
export default print