npm

npm’s 2019 JavaScript ecosystem survey analysis is now available!Get your copy here »

koa-camelcase-keys

1.0.1 • Public • Published

koa-camelcase-keys

NPM version Build status Node.js Version Dependency status Dev Dependency status NPM downloads

A koa middleware for converting object keys to camelCase using camelcase-keys.

Installation

$ npm i --save koa-camelcase-keys

Usage

const Koa = require('koa')
const bodyParser = require('koa-bodyparser')
const camelCase = require('koa-camelcase-keys')
 
const app = new Koa()
// convert json body to object
app.use(bodyParser())
 
// camel case the object from bodyParser middlerware
app.use(camelCase())
 
// Or
// exclude some routes
app.use(camelCase({ excludeRoutes: ['/route_a', 'route_b'] }))
app.use(camelCase({ excludeRoutes: '/route_a' }))
app.use(camelCase({ excludeRoutes: /a/ }))
 
// Or
// exclude some keys
app.use(camelCase({ exclude: ['a_b', 'c_d'] }))
app.use(camelCase({ exclude: 'a_b' }))
 
// Or
// disable deep match
app.use(camelCase({ deep: false }))

API

camelCase({ deep: true, exclude: [], excludeRoutes: '' } = {})

excludeRoutes

Type: string[] RegExp[]
Default: ''

Exclude routes from being camelCased.

exclude

Type: string[] RegExp[]
Default: []

Exclude keys from being camelCased.

deep

Type: boolean
Default: false

Recurse nested objects and objects in arrays.

License

MIT @ Mindspop

install

npm i koa-camelcase-keys

Downloadsweekly downloads

22

version

1.0.1

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
  • avatar
Report a vulnerability