forked from tuvn86/webapp-conversation
12 lines
No EOL
431 B
TypeScript
12 lines
No EOL
431 B
TypeScript
import { PromptVariable } from '@/types/app'
|
|
|
|
export function replaceVarWithValues(str: string, promptVariables: PromptVariable[], inputs: Record<string, any>) {
|
|
return str.replace(/\{\{([^}]+)\}\}/g, (match, key) => {
|
|
const name = inputs[key]
|
|
if (name)
|
|
return name
|
|
|
|
const valueObj: PromptVariable | undefined = promptVariables.find(v => v.key === key)
|
|
return valueObj ? `{{${valueObj.key}}}` : match
|
|
})
|
|
} |