fix: reverse meta relation and tidy code

This commit is contained in:
Mythie
2023-09-22 12:27:54 +00:00
parent 826a901c10
commit 7823100272
13 changed files with 168 additions and 108 deletions

View File

@ -2,19 +2,11 @@ export const renderCustomEmailTemplate = <T extends Record<string, string>>(
template: string,
variables: T,
): string => {
let t = template;
Object.entries(variables).forEach((entry) => {
const [key, value] = entry;
const placeholder = `{${key}}`;
const re = new RegExp(placeholder, 'g');
if (Object.prototype.hasOwnProperty.call(variables, key)) {
t = t.replace(re, String(value));
return template.replace(/\{(\S+)\}/g, (_, key) => {
if (key in variables) {
return variables[key];
}
});
return t;
return key;
});
};