koa-request-trimmer
v1.1.2
Published
A koa middleware package to trim all incoming requests
Downloads
1
Maintainers
Readme
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.
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