convert-keys
Version:
Convert object keys to camelCase or snakeCase.
47 lines (37 loc) • 840 B
Markdown
# convert-keys
[](https://travis-ci.org/hiroppy/convert-keys)
[](https://codecov.io/gh/hiroppy/convert-keys)
[](https://badge.fury.io/js/convert-keys)
# Install
```
$ npm install convert-keys
```
# Usage
```javascript
const convertKeys = require('convert-keys');
const obj = {
'hoge_fuga': 1,
hogeHoge: {
'piyo_piyo': 'aaaa',
'fuga_fuga': 'bbbb'
}
};
convertKeys.toCamel(obj);
// output
{
hogeFuga: 1,
hogeHoge: {
piyoPiyo: 'aaaa',
fugaFuga: 'bbbb'
}
}
convertKeys.toSnake(obj);
// output
{
'hoge_fuga': 1,
'hoge_hoge': {
'piyo_piyo': 'aaaa',
'fuga_fuga': 'bbbb'
}
}
```