@@ -425,7 +425,8 @@ export class CSSHelp {
425425/**
426426 * Extracts all function parameters and default values from a function
427427 * @param functionObject A function in string form
428- * @returns {{name:String,defaultValue: String | undefined} }
428+ * Note: All number parameters will returned as a string,
429+ * @returns {{name:string,defaultValue: string | undefined} }
429430 */
430431export function getFunctionParams ( code : string ) {
431432 // Regular expression to match function declarations, arrow functions, and function expressions
@@ -447,18 +448,22 @@ export function getFunctionParams(code: string) {
447448 const paramString =
448449 paramMatch [ 1 ] || paramMatch [ 2 ] || paramMatch [ 3 ] || paramMatch [ 4 ] ;
449450 // Split the parameter string by commas to get individual parameters
450- const params = paramString . split ( "," ) . map ( ( param : string ) => {
451- // Split each parameter by '=' to separate name and default value
452- const parts = param . trim ( ) . split ( "=" ) ;
453- // If the parameter has a default value, extract it, otherwise set it to undefined
454- const defaultValue =
455- parts . length > 1 ? parts [ 1 ] . replace ( / [ ' " ] / g, "" ) . trim ( ) : undefined ;
456- // Return an object with the parameter name and default value
457- return {
458- name : parts [ 0 ] . trim ( ) ,
459- defaultValue : defaultValue ,
460- } ;
461- } ) ;
451+ const params = paramString
452+ . replace ( / [ { } [ \] ] / g, "" )
453+ . split ( "," )
454+ . map ( ( param : string ) => {
455+ // Split each parameter by '=' to separate name and default value
456+ const parts = param . trim ( ) . split ( / [ = ] / ) ;
457+ // If the parameter has a default value, extract it, otherwise set it to undefined
458+ const defaultValue =
459+ parts . length > 1 ? parts [ 1 ] . replace ( / [ ' " ] / g, "" ) . trim ( ) : undefined ;
460+
461+ // Return an object with the parameter name and default value
462+ return {
463+ name : parts [ 0 ] . trim ( ) ,
464+ defaultValue : defaultValue ,
465+ } ;
466+ } ) ;
462467 return params ;
463468 }
464469
0 commit comments