@@ -177,6 +177,30 @@ function executeFunction() {
177177 validationError = `Parameter '${ param . name } ' must be a valid object (e.g., { maxSize: 100 })` ;
178178 break ;
179179 }
180+ } else if ( param . type . includes ( "[]" ) ) {
181+ // Handle array types (e.g., 'unknown[]', 'string[]', etc.)
182+ try {
183+ if ( value ) {
184+ // Try to evaluate as JavaScript array notation
185+ try {
186+ value = new Function ( "return " + value ) ( ) ;
187+ if ( ! Array . isArray ( value ) ) {
188+ throw new Error ( "Not an array" ) ;
189+ }
190+ } catch {
191+ // Fall back to strict JSON parsing
192+ value = JSON . parse ( value ) ;
193+ if ( ! Array . isArray ( value ) ) {
194+ throw new Error ( "Not an array" ) ;
195+ }
196+ }
197+ } else {
198+ value = [ ] ;
199+ }
200+ } catch ( e ) {
201+ validationError = `Parameter '${ param . name } ' must be a valid array (e.g., ["apple", "banana"])` ;
202+ break ;
203+ }
180204 } else if ( param . type === "function" ) {
181205 // Special handling for memoize function parameter
182206 try {
@@ -316,21 +340,34 @@ function loadExamples(_functionName: string, meta: FunctionMeta) {
316340 const match = example . code . match ( / \( ( [ ^ ) ] * ) \) / ) ;
317341 if ( match ) {
318342 const argsStr = match [ 1 ] ;
319- // Simple parser for example args
320- const args = argsStr
321- . split ( "," )
322- . map ( ( s ) => s . trim ( ) . replace ( / ^ [ " ' ] | [ " ' ] $ / g, "" ) ) ;
323-
324- meta . params . forEach ( ( param , i ) => {
325- const input = document . getElementById (
326- `param-${ param . name } `
327- ) as HTMLInputElement ;
328- if ( input && args [ i ] !== undefined ) {
329- input . value = args [ i ] ;
330- }
331- } ) ;
332343
333- executeFunction ( ) ;
344+ // Use proper JavaScript evaluation to parse arguments
345+ // This handles arrays, objects, strings, numbers, etc. correctly
346+ try {
347+ const args = new Function ( `return [${ argsStr } ]` ) ( ) ;
348+
349+ meta . params . forEach ( ( param , i ) => {
350+ const input = document . getElementById (
351+ `param-${ param . name } `
352+ ) as HTMLInputElement ;
353+ if ( input && args [ i ] !== undefined ) {
354+ const value = args [ i ] ;
355+
356+ // Convert value to appropriate string representation for the input
357+ if ( typeof value === "string" ) {
358+ input . value = value ;
359+ } else if ( typeof value === "object" && value !== null ) {
360+ input . value = JSON . stringify ( value ) ;
361+ } else {
362+ input . value = String ( value ) ;
363+ }
364+ }
365+ } ) ;
366+
367+ executeFunction ( ) ;
368+ } catch ( e ) {
369+ console . error ( "Failed to parse example arguments:" , e ) ;
370+ }
334371 }
335372 } ) ;
336373
0 commit comments