body-cleaner
v1.1.3
Published
Clean client data before use
Downloads
28
Readme
Body-cleaner
Very simple sanitizer to clean client-submitted data before you deal with it server-side. It iterates through objects & arrays to remove html & script tags, $ keys & everything that is not a string, a number, a date or a boolean.
Getting Started
Install
npm i --save body-cleaner
API
object(unsafe, options)
options <Object>
:ignoreKeys <Array>
: array of keys to ignore. Will ignore theses keys on all level.
- returns
safe <Object>
string(unsafe)
- returns
safe <String>
boolean(unsafe)
- returns
safe <Boolean>
Usage
Test it on RunKit.
const { object } = require('body-cleaner');
const newDate = new Date();
const dirty = {
$bad: 'very bad',
safe: 'safe',
count: [1, new Error(), 'it is <script>alert("un")</script>safe'],
date: newDate
};
const clean = object(dirty);
// clean = {
// safe: 'safe',
// count: [1, undefined, 'it is safe'],
// date: newDate
// }