tickle/modules/utils/print.mjs

19 lines
533 B
JavaScript
Raw Permalink 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}
*/
2023-06-13 16:50:13 +00:00
export const makeMiniStringTemplate = (str) => print.bind(null, str)
2023-05-09 02:00:53 +00:00
2023-06-13 16:50:13 +00:00
print.makeTemplate = makeMiniStringTemplate
2023-05-09 02:00:53 +00:00
export default print