Backstory: I'm creating a UI and I'd like an option for advanced users to be able to execute any function in the API.
I've successfully imported the eosio_system.json file which contains all the API commands that can be issued in underscore format ex: "account_name": "name"
I iterate over every command in the json and then provide the appropriate fields to the user for them to fill out. Once they hit send is when I get problems.
Send will return 2 things, the name of the function as a string such as: account_Name
and fields provided as an object or string depending on the function fields, in this case a string account name like "altshiftdev1".
I then want to execute the named function but the eos javascript api uses camelcase, not underscore so I convert it and this is as far as I get. I can't seem to execute the now correctly formatted string as a function. I've tried a few methods like eval() but nothing seems to work.
Here's my current method:
processAction (label, action) {
// label === eos api function name like 'account_name'
// action === the params for that function
const eos = Eos(eosConfig) // eos and eosConfig are imported elsewhere globally, I just put this line in for clarity
let camelCase = label.replace(/_([a-z])/gi, function ($0, $1) { return $1.toUpperCase() })
this.test = eos[camelCase](action)
console.log(this.test)
}
Update: To anyone who wants to replicate what I'm trying I was using the wrong file, the schema isn't a 1:1 match with the API functions, things like eos.getAccount are not listed in the schema.
However if you import the modules, you'll be able to find all the available functions to iterate over, use this:
const {format, api, ecc, json, Fcbuffer} = Eos.modules
// Then the functions will be found in json.api.chain
Then the updated answer from @TeeAttack42 will work.