1.0.6 • Published 4 years ago

@suben/keys_transformer v1.0.6

Weekly downloads
6
License
ISC
Repository
github
Last release
4 years ago

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.

1.0.6

4 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago