Need private packages and team management tools?Check out npm Teams »

object-casing

0.0.3 • Public • Published

object-casing

npm version Coverage Status

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

npm i -S object-casing

Example

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(),
}
*/

Install

npm i object-casing

DownloadsWeekly Downloads

63

Version

0.0.3

License

ISC

Unpacked Size

4.75 kB

Total Files

9

Last publish

Collaborators

  • avatar