Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/deriegle/better-recase
Recursive Object Key Recasing Library built with Typescript
https://github.com/deriegle/better-recase
Last synced: 25 days ago
JSON representation
Recursive Object Key Recasing Library built with Typescript
- Host: GitHub
- URL: https://github.com/deriegle/better-recase
- Owner: deriegle
- License: mit
- Created: 2019-10-03T03:55:08.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2024-04-26T17:59:34.000Z (7 months ago)
- Last Synced: 2024-05-10T22:02:42.963Z (6 months ago)
- Language: TypeScript
- Size: 467 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 22
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: code-of-conduct.md
Awesome Lists containing this project
README
# Recase
Recursive object key recasing library built in Typescript based on
[the OG Recase library](https://github.com/solderjs/recase-js).## Why should I use this library instead?
1. It has an easier API to use.
2. It has been tested more thoroughly.
3. It has better documentation.
4. It supports `CamelCaps`## Usage
**Add this package using your favorite package manager**:
```bash
npm install better-recase
# or
yarn add better-recase
```**Import the package**:
```javascript
import Recase from 'better-recase'
```#### `snakeCopy`
Change `camelCopy` object to `snake_copy`:
```javascript
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`:
```javascript
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`:
```javascript
const keyToChange = 'date_of_birth';
const changedCamelKey Recase.camelize(keyToChange);console.log(changedCamelKey);
// dateOfBirth
```Change string from `camelCopy` to `snake_copy`
```javascript
const keyToChange = 'dateOfBirth';
const changedSnakeKey Recase.snakify(keyToChange);console.log(changedCamelKey);
// date_of_birth
```