JavaScript文件解析器获取方法和参数

时间:2016-01-18 09:01:11

标签: javascript node.js

JavaScript文件是否有解析器? 我想获取/ grep参数的参数列表。

举个例子:

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
        });
    }

想获得第一个参数为的{3rd参数JSON对象:"components/TextInput/textInput"

任何Node模块或任何类型的javaScript库都可以..

我正在寻找的输出是:

            {
                "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
            }

1 个答案:

答案 0 :(得分:0)

尝试使用RegEx。就像是: (})。partial(“components / TextInput / textInput”,ctx,)({)([\ s \ S] +)(});)+ 要测试正则表达式,请查看this网站

第三组将是([\ s \ S] +)对象的内容(JSON)/

你也可以检查一下: How to get function parameter names/values dynamically from javascript