1.0.1 • Published 9 years ago

express-body-cleaner v1.0.1

Weekly downloads
2
License
ISC
Repository
github
Last release
9 years ago

express-body-cleaner

This is a middleware to use in combination with express and body-parser. It removes all leading, trailing and excessive whitespaces inside an incoming req.body

This only counts for values, keys will never be touched

Dependencies

Installation

npm i express-body-cleaner --save

Usage

express-body-cleaner needs to be used directly after you use body-parser

Example

Node.js

var express = require('express');
var bodyParser = require('body-parser');
var bodyCleaner = require('express-body-cleaner');
var app = express();

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
  extended: false
}));
app.use(bodyCleaner);

Client

Before:
{
  "nothing": "to remove",
  "leading": "  whitespace and trailing whitespace removed    ",
  "excessive": "whitespace     will also be replaced with a single whitespace"
}
After:
{
  "nothing": "to remove",
  "leading": "whitespace and trailing whitespace removed",
  "excessive": "whitespace will also be replaced with a single whitespace"
}