@suben/keys_transformer v1.0.6
keys_transformer
JavaScript module to transform object keys.
Background
It's common to use the naming convention of the programming language in where you develop. For JavaScript, the way to go would be camel case. Using HTTP-Requests, often, especially for POST-Requests, JSON payload is attached. Those keys often follow some different rules.
So you might have an JavaScript Object:
const dragons = {
health: 10,
mainAbility: 'Spit fire balls'
}
but your JSON file might look like that
{
"health:": "int",
"main_ability": "string"
}
If you want to map those for the request you would have to map them by hand.
axios.post('url', {
health: dragons.health,
main_ability: dragons.mainAbility
})
Solution
This module provides the ability to transform those object keys, so you would just have to do the following:
axios.post('url', ..._underscore(dragons))
or vice versa
axios.post('url', ..._camelcase(dragons))
This seems like an overengineering thing, but imagine you have to map like 5 or 10 keys. Your method quickly gets bigger than you might want.