An open API service indexing awesome lists of open source software.

https://github.com/brunolm/object-casing

Converts keys of an object using the specified callback.
https://github.com/brunolm/object-casing

casing javascript npm-package object-keys typescript

Last synced: about 2 months ago
JSON representation

Converts keys of an object using the specified callback.

Awesome Lists containing this project

README

        

# object-casing

[![npm version](https://badge.fury.io/js/object-casing.svg)](https://badge.fury.io/js/object-casing)
[![Coverage Status](https://coveralls.io/repos/github/brunolm/object-casing/badge.svg?branch=master)](https://coveralls.io/github/brunolm/object-casing?branch=master)

`object-casing` is a package that walks throught an object using a callback function to convert the object key, returning a new object with new keys.

## Install

```bash
npm i -S object-casing
```

## Example

```ts
import * as camelCase from 'lodash.camelcase'
import * as snakeCase from 'lodash.snakecase'

import { caseKeys } from 'object-casing'

const dbData = {
id: 1,
first_name: 'some name',
last_name: 'last',
created_at: new Date(),
}

const obj = caseKeys(dbData, camelCase)
/*
obj = {
id: 1,
firstName: 'some name',
lastName: 'last',
createdAt: new Date(),
}
*/

const objToDb = caseKeys(obj, snakeCase)
/*
objToDb = {
id: 1,
first_name: 'some name',
last_name: 'last',
created_at: new Date(),
}
*/
```