@@ -51,6 +51,13 @@ export function parseInput(input: unknown, outputs: Record<string, Record<string
5151 return input
5252}
5353
54+ // Your custom handler for undefined functions
55+ const customFunctionHandler = ( name , args ) => {
56+ console . log ( `Unknown function ${ name } called with arguments:` , args )
57+ // You can return whatever you like here or throw an error
58+ return null
59+ }
60+
5461/**
5562 * Replace references with their values and calculate expression
5663 * Example:
@@ -60,7 +67,7 @@ export function parseInput(input: unknown, outputs: Record<string, Record<string
6067 */
6168export function calculateExpression ( input : string , references : Record < string , Record < string , unknown > > ) : unknown {
6269 // each "[\w[\]]" group matches the allowed characters for variables, including array access (e.g. a.b[0].c)
63- const operatorsRegex = / [ \w \s [ \] ] + ( \. [ \w \s [ \] ] + | \[ \d + \] ) * / g
70+ const operatorsRegex = / ( \w + \[ \w + \] | \w + ) \. [ \w \[ \] ] + ( \. [ \w \[ \] ] + ) * / g
6471
6572 const operators = [ ...input . matchAll ( operatorsRegex ) ]
6673
@@ -100,6 +107,11 @@ export function calculateExpression(input: string, references: Record<string, Re
100107 }
101108 return ( '' + str ) . substring ( start , end )
102109 } )
110+ parser . set ( 'contact' , ( str : string , params : string ) => {
111+ console . log ( `get: ${ str } ` , params )
112+ console . log ( `references:` , references )
113+ return _ . get ( references , `${ str } [${ params } ]` )
114+ } )
103115 parser . set ( 'formatNumber' , ( value : number , locales ?: Intl . LocalesArgument ) => Number ( value ) . toLocaleString ( locales ) )
104116 parser . set ( 'lowercase' , ( str : string ) => ( str ? ( '' + str ) . toLowerCase ( ) : str ) )
105117 parser . set ( 'uppercase' , ( str : string ) => ( str ? ( '' + str ) . toUpperCase ( ) : str ) )
@@ -181,3 +193,7 @@ export function findOutputKeys(input: Record<string, any>, key: string): string[
181193
182194 return matches
183195}
196+
197+ export function strToInterpolationKey ( str : string ) : string {
198+ return str . replace ( / [ ^ a - z A - Z 0 - 9 ] / g, '_' )
199+ }
0 commit comments