Files
FastGPT/projects/app/src/utils/common/tools/text.ts
2023-10-11 17:18:43 +08:00

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