mirror of
https://github.com/dadosfera/maestro.git
synced 2026-10-15 03:39:09 +00:00
8 lines
364 B
TypeScript
8 lines
364 B
TypeScript
export const mustache = (string: string, data: Record<string, any> = {}) => {
|
|
return Object.entries(data).reduce((res, [key, value]) => {
|
|
const mainRe = new RegExp(`(?<!\\\\){{\\s*${key}\\s*}}`, 'g');
|
|
const escapeRe = new RegExp(`\\\\({{\\s*${key}\\s*}})`, 'g');
|
|
return res.replace(mainRe, value.toString()).replace(escapeRe, '$1');
|
|
}, string);
|
|
};
|