1.0.1 • Published 7 years ago

koa-camelcase-keys v1.0.1

Weekly downloads
10
License
MIT
Repository
github
Last release
7 years ago

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