better-recase
v1.0.0
Published
Easy-to-use Recursive object recasing library
Downloads
24
Readme
Recase
Recursive object key recasing library built in Typescript based on the OG Recase library.
Why should I use this library instead?
- It has an easier API to use.
- It has been tested more thoroughly.
- It has better documentation.
- It supports
CamelCaps
Usage
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'
snakeCopy
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',
}
*/
camelCopy
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',
}
*/
camelize
or snakify
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