Files
documenso/packages/lib/utils/render-custom-email-template.ts
Ephraim Atta-Duncan 345343f4b5 feat: replace template variables with values
Co-authored-by: Mythie <me@lucasjamessmith.me>
2023-11-06 13:01:15 +11:00

21 lines
446 B
TypeScript

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 t;
};