Open YogiAhir opened 4 days ago
import { LightningElement, api } from 'lwc'; import { replacePlaceholders } from 'c/replacePlaceholders';
export default class ReplaceStringLWC extends LightningElement { @api customerLastName; @api medOfProcessing; @api acctName; @api lastFourOfAccountNumber;
get formattedMessage() {
const template = 'Mr./Ms. <<Customer Last Name>>, the balance transfer was processed <<med of processing>>, to <<acct name>> ending in <<last four of account number>>.';
const values = {
'Customer Last Name': this.customerLastName,
'med of processing': this.medOfProcessing,
'acct name': this.acctName,
'last four of account number': this.lastFourOfAccountNumber
};
return replacePlaceholders(template, values);
}
}
export function replacePlaceholders(template, values) { return template.replace(/<<([^&]+)>>/g, (match, key) => { return values[key.trim()] || match; }); }
Const pickval = '/<<([^&]+)>>/g'
/<<([^&]+)>>/g
/< < ([^&]+) > > /g
export function replacePlaceholders(template, values) { return template.replace(/<<([^&]+)>>/g, (match, key) => { return values[key.trim()] || match; }); }