I have been working on an application with an editable script feature. As I go through the script, I find myself needing to replace placeholders with local data. While this process is functional, it feels quite messy.
initScript(script: LegalScript, lead: LeadTl): LegalScript {
const scriptVar = new LegalScriptVariables(lead);
for (let i = 1; i <= 30; i++) {
script[`html${i}`] = this.replaceHtml(script[`html${i}`], scriptVar);
}
return script;
}
replaceHtml(html: string, scriptVar: LegalScriptVariables) {
html = this.replaceClientFirstName(html, scriptVar.clientFirstName);
html = this.replaceClientLastName(html, scriptVar.clientLastName);
html = this.replaceAgentName(html, scriptVar.agentName);
html = this.replaceProductName(html, scriptVar.productName);
html = this.replacePolicyDeductionDate(html, scriptVar.policyDeductionDay);
html = this.replacePolicyInceptionDate(html, scriptVar.policyInceptionDate);
return html;
}
Does anyone have a more streamlined solution to improve this code?