-1

Is there any parser for JavaScript file? I want to get/grep the argument list for a parameter.

As an example:

function a(){
}

function b(){
}

function body_4(chk, ctx) {
        ctx = ctx.shiftBlocks(blocks);
        //WANT TO GET THE #3rd parameter JSON object. 
        return chk.partial("components/TextInput/textInput", ctx, {
            "className": "firstName",
            "name": "firstName",
            "id": "firstName",
            "placeholder": "Please enter first name",
            "maxlength": "30",
            "required": "required",
            "errorMessage": "Please enter a valid first name",
            "value": body_5
        }).partial("components/TextInput/textInput", ctx, {
            "className": "lastName",
            "name": "lastName",
            "id": "lastName",
            "placeholder": "Please enter last name",
            "maxlength": "30",
            "required": "required",
            "errorMessage": "Please enter a valid last name",
            "value": body_6
        });
    }

WANT TO GET THE #3rd parameter JSON object where the 1st argument is:"components/TextInput/textInput"

Any Node module or any kind of javaScript Library would do..

The Output I am looking for is:

            {
                "className": "lastName",
                "name": "lastName",
                "id": "lastName",
                "placeholder": "Please enter last name",
                "maxlength": "30",
                "required": "required",
                "errorMessage": "Please enter a valid last name",
                "value": body_6
            }
Mayukh Roy
  • 1,815
  • 3
  • 19
  • 31

1 Answers1

0

Try using RegEx. Something like: (}).partial("components/TextInput/textInput", ctx, )({)([\s\S]+)(});)+ For testing regex check out this site

the third group will be ([\s\S]+) the content of the the Object(JSON)/

You can also check this: How to get function parameter names/values dynamically from javascript

Community
  • 1
  • 1