1.1.2 • Published 5 years ago

koa-request-trimmer v1.1.2

Weekly downloads
6
License
MIT
Repository
github
Last release
5 years ago

Build Status MIT License

Koa Request Trimmer

A dependency-free koa middleware to trim incoming requests - complete with Typescript Typings!

The middleware is able to trim the request body, URL parameters and query string parameters.

Installation

npm i --save koa-request-trimmer

Usage

const Koa = require('koa');
// a body parser of your choice
const trimmer = require('koa-request-trimmer');


const app = new Koa();

const options = {
  body: true,
  query: true,
  params: true
};

// apply bodyparser middleware of your choice


app.use(trimmer(options));

Passing options to the middleware is optional. You can even use it like this:

app.use(trimmer());

If you do not provide any options then by default, the middleware will only trim the request body.

To trim other things like query string parameters and URL parameters, the options object needs to be passed to the middleware:

const options = {
  body: true,
  query: true,
  params: true
};

setting any of the property to true or false will dictate the middleware as to what to trim and what not.

Sample Usage

Using with Typescript

You can import the module in this way:

import { koaRequestTrimmer as trimmer } from 'koa-request-trimmer';

and then pass it on to the Koa App with optional parameters:

app.use(trimmer())

Contributors

License

MIT © Hussain Ali Akbar

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago