13 lines
314 B
TypeScript
13 lines
314 B
TypeScript
/*
|
|
replace {{variable}} to value
|
|
*/
|
|
export function replaceVariable(text: string, obj: Record<string, string | number>) {
|
|
for (const key in obj) {
|
|
const val = obj[key];
|
|
if (typeof val !== 'string') continue;
|
|
|
|
text = text.replace(new RegExp(`{{(${key})}}`, 'g'), val);
|
|
}
|
|
return text || '';
|
|
}
|