# @ridi/object-case-converter

> Convert keys in an javascript object for some cases(camelCase, snake_case, etc.)

Latest version **2.0.4** (published 2018-06-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install @ridi/object-case-converter
pnpm add @ridi/object-case-converter
yarn add @ridi/object-case-converter
bun add @ridi/object-case-converter
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.4 |
| Published | 2018-06-26 |
| First published | 2017-12-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 137.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 18 |
| Author | Kyungmi Koong |
| Maintainers | davin.ahn, devgrapher, earus, freekering, heejae, jh.park, kt.kang, kyungmi, mskims, namenu, ridi.krazijames, ridicorp |
| Keywords | converter, camelcase, snakecase |

## Links

- npm: https://www.npmjs.com/package/@ridi/object-case-converter
- Repository: https://github.com/ridi/object-case-converter
- Homepage: https://github.com/ridi/object-case-converter#readme
- Issues: https://github.com/ridi/object-case-converter/issues
- npm.io page: https://npm.io/package/@ridi/object-case-converter

## Dependencies (1)

- [lodash](https://npm.io/package/lodash.md) ^4.17.10

## Alternatives

- [@mce/gif](https://npm.io/package/@mce/gif.md) — 2.6K weekly downloads
- [cleanse](https://npm.io/package/cleanse.md) — 173 weekly downloads
- [str](https://npm.io/package/str.md) — 127 weekly downloads
- [naming](https://npm.io/package/naming.md) — 95 weekly downloads
- [tap-telco-api](https://npm.io/package/tap-telco-api.md) — 19 weekly downloads

## Recent versions

- 2.0.4 (latest) — 2018-06-26
- 2.0.2 — 2018-06-26
- 2.0.1 — 2018-06-14
- 2.0.0 — 2018-03-13
- 1.0.4 — 2017-12-07

## README

# object-case-converter

[![npm](https://img.shields.io/npm/v/@ridi/object-case-converter.svg)](https://www.npmjs.com/package/@ridi/object-case-converter)
[![Build Status](https://travis-ci.org/ridi/object-case-converter.svg?branch=master)](https://travis-ci.org/ridi/object-case-converter)
[![Greenkeeper badge](https://badges.greenkeeper.io/ridi/object-case-converter.svg)](https://greenkeeper.io/)

Convert keys in an javascript Object to the specific style(camelCase, snake_case, etc.)

## Installation

```
$ npm install --save @ridi/object-case-converter
```

## Usage

### ES6
```javascript
import { camelize, decamelize } from '@ridi/object-case-converter';

const result1 = camelize(null);
// result1 = null

const result2 = camelize({
    id: '1',
    nick_name: 'nick1',
    contacts: [{ contact_type: 'phone', value: '000-000-000' }, { contact_type: 'email', value: 'test@email.com' }],
    news_letter: { all_email: false, marketing_email: false },
});
// result2 = {
//    id: '1',
//    nickName: 'nick1',
//    contacts: [{ contact_type: 'phone', value: '000-000-000' }, { contact_type: 'email', value: 'test@email.com' }],
//    newsLetter: { all_email: false, marketing_email: false },
//}

const result3 = decamelize([
    { id: '1', nickName: 'nick1', contacts: [{ contactType: 'phone', value: '000-000-000' }, { contactType: 'email', value: 'test@email.com' }] },
    { id: '2', nickName: 'nick2', contacts: [] },
    { id: '3', nickName: 'nick3', contacts: [{ contactType: 'address', value: 'xxx' }] },
], true);
// result3 = [
//    { id: '1', nick_name: 'nick1', contacts: [{ contact_type: 'phone', value: '000-000-000' }, { contact_type: 'email', value: 'test@email.com' }] },
//    { id: '2', nick_name: 'nick2', contacts: [] },
//    { id: '3', nick_name: 'nick3', contacts: [{ contact_type: 'address', value: 'xxx' }] },
//]
```

### ES5
```javascript
var converter = require('@ridi/object-case-converter');

converter.camelize(...);
converter.decamelize(...);

```

### Methods
#### camelize(collection, options = {})

Convert keys in an object or collection to `camelCase`

* collection (Array|Object) - object or array to be converted
* [options] (Object)

        {
            recursive?: true | string[]| { excludes: string[] }
            excludes?: string[] | RegExp | ((key: string) => boolean)
        }

    * recursive - convert as recursively
    * excludes - excludes from conversion


#### decamelize(collection, options = { force: false })

Convert keys **that are camelCase only** in an object or collection to `snake_case`

* collection (Array|Object) - object or array to be converted
* [options] (Object)

        {
            recursive?: true | string[]| { excludes: string[] }
            exception?: { [key: string]: string | ((key?: string) => string) }
            force?: true
        }

    * recursive - convert as recursively
    * exception - convert to specified value
    * force - convert all keys to snake_case

### Options

* `recursive`: false

  * true -- always convert recursively
  * { excludes: string[] } -- convert when key is not in `recursive.excludes` array

  When used with the `excludes` option, excludes keys are also excluded from recursive conversions.

* `excludes`: `undefined`

  * string[] -- excludes from conversion if key is in the array
  * RegExp -- excludes matched keys
  * (key: string) => boolean -- excludes when function are return true

* `exception`: `{}`

      {
        [key: string]: string | ((key?: string) => string)
      }

  * string -- key is converted to specific string
  * (key?: string) => string -- converted to return value

* `force`: false

  If true, convert without checking that the key is camelCase

## Development

```
$ git clone git@github.com:ridi/object-case-converter.git
$ cd object-case-converter
$ npm install
```

### Build

Transpile TypeScript

```
$ npm run build
```

### Test

Tests using Jest

```
$ npm test
```

---
_Source: https://npm.io/package/@ridi/object-case-converter · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
