Convert object keys to lowercased one
npm install @puuuudding/decamelize-keysThis project was forked from camelcase-keys and converted to do the opposite. This project will keep updated with camelcase-keys.
> Convert object keys to lowercased one using decamelize.
```
$ npm install @puuuudding/decamelize-keys
`js
const decamelizeKeys = require('decamelize-keys');
// Convert an object
decamelizeKeys({fooBar: true});
//=> {'foo_bar': true}
// Convert an array of objects
decamelizeKeys([{fooBar: true}, {barFoo: false}]);
//=> [{'foo_bar': true}, {'bar_foo': false}]
decamelizeKeys({fooBar: true, nested: {unicornRainbow: true}}, {deep: true});
//=> {'foo_bar': true, nested: {'unicorn_rainbow': true}}
// Use custom separator
decamelizeKeys({fooBar: true, nested: {unicornRainbow: true}}, {deep: true, separator: '-'});
//=> {'foo-bar': true, nested: {'unicorn-rainbow': true}}
`
#### input
Type: object | object[]
An object or array of objects to decamelize.
#### options
Type: object
##### exclude
Type: Array\[]
Default:
Exclude keys from being camel-cased.
##### stopPaths
Type: string[]\[]
Default:
Exclude children at the given object paths in dot-notation from being decamelize. For example, with an object like {a: {b: '🦄'}}, the object path to reach the unicorn is 'a.b'.
`js`
decamelizeKeys({
aB: 1,
aC: {
cD: 1,
cE: {
eF: 1
}
}
}, {
deep: true,
stopPaths: [
'aC.cE'
]
})
/*
{
a_b: 1,
a_c: {
c_d: 1,
c_e: {
eF: 1
}
}
}
*/
##### deep
Type: boolean\false
Default:
Recurse nested objects and objects in arrays.
##### separator
Type: string\'_'
Default:
Character or string inserted to separate words in key.
`js
const decamelize = require('decamelize');
decamelize('unicornRainbow');
//=> 'unicorn_rainbow'
decamelize('unicornRainbow', {separator: '-'});
//=> 'unicorn-rainbow'
`
##### preserveConsecutiveUppercase
Type: boolean\false
Default:
Preserve sequences of uppercase characters.
`js
const decamelize = require('decamelize');
decamelize('testGUILabel');
//=> 'test_gui_label'
decamelize('testGUILabel', {preserveConsecutiveUppercase: true});
//=> 'test_GUI_label'
`Related
See camelcase-keys` for the inverse.