Skip to content
No description, website, or topics provided.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib
test
.gitignore
.travis.yml
LICENSE
README.md
package.json

README.md

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

You can’t perform that action at this time.