goatslacker / get-parameter-names

Retrieves the argument names of a function
46 stars 13 forks source link

Support for arguments destructuring #18

Open Vincz opened 6 years ago

Vincz commented 6 years ago

Could be cool to be able to handle functions with arguments destructuring like that :

function({ prop1, "my-prop2": prop2 = 'default', p3 : { sp1 }, ...rest }, arg2) => {
};

That would produce an array like this for example:

[["prop1", "my-prop2", ["p3", ["sp1"]]], "arg2"]

Or event better with more info:

[{
    type: object, 
    properties: [
        {name: prop1}, 
        {name: "my-prop2", as:  "prop2", default: "default"},
        {name: p3, type: object, properties: ["sp1"]}
    ]
}]

And why not array destructuring support too ?

ViniciusTavares commented 6 years ago

I've tried to find a lib that handle functions with params destructuring, and nothing until now...

+1 for this issue. I guess it really would be useful once destructuring is getting more popular.

ktutnik commented 4 years ago

Try using tinspector its supported parameter destructuring, rest parameters and complex default value.

https://github.com/plumier/tinspector