Recursively change the case of an object's keys
yarn add @replygirl/change-case-object
import { /* function */ } from 'change-case-object'
camelCase
capitalCase
constantCase
dotCase
headerCase
noCase
paramCase
pascalCase
pathCase
sentenceCase
snakeCase
camelCase({ some_key: { some_other_key: true })
// { someKey: { someOtherKey: true }}
capitalCase({ some_key: { some_other_key: true })
// { 'Some Key': { 'Some Other Key': true }}
constantCase({ some_key: { some_other_key: true })
// { SOME_KEY: { SOME_OTHER_KEY: true }}
Why would you do this??
dotCase({ some_key: { some_other_key: true })
// { 'some.key': { 'some.other.key': true }}
headerCase({ some_key: { some_other_key: true })
// { 'Some-Key': { 'Some-Other-Key': true }}
noCase({ some_key: { some_other_key: true })
// { 'some key': { 'some other key': true }}
paramCase({ some_key: { some_other_key: true })
// { 'some-key': { 'some-other-key': true }}
pascalCase({ some_key: { some_other_key: true })
// { SomeKey: { SomeOtherKey: true }}
pathCase({ some_key: { some_other_key: true })
// { 'some/key': { 'some/other/key': true }}
sentenceCase({ some_key: { some_other_key: true })
// { 'Some key': { 'Some other key': true }}
snakeCase({ 'some key': { 'some other key': true })
// { some_key: { some_other_key: true }}
import { CasedObject /*, Case */ } from 'change-case-object'
All of the individual functions are available as static members.
CasedObject.camelCase({ some_key: { some_other_key: true }})
// { someKey: { someOtherKey: true }}
const someObj = { some_key: { 'some other key': true }}
// initialize without changing case
const foo = new CasedObject(someObj)
console.info(foo.value) // { some_key: { 'some other key': true }}
// initialize and change case
const bar = new CasedObject(someObj, { case: 'camel' })
console.info(bar.value) // { someKey: { someOtherKey: true }}
// initialize and change case using enum
const baz = new CasedObject(someObj, { case: Case.camel })
console.info(baz.value) // { someKey: { someOtherKey: true }}
// output the value with keys in a different case
console.info(baz.snakeCase) // { some_key: { some_other_key: true }}
console.info(baz.value) // { someKey: { someOtherKey: true }}
// change the case of the value's keys
baz.value = baz.snakeCase
console.info(baz.value) // { some_key: { some_other_key: true }}