Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including koa-camelcase-keys with all npm packages installed. Try it out:

var koaCamelcaseKeys = require("koa-camelcase-keys")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

koa-camelcase-keys v1.0.1

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

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

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free