✨ Introducing The Forge (#1072)
The Forge allows anyone to easily create their own Typebot Block. Closes #380
This commit is contained in:
19
packages/variables/extractVariablesFromText.ts
Normal file
19
packages/variables/extractVariablesFromText.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import { Variable } from '@typebot.io/schemas'
|
||||
|
||||
export const extractVariablesFromText =
|
||||
(variables: Variable[]) =>
|
||||
(text: string): Variable[] => {
|
||||
const matches = [...text.matchAll(/\{\{(.*?)\}\}/g)]
|
||||
return matches.reduce<Variable[]>((acc, match) => {
|
||||
const variableName = match[1]
|
||||
const variable = variables.find(
|
||||
(variable) => variable.name === variableName
|
||||
)
|
||||
if (
|
||||
!variable ||
|
||||
acc.find((accVariable) => accVariable.id === variable.id)
|
||||
)
|
||||
return acc
|
||||
return [...acc, variable]
|
||||
}, [])
|
||||
}
|
Reference in New Issue
Block a user