# recase

> Deep rekey Objects and Arrays as either camel case or snake case.

Latest version **1.0.4** (published 2014-09-28) · Apache2 license · 0 weekly downloads

## Install

```sh
npm install recase
pnpm add recase
yarn add recase
bun add recase
```

## Health

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

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2014-09-28 |
| First published | 2014-07-31 |
| Weekly downloads | 0 |
| License | Apache2 |
| TypeScript types | separate (@types/recase) |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | AJ ONeal |
| Maintainers | coolaj86 |
| Keywords | rekey, key, recase, deep, copy, camel, snake, case, camelcase, snakecase, underscore, underscored |

## Links

- npm: https://www.npmjs.com/package/recase
- Repository: https://github.com/coolaj86/recase-js
- Issues: https://github.com/coolaj86/recase-js/issues
- npm.io page: https://npm.io/package/recase

## 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

- 1.0.4 (latest) — 2014-09-28
- 1.0.3 — 2014-08-09
- 1.0.2 — 2014-08-07
- 1.0.1 — 2014-07-31
- 1.0.0 — 2014-07-31

## README

recase
======

Deep re-key Objects and Arrays as either camel case or snake case.

In short:

```json
{ "fooBar": [
    { "baz": 1 }
  , { "_quxQuuxCorgeGrault": { "garplyWaldoFred": "plughXyzzyThud" } }
  ]
}
```

becomes:

```json
{ "foo_bar": [
    { "baz": 1 }
  , { "_qux_quux_corge_grault": { "garply_waldo_fred": "plughXyzzyThud" } }
  ]
}
```

And can be converted back.

Note that leading underscores `_` are considered as convention for private / special vars and are ingnored when changing case.

If I ever support `CamelCaps` (first letter capital) I might use leading `$` for private / special.

Usage
=====

This example works in both the Browser and Node

```javascript
(function (exports) {
  'use strict';

  var Recase = exports.Recase || require('recase')
    , recase = Recase.create({ exceptions: { FOO: 'foo'} })
    , snake
    , camel
    , _ = exports._ || require('lodash')
    ;

  snake = recase.snakeCopy(
    {
      FOO: 1                // Exception
    , abcXyz: {             // Normal
        _abcXyz: [          // private
          { __abcXyz: 1 }   // very private
        , { ___abcXyz: 1 }   // very very private
        ]
      }
    }
  );

  camel = recase.camelCopy(
    {
      foo: 1                // Exception
    , abc_xyz: {             // Normal
        _abc_xyz: [          // private
          { __abc_xyz: 1 }   // very private
        , { ___abc_xyz: 1 }   // very very private
        ]
      }
    }
  );

  console.log(_.isEqual(recase.camelCopy(snake), camel));
  console.log(_.isEqual(recase.snakeCopy(camel), snake));
}('undefined' !== typeof exports && exports || new Function('return this')()));
```

Currently converts between the two most common conventions (that I've seen):

* `snake_case -> camelCase` and `_private_var -> _privateVar`
* `camelCase -> snake_case` and `_privateVar -> _private_var`

Install
=======

`npm install --save recase`

`bower install --save recase`

Notes
-----

Does not support `CamelCaps`

Use the exceptions map for inconsistent key conversions such as `XMLHttpRequest` -> `xml_http_request`.

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