twenty / packages /twenty-shared /src /utils /evalFromContext.ts
Jules
Initial clean CRM deployment with prebuilt assets
d9494a5
Raw
History Blame Contribute Delete
563 Bytes
import Handlebars from 'handlebars';
export const evalFromContext = (
input: string,
context: Record<string, unknown>,
) => {
try {
Handlebars.registerHelper('json', (input: string) => JSON.stringify(input));
const inputWithHelper = input
.replace('{{', '{{{ json ')
.replace('}}', ' }}}');
const inferredInput = Handlebars.compile(inputWithHelper)(context, {
helpers: {
json: (input: string) => JSON.stringify(input),
},
});
return JSON.parse(inferredInput);
} catch {
return undefined;
}
};