koa-request-trimmer
TypeScript icon, indicating that this package has built-in type declarations

1.1.2 • Public • Published

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

Package Sidebar

Install

npm i koa-request-trimmer

Weekly Downloads

1

Version

1.1.2

License

MIT

Unpacked Size

12.7 kB

Total Files

9

Last publish

Collaborators

  • hussainaliakbar