@maizzle/framework
Version:
Maizzle is a framework that helps you quickly build HTML emails with Tailwind CSS.
19 lines (18 loc) • 757 B
JavaScript
//#region src/transformers/replaceStrings.ts
/**
* Replace strings transformer.
*
* Replaces strings in the HTML using the key-value pairs defined in
* `config.replaceStrings`. Each key is treated as a regular expression
* pattern (case-insensitive, global), and the value is the replacement.
*
* Character classes must be escaped in keys, e.g. `\\s` for `\s`.
*/
function replaceStrings(html, config = {}) {
const replacements = config.replaceStrings;
if (!replacements || Object.keys(replacements).length === 0) return html;
return Object.entries(replacements).reduce((result, [pattern, replacement]) => result.replace(new RegExp(pattern, "gi"), replacement), html);
}
//#endregion
export { replaceStrings };
//# sourceMappingURL=replaceStrings.js.map