Recursive object key recasing library built in Typescript based on the OG Recase library.
- It has an easier API to use.
- It has been tested more thoroughly.
- It has better documentation.
- It supports
CamelCaps
Add this package using your favorite package manager:
npm install better-recase
# or
yarn add better-recase
Import the package:
import Recase from 'better-recase'
Change camelCopy
object to snake_copy
:
const result = Recase.snakeCopy({
camelCopy: {
camelCopy: true,
randomCamelCopy: true
},
myDate: new Date(),
myKey: true,
already_snake_copy: "I won't change"
})
console.log(result)
/*
{
camel_copy: {
camel_copy: true,
random_camel_copy: true,
},
my_date: new Date(),
my_key: true,
already_snake_copy: 'I won\'t change',
}
*/
Change snake_copy
object to camelCopy
:
const result = Recase.camelCopy({
snake_copy: {
snake_copy: true,
random_snake_copy: false
},
my_date: new Date(),
my_key: true,
alreadyCamelCase: "I won't change"
})
console.log(result)
/*
{
snakeCopy: {
snakeCopy: true,
randomSnakeCopy: true,
},
myDate: new Date(),
myKey: true,
alreadyCamelCase: 'I won\'t change',
}
*/
Change string from snake_copy
to camelCopy
:
const keyToChange = 'date_of_birth';
const changedCamelKey Recase.camelize(keyToChange);
console.log(changedCamelKey);
// dateOfBirth
Change string from camelCopy
to snake_copy
const keyToChange = 'dateOfBirth';
const changedSnakeKey Recase.snakify(keyToChange);
console.log(changedCamelKey);
// date_of_birth